mirror of https://github.com/AMT-Cheif/drift.git
Resolve aliased columns
This commit is contained in:
parent
4bf58cb83b
commit
82f84732d0
|
@ -17,5 +17,7 @@ communicates with an app to verify behavior of widgets. As we want to run the wh
|
|||
on a device, we instead put the test files into `flutter_db/lib` and run them with
|
||||
`flutter run`. That works, but we don't get an output format that is machine readable.
|
||||
Please create an issue if you know a better way, thanks!
|
||||
TODO: https://github.com/tomaszpolanski/flutter-presentations/blob/master/lib/test_driver/test_runner.dart
|
||||
looks promising
|
||||
|
||||
That is also why these tests are not running automatically.
|
|
@ -80,14 +80,16 @@ class ColumnResolver extends RecursiveVisitor<void> {
|
|||
}
|
||||
} else if (resultColumn is ExpressionResultColumn) {
|
||||
final name = _nameOfResultColumn(resultColumn);
|
||||
usedColumns.add(
|
||||
ExpressionColumn(name: name, expression: resultColumn.expression),
|
||||
);
|
||||
final column =
|
||||
ExpressionColumn(name: name, expression: resultColumn.expression);
|
||||
|
||||
availableColumns.add(column);
|
||||
usedColumns.add(column);
|
||||
}
|
||||
}
|
||||
|
||||
s.resolvedColumns = usedColumns;
|
||||
s.scope.availableColumns = availableColumns;
|
||||
scope.availableColumns = availableColumns;
|
||||
}
|
||||
|
||||
String _nameOfResultColumn(ExpressionResultColumn c) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:sqlparser/src/utils/ast_equality.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:sqlparser/sqlparser.dart';
|
||||
|
||||
import '../parser/utils.dart';
|
||||
import 'data.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -34,4 +36,26 @@ void main() {
|
|||
expect((secondColumn.expression as Reference).resolved, content);
|
||||
expect(from.resolved, demoTable);
|
||||
});
|
||||
|
||||
test('resolves the column for order by clauses', () {
|
||||
final engine = SqlEngine()..registerTable(demoTable);
|
||||
|
||||
final context = engine
|
||||
.analyze('SELECT d.content, 3 * d.id AS t FROM demo AS d ORDER BY t');
|
||||
|
||||
expect(context.errors, isEmpty);
|
||||
|
||||
final select = context.root as SelectStatement;
|
||||
final orderingTerm = select.orderBy.terms.single.expression as Reference;
|
||||
final resolved = orderingTerm.resolved as ExpressionColumn;
|
||||
|
||||
enforceEqual(
|
||||
resolved.expression,
|
||||
BinaryExpression(
|
||||
NumericLiteral(3, token(TokenType.numberLiteral)),
|
||||
token(TokenType.star),
|
||||
Reference(tableName: 'd', columnName: 'id'),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue