mirror of https://github.com/AMT-Cheif/drift.git
Support subquery expressions in types2 (#583)
This commit is contained in:
parent
65f02cb22c
commit
5596c30cc7
|
@ -54,6 +54,20 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSubQuery(SubQuery e, TypeExpectation arg) {
|
||||
final columnsOfQuery = e.select.resolvedColumns;
|
||||
if (columnsOfQuery.isEmpty) {
|
||||
return super.visitSubQuery(e, arg);
|
||||
}
|
||||
|
||||
// The query should return one column only, but this is not the right place
|
||||
// to lint that. Just pick any column and resolve to that.
|
||||
final columnForExpr = columnsOfQuery.first;
|
||||
session._addRelation(CopyTypeFrom(e, columnForExpr));
|
||||
visitChildren(e, arg);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitInsertStatement(InsertStatement e, TypeExpectation arg) {
|
||||
if (e.withClause != null) visit(e.withClause, arg);
|
||||
|
|
|
@ -192,6 +192,11 @@ void main() {
|
|||
expect(type, const ResolvedType(type: BasicType.int));
|
||||
});
|
||||
|
||||
test('resolves subqueries', () {
|
||||
final type = _resolveResultColumn('SELECT (SELECT COUNT(*) FROM demo);');
|
||||
expect(type, const ResolvedType(type: BasicType.int));
|
||||
});
|
||||
|
||||
test('infers types for dart placeholders', () {
|
||||
final resolver = _obtainResolver(r'SELECT * FROM demo WHERE $pred');
|
||||
final type = resolver.session.typeOf(resolver
|
||||
|
|
Loading…
Reference in New Issue