Add table-valued query to test moor file

This commit is contained in:
Simon Binder 2020-01-26 15:37:46 +01:00
parent 71ef9b8cd7
commit 27430cbb07
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 38 additions and 5 deletions

View File

@ -1181,11 +1181,18 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
readsFrom: {config}).map(_rowToConfig);
}
Selectable<Config> findValidJsons() {
TableValuedResult _rowToTableValuedResult(QueryRow row) {
return TableValuedResult(
key: row.readString('key'),
value: row.readString('value'),
);
}
Selectable<TableValuedResult> tableValued() {
return customSelectQuery(
'SELECT * FROM config WHERE json_valid(config_value)',
'SELECT\n "key", "value"\n FROM config, json_each(config.config_value)\n WHERE json_valid(config_value)',
variables: [],
readsFrom: {config}).map(_rowToConfig);
readsFrom: {config}).map(_rowToTableValuedResult);
}
MultipleResult _rowToMultipleResult(QueryRow row) {
@ -1270,6 +1277,23 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
];
}
class TableValuedResult {
final String key;
final String value;
TableValuedResult({
this.key,
this.value,
});
@override
int get hashCode => $mrjf($mrjc(key.hashCode, value.hashCode));
@override
bool operator ==(dynamic other) =>
identical(this, other) ||
(other is TableValuedResult &&
other.key == this.key &&
other.value == this.value);
}
class MultipleResult {
final String a;
final int b;

View File

@ -41,7 +41,11 @@ END;
readConfig: SELECT * FROM config WHERE config_key = ?;
readMultiple: SELECT * FROM config WHERE config_key IN ? ORDER BY $clause;
readDynamic: SELECT * FROM config WHERE $predicate;
findValidJsons: SELECT * FROM config WHERE json_valid(config_value);
tableValued:
SELECT "key", "value"
FROM config, json_each(config.config_value)
WHERE json_valid(config_value);
@create: INSERT INTO config (config_key, config_value) VALUES ('key', 'values');

View File

@ -339,7 +339,12 @@ mixin ExpressionParser on ParserBase {
}
}
_error('Could not parse this expression');
if (_peek is KeywordToken) {
_error('Could not parse this expressions. Note: This is a reserved '
'keyword, you can escape it in double ticks');
} else {
_error('Could not parse this expression');
}
}
@override