mirror of https://github.com/AMT-Cheif/drift.git
Fix analysis for views with CTEs
This commit is contained in:
parent
61d5b7897a
commit
968af8f56e
|
@ -1,3 +1,7 @@
|
|||
## 0.14.0-dev
|
||||
|
||||
- Fix views using common table expressions
|
||||
|
||||
## 0.13.0-nullsafety.0
|
||||
|
||||
- Parse ordering in table key constraints
|
||||
|
|
|
@ -39,10 +39,11 @@ class AstPreparingVisitor extends RecursiveVisitor<void, void> {
|
|||
if (registeredView != null) {
|
||||
scope.availableColumns = registeredView.resolvedColumns;
|
||||
for (final column in registeredView.resolvedColumns) {
|
||||
print(column.name);
|
||||
scope.register(column.name, column);
|
||||
}
|
||||
}
|
||||
|
||||
visitChildren(e, arg);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -83,10 +83,11 @@ void main() {
|
|||
});
|
||||
|
||||
group('can read views', () {
|
||||
final engine = SqlEngine()..registerTable(demoTable);
|
||||
|
||||
View readView(String sql) {
|
||||
final engine = SqlEngine()..registerTable(demoTable);
|
||||
final context = engine.analyze(sql);
|
||||
expect(context.errors, isEmpty);
|
||||
|
||||
final stmt = context.root as CreateViewStatement;
|
||||
return const SchemaFromCreateTable().readView(context, stmt);
|
||||
}
|
||||
|
@ -109,6 +110,14 @@ void main() {
|
|||
expect(view.name, 'another_view');
|
||||
expect(view.resolvedColumns.map((e) => e.name), ['foo', 'bar']);
|
||||
});
|
||||
|
||||
test('with WITH clause', () {
|
||||
final view = readView('CREATE VIEW my_view AS '
|
||||
'WITH foo AS (SELECT * FROM demo) SELECT * FROM foo;');
|
||||
|
||||
expect(view.name, 'my_view');
|
||||
expect(view.resolvedColumns.map((e) => e.name), ['id', 'content']);
|
||||
});
|
||||
});
|
||||
|
||||
test('can read columns without type name', () {
|
||||
|
|
Loading…
Reference in New Issue