@crvouga/sqlite-mem 1.6.0 → 1.7.0
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/dist/ast/nodes.d.ts +5 -0
- package/dist/index.js +305 -179
- package/dist/index.js.map +2 -2
- package/dist/unstable.js +39 -18
- package/dist/unstable.js.map +2 -2
- package/package.json +3 -2
package/dist/unstable.js
CHANGED
|
@@ -99,32 +99,46 @@ function applyAffinity(value, affinity) {
|
|
|
99
99
|
if (value === null) return null;
|
|
100
100
|
switch (affinity) {
|
|
101
101
|
case "TEXT":
|
|
102
|
-
if (value instanceof Uint8Array) return
|
|
102
|
+
if (value instanceof Uint8Array) return value;
|
|
103
103
|
if (value instanceof SqlJsonText) return value.value;
|
|
104
104
|
if (typeof value === "string") return value;
|
|
105
|
-
if (value instanceof SqlReal) return
|
|
105
|
+
if (value instanceof SqlReal) return formatRealAsText(value.value);
|
|
106
|
+
if (typeof value === "number") return String(canonicalizeNumber(value));
|
|
107
|
+
if (typeof value === "bigint") return value.toString();
|
|
106
108
|
return String(value);
|
|
107
109
|
case "INTEGER": {
|
|
110
|
+
if (value instanceof Uint8Array) return value;
|
|
108
111
|
const n = coerceToNumber(value);
|
|
109
112
|
if (n === null) return value;
|
|
110
113
|
if (typeof value === "bigint") return value;
|
|
111
114
|
return Number.isInteger(n) && Number.isSafeInteger(n) ? Math.trunc(n) : canonicalizeNumber(n);
|
|
112
115
|
}
|
|
113
116
|
case "REAL": {
|
|
117
|
+
if (value instanceof Uint8Array) return value;
|
|
114
118
|
const n = coerceToNumber(value);
|
|
115
119
|
return n === null ? value : asSqlReal(n);
|
|
116
120
|
}
|
|
117
121
|
case "NUMERIC": {
|
|
122
|
+
if (value instanceof Uint8Array) return value;
|
|
118
123
|
const n = coerceToNumber(value);
|
|
119
124
|
if (n === null) return value;
|
|
120
125
|
if (Number.isInteger(n) && Number.isSafeInteger(n)) return Math.trunc(n);
|
|
121
126
|
return canonicalizeNumber(n);
|
|
122
127
|
}
|
|
123
128
|
case "BLOB":
|
|
124
|
-
if (typeof value === "number") return canonicalizeNumber(value);
|
|
125
129
|
return value;
|
|
126
130
|
}
|
|
127
131
|
}
|
|
132
|
+
function formatRealAsText(value) {
|
|
133
|
+
const n = canonicalizeNumber(value);
|
|
134
|
+
if (Object.is(n, -0) || n === 0) return "0.0";
|
|
135
|
+
if (Number.isInteger(n) && Number.isSafeInteger(n)) return `${n}.0`;
|
|
136
|
+
const abs = Math.abs(n);
|
|
137
|
+
if (abs >= 1e16 || abs > 0 && abs < 1e-4) {
|
|
138
|
+
return n.toExponential(1).replace(/e([+-])(\d)$/, "e$10$2").replace(/e\+/, "e+");
|
|
139
|
+
}
|
|
140
|
+
return String(n);
|
|
141
|
+
}
|
|
128
142
|
function applyComparisonAffinity(left, right, leftAffinity, rightAffinity) {
|
|
129
143
|
const leftNumeric = leftAffinity === "INTEGER" || leftAffinity === "REAL" || leftAffinity === "NUMERIC";
|
|
130
144
|
const rightNumeric = rightAffinity === "INTEGER" || rightAffinity === "REAL" || rightAffinity === "NUMERIC";
|
|
@@ -4317,7 +4331,7 @@ var Parser = class {
|
|
|
4317
4331
|
if (this.at("SELECT") || this.at("WITH") || this.at("VALUES")) {
|
|
4318
4332
|
const select = this.at("SELECT") || this.at("WITH") ? this.parseSelectStmt() : this.parseValuesAsSelect();
|
|
4319
4333
|
this.expect("RPAREN");
|
|
4320
|
-
const alias3 = this.optionalAlias() ?? this.
|
|
4334
|
+
const alias3 = this.optionalAlias() ?? `__subq_${this.pos}`;
|
|
4321
4335
|
return { type: "subquery", select, alias: alias3 };
|
|
4322
4336
|
}
|
|
4323
4337
|
const item = this.parseFromItem();
|
|
@@ -4544,13 +4558,15 @@ var Parser = class {
|
|
|
4544
4558
|
// ── DELETE ──────────────────────────────────────────────────────────────
|
|
4545
4559
|
parseDeleteStmt(withClause = this.parseOptionalWith()) {
|
|
4546
4560
|
this.expect("DELETE");
|
|
4561
|
+
const or = this.parseOrConflict();
|
|
4547
4562
|
this.expect("FROM");
|
|
4548
4563
|
const table = this.parseTableName();
|
|
4549
4564
|
const alias = this.optionalAlias();
|
|
4550
4565
|
let where = null;
|
|
4551
4566
|
if (this.match("WHERE")) where = this.parseExpr();
|
|
4552
4567
|
const returning = this.parseReturning();
|
|
4553
|
-
|
|
4568
|
+
const orMode = or === null ? null : or === "REPLACE" ? "replace" : or === "IGNORE" ? "ignore" : or === "ABORT" ? "abort" : or === "ROLLBACK" ? "rollback" : "fail";
|
|
4569
|
+
return { type: "delete", with: withClause, or: orMode, table, alias, where, returning };
|
|
4554
4570
|
}
|
|
4555
4571
|
// ── CREATE ──────────────────────────────────────────────────────────────
|
|
4556
4572
|
parseCreateStmt() {
|
|
@@ -4839,9 +4855,9 @@ var Parser = class {
|
|
|
4839
4855
|
} while (this.match("COMMA"));
|
|
4840
4856
|
this.expect("RPAREN");
|
|
4841
4857
|
}
|
|
4842
|
-
const { onDelete, onUpdate } = this.parseFkActions();
|
|
4858
|
+
const { onDelete, onUpdate, match } = this.parseFkActions();
|
|
4843
4859
|
const { deferrable, initiallyDeferred } = this.parseDeferrable();
|
|
4844
|
-
return { type: "references", table, columns, onDelete, onUpdate, deferrable, initiallyDeferred };
|
|
4860
|
+
return { type: "references", table, columns, onDelete, onUpdate, match, deferrable, initiallyDeferred };
|
|
4845
4861
|
}
|
|
4846
4862
|
parseTableConstraint() {
|
|
4847
4863
|
let name = null;
|
|
@@ -4887,7 +4903,7 @@ var Parser = class {
|
|
|
4887
4903
|
} while (this.match("COMMA"));
|
|
4888
4904
|
this.expect("RPAREN");
|
|
4889
4905
|
}
|
|
4890
|
-
const { onDelete, onUpdate } = this.parseFkActions();
|
|
4906
|
+
const { onDelete, onUpdate, match } = this.parseFkActions();
|
|
4891
4907
|
const { deferrable, initiallyDeferred } = this.parseDeferrable();
|
|
4892
4908
|
return {
|
|
4893
4909
|
type: "foreign_key",
|
|
@@ -4896,6 +4912,7 @@ var Parser = class {
|
|
|
4896
4912
|
refColumns,
|
|
4897
4913
|
onDelete,
|
|
4898
4914
|
onUpdate,
|
|
4915
|
+
match,
|
|
4899
4916
|
name,
|
|
4900
4917
|
deferrable,
|
|
4901
4918
|
initiallyDeferred
|
|
@@ -4957,21 +4974,24 @@ var Parser = class {
|
|
|
4957
4974
|
parseFkActions() {
|
|
4958
4975
|
let onDelete = null;
|
|
4959
4976
|
let onUpdate = null;
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4977
|
+
let match = "SIMPLE";
|
|
4978
|
+
const readMatch = () => {
|
|
4979
|
+
while (this.match("MATCH")) {
|
|
4980
|
+
const word = this.parseIdent().toUpperCase();
|
|
4981
|
+
if (word === "FULL") match = "FULL";
|
|
4982
|
+
else if (word === "PARTIAL") match = "PARTIAL";
|
|
4983
|
+
else match = "SIMPLE";
|
|
4984
|
+
}
|
|
4985
|
+
};
|
|
4986
|
+
readMatch();
|
|
4963
4987
|
while (this.at("ON")) {
|
|
4964
4988
|
if (this.peek().kind === "DELETE") onDelete = this.parseFkAction("DELETE");
|
|
4965
4989
|
else if (this.peek().kind === "UPDATE") onUpdate = this.parseFkAction("UPDATE");
|
|
4966
4990
|
else this.syntaxError("expected ON DELETE or ON UPDATE");
|
|
4967
|
-
|
|
4968
|
-
this.parseIdent();
|
|
4969
|
-
}
|
|
4970
|
-
}
|
|
4971
|
-
while (this.match("MATCH")) {
|
|
4972
|
-
this.parseIdent();
|
|
4991
|
+
readMatch();
|
|
4973
4992
|
}
|
|
4974
|
-
|
|
4993
|
+
readMatch();
|
|
4994
|
+
return { onDelete, onUpdate, match };
|
|
4975
4995
|
}
|
|
4976
4996
|
parseDeferrable() {
|
|
4977
4997
|
let deferrable = false;
|
|
@@ -8265,6 +8285,7 @@ var DatabaseState = class _DatabaseState {
|
|
|
8265
8285
|
refColumns: constraint.columns,
|
|
8266
8286
|
onDelete: constraint.onDelete,
|
|
8267
8287
|
onUpdate: constraint.onUpdate,
|
|
8288
|
+
match: constraint.match,
|
|
8268
8289
|
name: null,
|
|
8269
8290
|
deferrable: constraint.deferrable,
|
|
8270
8291
|
initiallyDeferred: constraint.initiallyDeferred
|