mirror of https://github.com/AMT-Cheif/drift.git
commit
aa09540946
|
@ -83,6 +83,13 @@ class NestedQueryAnalyzer extends RecursiveVisitor<_AnalyzerState, void> {
|
|||
super.visitDriftSpecificNode(e, arg);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitVariable(Variable e, _AnalyzerState arg) {
|
||||
arg.actualAndAddedVariables.add(e);
|
||||
|
||||
super.visitVariable(e, arg);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitReference(Reference e, _AnalyzerState arg) {
|
||||
final resultEntity = e.resultEntity;
|
||||
|
|
|
@ -160,7 +160,11 @@ void main() {
|
|||
c TEXT
|
||||
);
|
||||
|
||||
query: SELECT a, LIST(SELECT b, c FROM tbl WHERE a = :a AND b = :b) FROM tbl WHERE a = :a;
|
||||
query:
|
||||
SELECT
|
||||
parent.a,
|
||||
LIST(SELECT b, c FROM tbl WHERE a = :a OR a = parent.a AND b = :b)
|
||||
FROM tbl AS parent WHERE parent.a = :a;
|
||||
''',
|
||||
});
|
||||
});
|
||||
|
@ -204,17 +208,32 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('with the new query generator', () {
|
||||
test('should generate correct queries with variables', () {
|
||||
return _runTest(
|
||||
const MoorOptions.defaults(newSqlCodeGeneration: true),
|
||||
[
|
||||
contains('SELECT a FROM tbl WHERE a = ?1'),
|
||||
contains('SELECT b, c FROM tbl WHERE a = ?1 AND b = ?2'),
|
||||
contains('nestedQuery0: await'),
|
||||
contains('variables: [Variable<String?>(a), Variable<String?>(b)]'),
|
||||
contains('b: row.read<String?>(\'b\')'),
|
||||
contains('c: row.read<String?>(\'c\')'),
|
||||
contains('class QueryNestedQuery0'),
|
||||
contains(
|
||||
r'SELECT parent.a, parent.a AS "\$n_0" FROM tbl AS parent WHERE parent.a = ?1',
|
||||
),
|
||||
contains(
|
||||
r'[Variable<String?>(a)]',
|
||||
),
|
||||
contains(
|
||||
r'SELECT b, c FROM tbl WHERE a = ?1 OR a = ?2 AND b = ?3',
|
||||
),
|
||||
contains(
|
||||
r"[Variable<String?>(a), Variable<String>(row.read('\$n_0')), Variable<String?>(b)]",
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
test('should generate correct data class', () {
|
||||
return _runTest(
|
||||
const MoorOptions.defaults(newSqlCodeGeneration: true),
|
||||
[
|
||||
contains('QueryNestedQuery0({this.b,this.c,})'),
|
||||
contains('QueryResult({this.a,required this.nestedQuery0,})'),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
|
|
@ -727,7 +727,6 @@ class NodeSqlBuilder extends AstVisitor<void, void> {
|
|||
InsertMode.insertOrFail: TokenType.fail,
|
||||
InsertMode.insertOrIgnore: TokenType.ignore,
|
||||
}[mode]!);
|
||||
visitNullable(e.returning, arg);
|
||||
}
|
||||
|
||||
_keyword(TokenType.into);
|
||||
|
|
|
@ -304,6 +304,10 @@ CREATE UNIQUE INDEX my_idx ON t1 (c1, c2, c3) WHERE c1 < c3;
|
|||
testFormat('INSERT INTO foo DEFAULT VALUES RETURNING *');
|
||||
});
|
||||
|
||||
test('with returning and insert mode', () {
|
||||
testFormat('INSERT OR IGNORE INTO foo DEFAULT VALUES RETURNING *');
|
||||
});
|
||||
|
||||
test('upsert - do nothing', () {
|
||||
testFormat(
|
||||
'INSERT OR REPLACE INTO foo DEFAULT VALUES ON CONFLICT DO NOTHING');
|
||||
|
|
Loading…
Reference in New Issue