Make JoinBuilder take to as a String Function().

This commit is contained in:
Tobe O 2019-08-17 17:58:33 -04:00
parent 7e19bb2a47
commit 1fa9612c8a
3 changed files with 15 additions and 7 deletions

View file

@ -3,6 +3,8 @@
separate files. separate files.
* **BREAKING**: Add a required `QueryExecutor` argument to `transaction` * **BREAKING**: Add a required `QueryExecutor` argument to `transaction`
callbacks. callbacks.
* Make `JoinBuilder` take `to` as a `String Function()`. This will allow
ORM queries to reference their joined subqueries.
# 2.0.1 # 2.0.1
* Apply `package:pedantic` fixes. * Apply `package:pedantic` fixes.

View file

@ -5,7 +5,11 @@ import 'query.dart';
class JoinBuilder { class JoinBuilder {
final JoinType type; final JoinType type;
final Query from; final Query from;
final String to, key, value, op, alias; final String key, value, op, alias;
/// A callback to produces the expression to join against, i.e.
/// a table name, or the result of compiling a query.
final String Function() to;
final List<String> additionalFields; final List<String> additionalFields;
JoinBuilder(this.type, this.from, this.to, this.key, this.value, JoinBuilder(this.type, this.from, this.to, this.key, this.value,

View file

@ -107,13 +107,15 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
} }
} }
String _compileJoin(tableName, Set<String> trampoline) { String Function() _compileJoin(tableName, Set<String> trampoline) {
if (tableName is String) { if (tableName is String) {
return tableName; return () => tableName;
} else if (tableName is Query) { } else if (tableName is Query) {
return () {
var c = tableName.compile(trampoline); var c = tableName.compile(trampoline);
if (c == null) return c; if (c == null) return c;
return '($c)'; return '($c)';
};
} else { } else {
throw ArgumentError.value( throw ArgumentError.value(
tableName, 'tableName', 'must be a String or Query'); tableName, 'tableName', 'must be a String or Query');