Handle table aliases in moor_generator

This commit is contained in:
Simon Binder 2020-02-10 18:41:02 +01:00
parent b30c21e577
commit 04a43b36d6
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 14 additions and 4 deletions

View File

@ -16,11 +16,21 @@ class ReferencedTablesVisitor extends RecursiveVisitor<void, void> {
visitChildren(e, arg); visitChildren(e, arg);
} }
Table /*?*/ _toTableOrNull(ResolvesToResultSet resultSet) {
var resolved = resultSet.resultSet;
while (resolved != null && resolved is TableAlias) {
resolved = (resolved as TableAlias).delegate;
}
return resolved is Table ? resolved : null;
}
@override @override
void visitQueryable(Queryable e, void arg) { void visitQueryable(Queryable e, void arg) {
if (e is TableReference) { if (e is TableReference) {
final resolved = e.resolved; final resolved = _toTableOrNull(e.resultSet);
if (resolved != null && resolved is Table) { if (resolved != null) {
foundTables.add(resolved); foundTables.add(resolved);
} }
} }
@ -41,8 +51,8 @@ class UpdatedTablesVisitor extends ReferencedTablesVisitor {
final Set<Table> writtenTables = {}; final Set<Table> writtenTables = {};
void _addIfResolved(ResolvesToResultSet r) { void _addIfResolved(ResolvesToResultSet r) {
final resolved = r.resultSet; final resolved = _toTableOrNull(r);
if (resolved is Table) { if (resolved != null) {
writtenTables.add(resolved); writtenTables.add(resolved);
} }
} }