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.
|
||||
- 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 `UPSERT` clauses for insert statements
|
||||
|
||||
## 0.6.0
|
||||
|
||||
|
|
|
@ -85,6 +85,8 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
|||
}
|
||||
},
|
||||
);
|
||||
|
||||
visitNullable(e.upsert, const NoTypeExpectation());
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -540,6 +542,18 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
|||
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) {
|
||||
if (session.graph.knowsType(column)) return;
|
||||
|
||||
|
@ -561,12 +575,12 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
|||
}
|
||||
}
|
||||
|
||||
void _handleWhereClause(StatementWithWhere stmt) {
|
||||
if (stmt.where != null) {
|
||||
void _handleWhereClause(HasWhereClause e) {
|
||||
if (e.where != null) {
|
||||
// assume that a where statement is a boolean expression. Sqlite
|
||||
// internally casts (https://www.sqlite.org/lang_expr.html#booleanexpr),
|
||||
// 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 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() {
|
||||
|
|
Loading…
Reference in New Issue