mirror of https://github.com/AMT-Cheif/drift.git
Fix tests that used "table" as a table name
(we now recognize that as a keyword)
This commit is contained in:
parent
dee9993c83
commit
1766bb3f77
|
@ -23,7 +23,10 @@ class OrderingTerm extends AstNode {
|
||||||
final Expression expression;
|
final Expression expression;
|
||||||
final OrderingMode orderingMode;
|
final OrderingMode orderingMode;
|
||||||
|
|
||||||
OrderingTerm({this.expression, this.orderingMode = OrderingMode.ascending});
|
OrderingMode get resolvedOrderingMode =>
|
||||||
|
orderingMode ?? OrderingMode.ascending;
|
||||||
|
|
||||||
|
OrderingTerm({this.expression, this.orderingMode});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
T accept<T>(AstVisitor<T> visitor) => visitor.visitOrderingTerm(this);
|
T accept<T>(AstVisitor<T> visitor) => visitor.visitOrderingTerm(this);
|
||||||
|
|
|
@ -14,6 +14,6 @@ final dateTime = TableColumn(
|
||||||
'date', const ResolvedType(type: BasicType.int, hint: IsDateTime()));
|
'date', const ResolvedType(type: BasicType.int, hint: IsDateTime()));
|
||||||
|
|
||||||
final anotherTable = Table(
|
final anotherTable = Table(
|
||||||
name: 'table',
|
name: 'tbl',
|
||||||
resolvedColumns: [anotherId, dateTime],
|
resolvedColumns: [anotherId, dateTime],
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,7 +24,7 @@ Map<String, ResolveResult> _types = {
|
||||||
const ResolveResult(ResolvedType(type: BasicType.text, isArray: true)),
|
const ResolveResult(ResolvedType(type: BasicType.text, isArray: true)),
|
||||||
'SELECT * FROM demo WHERE content IN (?)':
|
'SELECT * FROM demo WHERE content IN (?)':
|
||||||
const ResolveResult(ResolvedType(type: BasicType.text, isArray: false)),
|
const ResolveResult(ResolvedType(type: BasicType.text, isArray: false)),
|
||||||
'SELECT * FROM demo JOIN table ON demo.id = table.id WHERE date = ?':
|
'SELECT * FROM demo JOIN tbl ON demo.id = tbl.id WHERE date = ?':
|
||||||
const ResolveResult(
|
const ResolveResult(
|
||||||
ResolvedType(type: BasicType.int, hint: IsDateTime())),
|
ResolvedType(type: BasicType.int, hint: IsDateTime())),
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,9 +7,9 @@ import 'utils.dart';
|
||||||
void main() {
|
void main() {
|
||||||
test('parses delete statements', () {
|
test('parses delete statements', () {
|
||||||
testStatement(
|
testStatement(
|
||||||
'DELETE FROM table WHERE id = 5',
|
'DELETE FROM tbl WHERE id = 5',
|
||||||
DeleteStatement(
|
DeleteStatement(
|
||||||
from: TableReference('table', null),
|
from: TableReference('tbl', null),
|
||||||
where: BinaryExpression(
|
where: BinaryExpression(
|
||||||
Reference(columnName: 'id'),
|
Reference(columnName: 'id'),
|
||||||
token(TokenType.equal),
|
token(TokenType.equal),
|
||||||
|
|
|
@ -17,20 +17,20 @@ void main() {
|
||||||
group('from', () {
|
group('from', () {
|
||||||
test('a simple table', () {
|
test('a simple table', () {
|
||||||
final stmt =
|
final stmt =
|
||||||
SqlEngine().parse('SELECT * FROM table').rootNode as SelectStatement;
|
SqlEngine().parse('SELECT * FROM tbl').rootNode as SelectStatement;
|
||||||
|
|
||||||
enforceEqual(stmt.from.single, TableReference('table', null));
|
enforceEqual(stmt.from.single, TableReference('tbl', null));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('from more than one table', () {
|
test('from more than one table', () {
|
||||||
final stmt = SqlEngine()
|
final stmt = SqlEngine()
|
||||||
.parse('SELECT * FROM table AS test, table2')
|
.parse('SELECT * FROM tbl AS test, table2')
|
||||||
.rootNode as SelectStatement;
|
.rootNode as SelectStatement;
|
||||||
|
|
||||||
_enforceFrom(
|
_enforceFrom(
|
||||||
stmt,
|
stmt,
|
||||||
[
|
[
|
||||||
TableReference('table', 'test'),
|
TableReference('tbl', 'test'),
|
||||||
TableReference('table2', null),
|
TableReference('table2', null),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,10 +2,10 @@ import 'package:sqlparser/src/ast/ast.dart';
|
||||||
import '../utils.dart';
|
import '../utils.dart';
|
||||||
|
|
||||||
final Map<String, AstNode> testCases = {
|
final Map<String, AstNode> testCases = {
|
||||||
'SELECT table.*, *, 1 as name WHERE 1 ORDER BY name LIMIT 3 OFFSET 5':
|
'SELECT tbl.*, *, 1 as name WHERE 1 ORDER BY name ASC LIMIT 3 OFFSET 5':
|
||||||
SelectStatement(
|
SelectStatement(
|
||||||
columns: [
|
columns: [
|
||||||
StarResultColumn('table'),
|
StarResultColumn('tbl'),
|
||||||
StarResultColumn(null),
|
StarResultColumn(null),
|
||||||
ExpressionResultColumn(
|
ExpressionResultColumn(
|
||||||
expression: NumericLiteral(1, token(TokenType.numberLiteral)),
|
expression: NumericLiteral(1, token(TokenType.numberLiteral)),
|
||||||
|
@ -14,7 +14,10 @@ final Map<String, AstNode> testCases = {
|
||||||
],
|
],
|
||||||
where: NumericLiteral(1, token(TokenType.numberLiteral)),
|
where: NumericLiteral(1, token(TokenType.numberLiteral)),
|
||||||
orderBy: OrderBy(terms: [
|
orderBy: OrderBy(terms: [
|
||||||
OrderingTerm(expression: Reference(columnName: 'name')),
|
OrderingTerm(
|
||||||
|
expression: Reference(columnName: 'name'),
|
||||||
|
orderingMode: OrderingMode.ascending,
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
limit: Limit(
|
limit: Limit(
|
||||||
count: NumericLiteral(3, token(TokenType.numberLiteral)),
|
count: NumericLiteral(3, token(TokenType.numberLiteral)),
|
||||||
|
@ -22,9 +25,9 @@ final Map<String, AstNode> testCases = {
|
||||||
offset: NumericLiteral(5, token(TokenType.numberLiteral)),
|
offset: NumericLiteral(5, token(TokenType.numberLiteral)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'SELECT table.*, (SELECT * FROM table2) FROM table': SelectStatement(
|
'SELECT tbl.*, (SELECT * FROM table2) FROM tbl': SelectStatement(
|
||||||
columns: [
|
columns: [
|
||||||
StarResultColumn('table'),
|
StarResultColumn('tbl'),
|
||||||
ExpressionResultColumn(
|
ExpressionResultColumn(
|
||||||
expression: SubQuery(
|
expression: SubQuery(
|
||||||
select: SelectStatement(
|
select: SelectStatement(
|
||||||
|
@ -35,12 +38,12 @@ final Map<String, AstNode> testCases = {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
from: [
|
from: [
|
||||||
TableReference('table', null),
|
TableReference('tbl', null),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
'SELECT * FROM table WHERE id IN ()': SelectStatement(
|
'SELECT * FROM tbl WHERE id IN ()': SelectStatement(
|
||||||
columns: [StarResultColumn(null)],
|
columns: [StarResultColumn(null)],
|
||||||
from: [TableReference('table', null)],
|
from: [TableReference('tbl', null)],
|
||||||
where: InExpression(
|
where: InExpression(
|
||||||
left: Reference(columnName: 'id'),
|
left: Reference(columnName: 'id'),
|
||||||
inside: TupleExpression(expressions: []),
|
inside: TupleExpression(expressions: []),
|
||||||
|
|
|
@ -8,7 +8,7 @@ import '../utils.dart';
|
||||||
void main() {
|
void main() {
|
||||||
test('parses order by clauses', () {
|
test('parses order by clauses', () {
|
||||||
final parsed = SqlEngine()
|
final parsed = SqlEngine()
|
||||||
.parse('SELECT * FROM table ORDER BY -a, b DESC')
|
.parse('SELECT * FROM tbl ORDER BY -a, b DESC')
|
||||||
.rootNode as SelectStatement;
|
.rootNode as SelectStatement;
|
||||||
|
|
||||||
enforceEqual(
|
enforceEqual(
|
||||||
|
@ -16,7 +16,6 @@ void main() {
|
||||||
OrderBy(
|
OrderBy(
|
||||||
terms: [
|
terms: [
|
||||||
OrderingTerm(
|
OrderingTerm(
|
||||||
orderingMode: OrderingMode.ascending,
|
|
||||||
expression: UnaryExpression(
|
expression: UnaryExpression(
|
||||||
token(TokenType.minus),
|
token(TokenType.minus),
|
||||||
Reference(columnName: 'a'),
|
Reference(columnName: 'a'),
|
||||||
|
|
|
@ -3,9 +3,9 @@ import 'package:sqlparser/sqlparser.dart';
|
||||||
import 'utils.dart';
|
import 'utils.dart';
|
||||||
|
|
||||||
final testCases = {
|
final testCases = {
|
||||||
'UPDATE OR ROLLBACK table SET a = NULL, b = c WHERE d': UpdateStatement(
|
'UPDATE OR ROLLBACK tbl SET a = NULL, b = c WHERE d': UpdateStatement(
|
||||||
or: FailureMode.rollback,
|
or: FailureMode.rollback,
|
||||||
table: TableReference('table', null),
|
table: TableReference('tbl', null),
|
||||||
set: [
|
set: [
|
||||||
SetComponent(
|
SetComponent(
|
||||||
column: Reference(columnName: 'a'),
|
column: Reference(columnName: 'a'),
|
||||||
|
|
Loading…
Reference in New Issue