@procedures/sqlite 0.60.1 → 0.61.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/CHANGELOG.md +33 -0
- package/README.md +84 -189
- package/dist/engines.d.ts +31 -34
- package/dist/engines.d.ts.map +1 -1
- package/dist/engines.js +35 -95
- package/dist/engines.js.map +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -1
- package/dist/load.d.ts +9 -0
- package/dist/load.d.ts.map +1 -0
- package/dist/load.js +11 -0
- package/dist/load.js.map +1 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +104 -62
- package/dist/module.js.map +1 -1
- package/dist/procedures/db/backup.d.ts +5 -7
- package/dist/procedures/db/backup.d.ts.map +1 -1
- package/dist/procedures/db/backup.js +22 -27
- package/dist/procedures/db/backup.js.map +1 -1
- package/dist/procedures/db/migrate.d.ts +1 -1
- package/dist/procedures/db/migrate.d.ts.map +1 -1
- package/dist/procedures/db/migrate.js +32 -38
- package/dist/procedures/db/migrate.js.map +1 -1
- package/dist/procedures/db/schema.d.ts.map +1 -1
- package/dist/procedures/db/schema.js +8 -10
- package/dist/procedures/db/schema.js.map +1 -1
- package/dist/procedures/db/shared.d.ts +75 -10
- package/dist/procedures/db/shared.d.ts.map +1 -1
- package/dist/procedures/db/shared.js +148 -53
- package/dist/procedures/db/shared.js.map +1 -1
- package/dist/procedures/db/tables.d.ts.map +1 -1
- package/dist/procedures/db/tables.js +5 -7
- package/dist/procedures/db/tables.js.map +1 -1
- package/dist/procedures/db/transaction.d.ts +3 -4
- package/dist/procedures/db/transaction.d.ts.map +1 -1
- package/dist/procedures/db/transaction.js +18 -26
- package/dist/procedures/db/transaction.js.map +1 -1
- package/dist/storage.d.ts +18 -30
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +32 -118
- package/dist/storage.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +8 -10
- package/src/engines.ts +50 -158
- package/src/index.ts +3 -31
- package/src/load.ts +15 -0
- package/src/module.ts +128 -84
- package/src/procedures/db/backup.ts +21 -27
- package/src/procedures/db/migrate.ts +35 -40
- package/src/procedures/db/schema.ts +10 -12
- package/src/procedures/db/shared.ts +178 -50
- package/src/procedures/db/tables.ts +5 -7
- package/src/procedures/db/transaction.ts +17 -24
- package/src/storage.ts +39 -137
- package/src/types.ts +2 -2
|
@@ -1,23 +1,126 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The helpers of the sqlite.* procedures
|
|
2
|
+
* The helpers of the sqlite.* and logs.* procedures. Each procedure opens the file through the engine of
|
|
3
|
+
* `@mark1russell7/sqlite`: `openDatabase` on `node:sqlite`, one connection for each call.
|
|
4
|
+
*
|
|
5
|
+
* - A connection that runs the SQL of a caller gets `confineToFile`: the SQL works only on its file. The guard needs
|
|
6
|
+
* Node.js 24.10 or later. Before it, the call throws `ConfineUnavailableError` (`code: "CONFINE_UNAVAILABLE"`) before
|
|
7
|
+
* it opens the file.
|
|
8
|
+
* - The open does not change the journal mode of a file: a file in WAL mode stays in WAL mode, and another file stays in
|
|
9
|
+
* its mode.
|
|
10
|
+
* - A write waits for the lock of another connection for `BUSY_TIMEOUT_MS`.
|
|
3
11
|
*/
|
|
4
12
|
import { existsSync } from "node:fs";
|
|
13
|
+
import { MEMORY_PATH } from "../../engines.js";
|
|
14
|
+
import { loadSqlite } from "../../load.js";
|
|
5
15
|
import { DEFAULT_DB_PATH } from "../../types.js";
|
|
16
|
+
/** The time that a call waits for the lock of another connection, in milliseconds. */
|
|
17
|
+
export const BUSY_TIMEOUT_MS = 5000;
|
|
6
18
|
/** The database file of an input: `dbPath`, or the CLI log database. */
|
|
7
19
|
export function databasePath(dbPath) {
|
|
8
20
|
return dbPath ?? DEFAULT_DB_PATH;
|
|
9
21
|
}
|
|
10
|
-
/**
|
|
11
|
-
* This function throws ENOENT for a database file that does not exist. A procedure that only
|
|
12
|
-
* reads uses it: sql.js opens a missing file as an empty database, so a wrong path gave no tables.
|
|
13
|
-
*/
|
|
22
|
+
/** This function throws ENOENT for a database file that does not exist. */
|
|
14
23
|
export function requireDatabaseFile(procedure, path) {
|
|
15
|
-
if (path ===
|
|
24
|
+
if (path === MEMORY_PATH || existsSync(path))
|
|
16
25
|
return;
|
|
17
26
|
const error = new Error(`${procedure}: the database file does not exist: ${path}`);
|
|
18
27
|
error.code = "ENOENT";
|
|
19
28
|
throw error;
|
|
20
29
|
}
|
|
30
|
+
/** True when this Node.js has the guard, false when it does not, undefined before the first check. */
|
|
31
|
+
let confineAvailable;
|
|
32
|
+
/**
|
|
33
|
+
* This function tells if this Node.js has the guard `confineToFile`. It tries the guard one time on a database in
|
|
34
|
+
* memory. The procedures and their tests use this one check.
|
|
35
|
+
*/
|
|
36
|
+
export function isConfineAvailable(sqlite) {
|
|
37
|
+
if (confineAvailable === undefined) {
|
|
38
|
+
const probe = sqlite.openDatabase(MEMORY_PATH, { wal: false });
|
|
39
|
+
try {
|
|
40
|
+
sqlite.confineToFile(probe);
|
|
41
|
+
confineAvailable = true;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (!(error instanceof sqlite.ConfineUnavailableError))
|
|
45
|
+
throw error;
|
|
46
|
+
confineAvailable = false;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
probe.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return confineAvailable;
|
|
53
|
+
}
|
|
54
|
+
/** This function throws `ConfineUnavailableError` when this Node.js has no guard, before the call opens its file. */
|
|
55
|
+
function checkConfine(sqlite) {
|
|
56
|
+
if (!isConfineAvailable(sqlite))
|
|
57
|
+
throw new sqlite.ConfineUnavailableError();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* This function opens the database of a call, gives it to the work, and closes it. The work is synchronous, so no
|
|
61
|
+
* other call of this process uses the connection.
|
|
62
|
+
*/
|
|
63
|
+
export async function withDatabase(path, mode, work) {
|
|
64
|
+
const sqlite = await loadSqlite();
|
|
65
|
+
if (mode.callerSql)
|
|
66
|
+
checkConfine(sqlite);
|
|
67
|
+
let memory = path === MEMORY_PATH;
|
|
68
|
+
if (!memory && !existsSync(path)) {
|
|
69
|
+
if (mode.missing === "error")
|
|
70
|
+
requireDatabaseFile(mode.procedure, path);
|
|
71
|
+
else if (mode.missing === "empty")
|
|
72
|
+
memory = true;
|
|
73
|
+
}
|
|
74
|
+
const db = sqlite.openDatabase(memory ? MEMORY_PATH : path, {
|
|
75
|
+
wal: false,
|
|
76
|
+
busyTimeoutMs: BUSY_TIMEOUT_MS,
|
|
77
|
+
makeFolder: !memory && mode.missing === "make",
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
if (mode.queryOnly)
|
|
81
|
+
db.exec("PRAGMA query_only = 1");
|
|
82
|
+
if (mode.callerSql)
|
|
83
|
+
sqlite.confineToFile(db);
|
|
84
|
+
return work(db, sqlite);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
db.close();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* This function gives the values of the `?` placeholders. A boolean becomes 1 or 0, and an undefined value becomes
|
|
92
|
+
* null. Another value is an error: an object would bind as named parameters.
|
|
93
|
+
*/
|
|
94
|
+
export function toSqlParams(params, label) {
|
|
95
|
+
return (params ?? []).map((value, index) => {
|
|
96
|
+
if (value === null || value === undefined)
|
|
97
|
+
return null;
|
|
98
|
+
if (typeof value === "boolean")
|
|
99
|
+
return value ? 1 : 0;
|
|
100
|
+
if (typeof value === "number" || typeof value === "string" || typeof value === "bigint" || value instanceof Uint8Array)
|
|
101
|
+
return value;
|
|
102
|
+
throw new TypeError(`${label}: params[${index}] is ${Array.isArray(value) ? "an array" : `a value of the type ${typeof value}`}. Give a number, a string, a boolean or null.`);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** The rows of one statement, as objects. */
|
|
106
|
+
export function rowsOf(db, sql, params = []) {
|
|
107
|
+
return db.prepare(sql).all(...params);
|
|
108
|
+
}
|
|
109
|
+
/** The number of rows that the connection changed since it opened. */
|
|
110
|
+
export function totalChanges(db) {
|
|
111
|
+
return Number(rowsOf(db, "SELECT total_changes() AS n")[0]?.n ?? 0);
|
|
112
|
+
}
|
|
113
|
+
/** This function runs one statement to its end, and gives its rows when it has columns. */
|
|
114
|
+
export function runStatement(statement, params) {
|
|
115
|
+
if (statement.columns().length > 0)
|
|
116
|
+
return statement.all(...params);
|
|
117
|
+
statement.run(...params);
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
/** The text of an error. */
|
|
121
|
+
export function errorText(error) {
|
|
122
|
+
return error instanceof Error ? error.message : String(error);
|
|
123
|
+
}
|
|
21
124
|
/** The statements that control a transaction, which the procedures run themselves. */
|
|
22
125
|
const TRANSACTION_CONTROL = /^(BEGIN|COMMIT|END|ROLLBACK|SAVEPOINT|RELEASE)\b/i;
|
|
23
126
|
/** The SQL of a statement without its leading spaces and comments. */
|
|
@@ -42,64 +145,56 @@ function withoutLeadingComments(sql) {
|
|
|
42
145
|
export function controlsTransaction(sql) {
|
|
43
146
|
return TRANSACTION_CONTROL.test(withoutLeadingComments(sql));
|
|
44
147
|
}
|
|
45
|
-
function totalChanges(db) {
|
|
46
|
-
return Number(db.exec("SELECT total_changes()")[0]?.values[0]?.[0] ?? 0);
|
|
47
|
-
}
|
|
48
148
|
/**
|
|
49
|
-
* This function runs the statements of one SQL text in order, and gives one result for the text.
|
|
50
|
-
*
|
|
51
|
-
*
|
|
149
|
+
* This function runs the statements of one SQL text in order, and gives one result for the text. The params bind to the
|
|
150
|
+
* first statement, so a text with params must hold one statement.
|
|
151
|
+
*
|
|
152
|
+
* - With `control: "refuse"` (the default), the text runs in the transaction of the caller, and a statement that
|
|
153
|
+
* controls a transaction is an error.
|
|
154
|
+
* - With `control: "allow"`, the text controls its own transactions.
|
|
52
155
|
*/
|
|
53
|
-
export function runStatements(db, sql, params, label) {
|
|
156
|
+
export function runStatements(sqlite, db, sql, params, label, control = "refuse") {
|
|
54
157
|
const before = totalChanges(db);
|
|
55
158
|
const result = { changes: 0 };
|
|
56
159
|
let count = 0;
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
count++;
|
|
63
|
-
if (count > 1 && params.length > 0) {
|
|
64
|
-
throw new Error(`${label}: the params bind to one statement, and the SQL has several`);
|
|
65
|
-
}
|
|
66
|
-
if (controlsTransaction(statement.getSQL())) {
|
|
67
|
-
throw new Error(`${label}: the procedure runs the transaction: BEGIN, COMMIT, ROLLBACK, SAVEPOINT and RELEASE are refused`);
|
|
68
|
-
}
|
|
69
|
-
if (count === 1 && params.length > 0)
|
|
70
|
-
statement.bind(params);
|
|
71
|
-
if (statement.getColumnNames().length > 0) {
|
|
72
|
-
const rows = [];
|
|
73
|
-
while (statement.step())
|
|
74
|
-
rows.push(statement.getAsObject());
|
|
75
|
-
result.rows = rows;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
while (statement.step()) {
|
|
79
|
-
// A statement without columns gives no rows: one step runs it
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
statement.free();
|
|
85
|
-
}
|
|
160
|
+
for (const statement of sqlite.eachStatement(db, sql)) {
|
|
161
|
+
count++;
|
|
162
|
+
if (count > 1 && params.length > 0) {
|
|
163
|
+
throw new Error(`${label}: the params bind to one statement, and the SQL has several. Send one statement for each call.`);
|
|
86
164
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// Read the iterator to its end: that frees its copy of the SQL (it only prepares the rest)
|
|
90
|
-
try {
|
|
91
|
-
while (!iterator.next().done) {
|
|
92
|
-
// Prepare only
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
// A later statement did not prepare: the iterator ended
|
|
165
|
+
if (control === "refuse" && controlsTransaction(statement.sourceSQL)) {
|
|
166
|
+
throw new Error(`${label}: the procedure runs the transaction: BEGIN, COMMIT, ROLLBACK, SAVEPOINT and RELEASE are refused`);
|
|
97
167
|
}
|
|
98
|
-
|
|
168
|
+
const rows = runStatement(statement, count === 1 ? params : []);
|
|
169
|
+
if (rows)
|
|
170
|
+
result.rows = rows;
|
|
99
171
|
}
|
|
100
172
|
if (count === 0)
|
|
101
173
|
throw new Error(`${label}: the SQL has no statement`);
|
|
102
174
|
result.changes = totalChanges(db) - before;
|
|
103
175
|
return result;
|
|
104
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* This function counts the statements of a SQL text up to two, and runs none. It compiles the first statement and asks
|
|
179
|
+
* `eachStatement` for the second. A second statement that does not compile before the first one runs, for example an
|
|
180
|
+
* `INSERT` into a table that the first one makes, also counts.
|
|
181
|
+
*/
|
|
182
|
+
export function countStatements(sqlite, db, sql) {
|
|
183
|
+
const statements = sqlite.eachStatement(db, sql);
|
|
184
|
+
try {
|
|
185
|
+
const first = statements.next();
|
|
186
|
+
if (first.done)
|
|
187
|
+
return { count: 0, firstControls: false };
|
|
188
|
+
const firstControls = controlsTransaction(first.value.sourceSQL);
|
|
189
|
+
try {
|
|
190
|
+
return { count: statements.next().done ? 1 : 2, firstControls };
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return { count: 2, firstControls };
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
statements.return(undefined);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
105
200
|
//# sourceMappingURL=shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/procedures/db/shared.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/procedures/db/shared.ts"],"names":[],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IAC3C,OAAO,MAAM,CAAC;AAChB,CAAC;AAUD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,EAAgB,EAAE,GAAW;IAC3E,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACjD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,IAAI;YAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;QAC1D,MAAM,aAAa,GAAG,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACjE,IAAI,CAAC;YACH,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC;QAClE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC;QACrC,CAAC;IACH,CAAC;YAAS,CAAC;QACT,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/tables.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/tables.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAe,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGjF;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAW5E"}
|
|
@@ -4,19 +4,17 @@
|
|
|
4
4
|
* The tables and the views of a database, without the internal `sqlite_` tables. The connection
|
|
5
5
|
* is read only (PRAGMA query_only), and a missing file is an error: it does not make one.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import { databasePath, requireDatabaseFile } from "./shared.js";
|
|
7
|
+
import { databasePath, rowsOf, withDatabase } from "./shared.js";
|
|
9
8
|
/**
|
|
10
9
|
* The tables and views of a database
|
|
11
10
|
*/
|
|
12
11
|
export async function dbTables(input) {
|
|
13
12
|
const path = databasePath(input.dbPath);
|
|
14
|
-
requireDatabaseFile("sqlite.tables", path);
|
|
15
13
|
const types = input.views === false ? "('table')" : "('table', 'view')";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
return { tables:
|
|
14
|
+
const mode = { procedure: "sqlite.tables", missing: "error", queryOnly: true, callerSql: false };
|
|
15
|
+
return withDatabase(path, mode, (db) => {
|
|
16
|
+
const rows = rowsOf(db, `SELECT name, type, sql FROM sqlite_master WHERE type IN ${types} AND name NOT LIKE 'sqlite\\_%' ESCAPE '\\' ORDER BY name`);
|
|
17
|
+
return { tables: rows.map((row) => ({ name: row.name, type: row.type, sql: row.sql ?? null })) };
|
|
20
18
|
});
|
|
21
19
|
}
|
|
22
20
|
//# sourceMappingURL=tables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/procedures/db/tables.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/procedures/db/tables.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEjE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,KAAoB;IACjD,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC;IACxE,MAAM,IAAI,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAW,CAAC;IAC1G,OAAO,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,MAAM,CACjB,EAAE,EACF,2DAA2D,KAAK,2DAA2D,CAC5H,CAAC;QACF,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;IACnG,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* sqlite.transaction procedure (roadmap R44)
|
|
3
3
|
*
|
|
4
|
-
* The statements of the input run in order in one transaction. When one fails, the procedure
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* statement can follow an earlier one in the same transaction.
|
|
4
|
+
* The statements of the input run in order in one `BEGIN IMMEDIATE` transaction. When one fails, the procedure rolls back
|
|
5
|
+
* the transaction: the database stays as it was. A statement that gives rows (SELECT, or RETURNING) gives them in its
|
|
6
|
+
* result, so a later statement can follow an earlier one in the same transaction.
|
|
8
7
|
*/
|
|
9
8
|
import type { DbTransactionInput, DbTransactionOutput } from "../../types.js";
|
|
10
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/transaction.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/transaction.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAqB,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGjG;;GAEG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAqB3F"}
|
|
@@ -1,42 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* sqlite.transaction procedure (roadmap R44)
|
|
3
3
|
*
|
|
4
|
-
* The statements of the input run in order in one transaction. When one fails, the procedure
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* statement can follow an earlier one in the same transaction.
|
|
4
|
+
* The statements of the input run in order in one `BEGIN IMMEDIATE` transaction. When one fails, the procedure rolls back
|
|
5
|
+
* the transaction: the database stays as it was. A statement that gives rows (SELECT, or RETURNING) gives them in its
|
|
6
|
+
* result, so a later statement can follow an earlier one in the same transaction.
|
|
8
7
|
*/
|
|
9
|
-
import {
|
|
10
|
-
import { databasePath, runStatements } from "./shared.js";
|
|
8
|
+
import { databasePath, errorText, runStatements, toSqlParams, withDatabase } from "./shared.js";
|
|
11
9
|
/**
|
|
12
10
|
* Run statements in one transaction
|
|
13
11
|
*/
|
|
14
12
|
export async function dbTransaction(input) {
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const mode = { procedure: "sqlite.transaction", missing: "make", queryOnly: false, callerSql: true };
|
|
14
|
+
return withDatabase(databasePath(input.dbPath), mode, (db, sqlite) => {
|
|
17
15
|
const results = [];
|
|
18
16
|
try {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
sqlite.transaction(db, () => {
|
|
18
|
+
input.statements.forEach((statement, index) => {
|
|
19
|
+
const label = `sqlite.transaction: statements[${index}]`;
|
|
20
|
+
try {
|
|
21
|
+
results.push(runStatements(sqlite, db, statement.sql, toSqlParams(statement.params, label), label));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const message = errorText(error);
|
|
25
|
+
throw new Error(message.startsWith(label) ? message : `${label}: ${message}`);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
28
|
});
|
|
29
|
-
db.run("COMMIT");
|
|
30
29
|
}
|
|
31
30
|
catch (error) {
|
|
32
|
-
|
|
33
|
-
db.run("ROLLBACK");
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
// SQLite ended the transaction already (an ON CONFLICT ROLLBACK)
|
|
37
|
-
}
|
|
38
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
-
throw new Error(`${message}. The transaction was rolled back.`);
|
|
31
|
+
throw new Error(`${errorText(error)}. The transaction was rolled back.`);
|
|
40
32
|
}
|
|
41
33
|
return { results, changes: results.reduce((sum, result) => sum + result.changes, 0) };
|
|
42
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/procedures/db/transaction.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/procedures/db/transaction.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhG;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAyB;IAC3D,MAAM,IAAI,GAAG,EAAE,SAAS,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAW,CAAC;IAC9G,OAAO,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,MAA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and a `HybridStorage` can use it.
|
|
7
7
|
*
|
|
8
|
-
* - The
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* writes the whole file after a write. The default `auto` uses `node` when Node.js has it.
|
|
12
|
-
* - The two engines use the same file format: a file of one engine opens with the other.
|
|
8
|
+
* - The engine is `node:sqlite` of Node.js, through `@mark1russell7/sqlite`. It writes only the
|
|
9
|
+
* changed pages of the file. Version 0.61.0 removed the engine `sqljs`, and a file that it wrote
|
|
10
|
+
* opens with its items and its versions.
|
|
13
11
|
* - The table of a collection has the columns `id` (the key) and `value` (the JSON text of the
|
|
14
12
|
* item). A value goes through `JSON.stringify` and `JSON.parse`.
|
|
15
13
|
* - A change log gives `getChangesSince()`. The table `_storage_log` has the last change of each
|
|
@@ -47,23 +45,14 @@ export interface SqliteStorageOptions<T = unknown> {
|
|
|
47
45
|
*/
|
|
48
46
|
maxTombstones?: number;
|
|
49
47
|
/**
|
|
50
|
-
* The SQLite engine.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* the file is in WAL mode. Two processes can use one file.
|
|
54
|
-
* - `sqljs`: sql.js, SQLite in WebAssembly. It keeps the database in memory, and it writes the
|
|
55
|
-
* whole file after a write. This engine is deprecated, and version 0.61.0 removes it. Its first
|
|
56
|
-
* open in a process shows a `DeprecationWarning` with the code `PROCEDURES_SQLITE_SQLJS`.
|
|
57
|
-
* - `auto`: `node` when Node.js has `node:sqlite`, and else `sqljs`, with the same warning.
|
|
58
|
-
*
|
|
59
|
-
* The storages of one file in one process share one database, and thus one engine. The first
|
|
60
|
-
* storage of the file sets it. A storage with another engine than `auto` refuses a database
|
|
61
|
-
* of the other engine.
|
|
48
|
+
* The SQLite engine. `auto` and `node` both use the module `node:sqlite` of Node.js 22.13 or
|
|
49
|
+
* later. It writes only the changes, and the file is in WAL mode. Two processes can use one file.
|
|
50
|
+
* Version 0.61.0 removed the engine `sqljs`: the constructor refuses it with a `TypeError`.
|
|
62
51
|
* @default "auto"
|
|
63
52
|
*/
|
|
64
53
|
engine?: SqliteEngine;
|
|
65
54
|
/**
|
|
66
|
-
* The time that a write
|
|
55
|
+
* The time that a write waits for the lock of another process, for example
|
|
67
56
|
* `seconds(5)`. After it, the write fails with the error `database is locked`. The first
|
|
68
57
|
* storage of a file sets it.
|
|
69
58
|
* @default 5 seconds
|
|
@@ -97,7 +86,7 @@ export declare function checkTableName(name: unknown): string;
|
|
|
97
86
|
* await users.set("123", { id: "123", name: "John" });
|
|
98
87
|
* const user = await users.get("123"); // { id: "123", name: "John" }
|
|
99
88
|
* const changes = await users.getChangesSince(); // { version, full: true, changed, deleted: [] }
|
|
100
|
-
* await users.getEngine(); // "node"
|
|
89
|
+
* await users.getEngine(); // "node"
|
|
101
90
|
* await users.close();
|
|
102
91
|
* ```
|
|
103
92
|
*/
|
|
@@ -157,16 +146,16 @@ export declare class SqliteStorage<T> implements CollectionStorage<T> {
|
|
|
157
146
|
/** This method deletes several items in one transaction. */
|
|
158
147
|
deleteBatch(ids: string[]): Promise<number>;
|
|
159
148
|
getBatch(ids: string[]): Promise<Map<string, T>>;
|
|
160
|
-
/** The engine that the storage uses: `node
|
|
149
|
+
/** The engine that the storage uses: `node`. */
|
|
161
150
|
getEngine(): Promise<SqliteEngineName>;
|
|
162
151
|
/**
|
|
163
|
-
* This method
|
|
164
|
-
*
|
|
165
|
-
*
|
|
152
|
+
* This method does no work: each write is in the file at the commit of its transaction. It
|
|
153
|
+
* rejects after `close()`. It is the optional method `flush` of `CollectionStorage`, which the
|
|
154
|
+
* drain of a procedure server calls.
|
|
166
155
|
*/
|
|
167
156
|
flush(): Promise<void>;
|
|
168
157
|
/**
|
|
169
|
-
* This method
|
|
158
|
+
* This method releases the database. The items stay in the file. A new
|
|
170
159
|
* storage of the same file and table reads them, and the versions of this storage stay valid.
|
|
171
160
|
* After `close()`, each operation rejects, and a second `close()` does nothing.
|
|
172
161
|
*/
|
|
@@ -191,13 +180,12 @@ export declare class SqliteStorage<T> implements CollectionStorage<T> {
|
|
|
191
180
|
private entries;
|
|
192
181
|
private counter;
|
|
193
182
|
/**
|
|
194
|
-
* One write: the change in a transaction with the change log
|
|
195
|
-
*
|
|
196
|
-
* no file.
|
|
183
|
+
* One write: the change in a transaction with the change log. `next` gives the next number of
|
|
184
|
+
* the change log.
|
|
197
185
|
*
|
|
198
|
-
* Before the first write, the
|
|
199
|
-
*
|
|
200
|
-
* file and runs the write in it.
|
|
186
|
+
* Before the first write, the storage keeps the database of a missing file in memory, with no
|
|
187
|
+
* item. A write first tests its change there. When it changes an item, the storage makes the
|
|
188
|
+
* file and runs the write in it. Thus a write that changes nothing makes no file.
|
|
201
189
|
*/
|
|
202
190
|
private write;
|
|
203
191
|
private runWrite;
|
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAOL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EAEtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE5G,wCAAwC;AACxC,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,OAAO;IAC/C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK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