sql-typechecker 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/typecheck.ts +15 -9
package/package.json
CHANGED
package/src/typecheck.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
SelectStatement,
|
|
25
25
|
Statement,
|
|
26
26
|
toSql,
|
|
27
|
+
UpdateStatement,
|
|
27
28
|
} from "pgsql-ast-parser";
|
|
28
29
|
import { builtincasts } from "./builtincasts";
|
|
29
30
|
import { builtinoperators } from "./builtinoperators";
|
|
@@ -740,21 +741,26 @@ function elabInsert(g: Global, c: Context, s: InsertStatement): VoidT | SetT {
|
|
|
740
741
|
// TODO: typecheck s.onConflict
|
|
741
742
|
}
|
|
742
743
|
|
|
743
|
-
function
|
|
744
|
-
|
|
744
|
+
function elabDeleteOrUpdate(
|
|
745
|
+
g: Global,
|
|
746
|
+
c: Context,
|
|
747
|
+
s: DeleteStatement | UpdateStatement
|
|
748
|
+
): VoidT | SetT {
|
|
749
|
+
const tableName = s.type === "delete" ? s.from : s.table;
|
|
750
|
+
const tableDef: null | {
|
|
745
751
|
readonly name: QName;
|
|
746
752
|
readonly rel: SetT;
|
|
747
|
-
} = g.tables.find((t) => eqQNames(t.name,
|
|
753
|
+
} = g.tables.find((t) => eqQNames(t.name, tableName)) || null;
|
|
748
754
|
|
|
749
|
-
if (!
|
|
750
|
-
throw new UnknownIdentifier(s,
|
|
755
|
+
if (!tableDef) {
|
|
756
|
+
throw new UnknownIdentifier(s, tableName);
|
|
751
757
|
}
|
|
752
|
-
const nameToAddInContext =
|
|
758
|
+
const nameToAddInContext = tableName.alias || tableName.name;
|
|
753
759
|
const newContext = {
|
|
754
760
|
...c,
|
|
755
761
|
froms: c.froms.concat({
|
|
756
762
|
name: { name: nameToAddInContext },
|
|
757
|
-
type:
|
|
763
|
+
type: tableDef.rel,
|
|
758
764
|
}),
|
|
759
765
|
};
|
|
760
766
|
|
|
@@ -1771,8 +1777,8 @@ function elabStatement(g: Global, c: Context, s: Statement): VoidT | Type {
|
|
|
1771
1777
|
return elabExpr(g, c, s);
|
|
1772
1778
|
} else if (s.type === "insert") {
|
|
1773
1779
|
return elabInsert(g, c, s);
|
|
1774
|
-
} else if (s.type === "delete") {
|
|
1775
|
-
return
|
|
1780
|
+
} else if (s.type === "delete" || s.type === "update") {
|
|
1781
|
+
return elabDeleteOrUpdate(g, c, s);
|
|
1776
1782
|
} else {
|
|
1777
1783
|
return notImplementedYet(s);
|
|
1778
1784
|
}
|