Make JoinBuilder
take to
as a String Function()
.
This commit is contained in:
parent
7e19bb2a47
commit
1fa9612c8a
3 changed files with 15 additions and 7 deletions
|
@ -3,6 +3,8 @@
|
|||
separate files.
|
||||
* **BREAKING**: Add a required `QueryExecutor` argument to `transaction`
|
||||
callbacks.
|
||||
* Make `JoinBuilder` take `to` as a `String Function()`. This will allow
|
||||
ORM queries to reference their joined subqueries.
|
||||
|
||||
# 2.0.1
|
||||
* Apply `package:pedantic` fixes.
|
||||
|
|
|
@ -5,7 +5,11 @@ import 'query.dart';
|
|||
class JoinBuilder {
|
||||
final JoinType type;
|
||||
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;
|
||||
|
||||
JoinBuilder(this.type, this.from, this.to, this.key, this.value,
|
||||
|
@ -55,4 +59,4 @@ class JoinBuilder {
|
|||
b.write(' ON $left$op$right');
|
||||
return b.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
return tableName;
|
||||
return () => tableName;
|
||||
} else if (tableName is Query) {
|
||||
var c = tableName.compile(trampoline);
|
||||
if (c == null) return c;
|
||||
return '($c)';
|
||||
return () {
|
||||
var c = tableName.compile(trampoline);
|
||||
if (c == null) return c;
|
||||
return '($c)';
|
||||
};
|
||||
} else {
|
||||
throw ArgumentError.value(
|
||||
tableName, 'tableName', 'must be a String or Query');
|
||||
|
|
Loading…
Reference in a new issue