mirror of https://github.com/AMT-Cheif/drift.git
types2: Inference for upsert clauses
This commit is contained in:
parent
0c171c3b81
commit
8839ec75a8
|
@ -5,6 +5,7 @@
|
||||||
to `enabledExtensions` instead.
|
to `enabledExtensions` instead.
|
||||||
- Parse `rowid` as a valid reference when needed (`SELECT rowid FROM tbl` is now parsed correctly)
|
- Parse `rowid` as a valid reference when needed (`SELECT rowid FROM tbl` is now parsed correctly)
|
||||||
- Parse `CURRENT_TIME`, `CURRENT_DATE` and `CURRENT_TIMESTAMP`
|
- Parse `CURRENT_TIME`, `CURRENT_DATE` and `CURRENT_TIMESTAMP`
|
||||||
|
- Parse `UPSERT` clauses for insert statements
|
||||||
|
|
||||||
## 0.6.0
|
## 0.6.0
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,8 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
visitNullable(e.upsert, const NoTypeExpectation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -540,6 +542,18 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
||||||
return visited;
|
return visited;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void visitUpsertClause(UpsertClause e, TypeExpectation arg) {
|
||||||
|
_handleWhereClause(e);
|
||||||
|
visitExcept(e, e.where, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void visitDoUpdate(DoUpdate e, TypeExpectation arg) {
|
||||||
|
_handleWhereClause(e);
|
||||||
|
visitExcept(e, e.where, arg);
|
||||||
|
}
|
||||||
|
|
||||||
void _handleColumn(Column column) {
|
void _handleColumn(Column column) {
|
||||||
if (session.graph.knowsType(column)) return;
|
if (session.graph.knowsType(column)) return;
|
||||||
|
|
||||||
|
@ -561,12 +575,12 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleWhereClause(StatementWithWhere stmt) {
|
void _handleWhereClause(HasWhereClause e) {
|
||||||
if (stmt.where != null) {
|
if (e.where != null) {
|
||||||
// assume that a where statement is a boolean expression. Sqlite
|
// assume that a where statement is a boolean expression. Sqlite
|
||||||
// internally casts (https://www.sqlite.org/lang_expr.html#booleanexpr),
|
// internally casts (https://www.sqlite.org/lang_expr.html#booleanexpr),
|
||||||
// so be lax
|
// so be lax
|
||||||
visit(stmt.where, const ExactTypeExpectation.laxly(ResolvedType.bool()));
|
visit(e.where, const ExactTypeExpectation.laxly(ResolvedType.bool()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,10 @@ const Map<String, ResolvedType> _types = {
|
||||||
'SELECT (3 * 4) = ?': ResolvedType(type: BasicType.int),
|
'SELECT (3 * 4) = ?': ResolvedType(type: BasicType.int),
|
||||||
'SELECT (3 / 4) = ?': ResolvedType(type: BasicType.int),
|
'SELECT (3 / 4) = ?': ResolvedType(type: BasicType.int),
|
||||||
'SELECT CURRENT_TIMESTAMP = ?': ResolvedType(type: BasicType.text),
|
'SELECT CURRENT_TIMESTAMP = ?': ResolvedType(type: BasicType.text),
|
||||||
|
'INSERT INTO demo DEFAULT VALUES ON CONFLICT (id) WHERE ? DO NOTHING':
|
||||||
|
ResolvedType.bool(),
|
||||||
|
'INSERT INTO demo DEFAULT VALUES ON CONFLICT DO UPDATE SET id = id WHERE ?':
|
||||||
|
ResolvedType.bool(),
|
||||||
};
|
};
|
||||||
|
|
||||||
SqlEngine _spawnEngine() {
|
SqlEngine _spawnEngine() {
|
||||||
|
|
Loading…
Reference in New Issue