@procedures/sqlite 0.60.0 → 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.
Files changed (60) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +84 -183
  3. package/dist/engines.d.ts +31 -31
  4. package/dist/engines.d.ts.map +1 -1
  5. package/dist/engines.js +35 -78
  6. package/dist/engines.js.map +1 -1
  7. package/dist/index.d.ts +3 -5
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -7
  10. package/dist/index.js.map +1 -1
  11. package/dist/load.d.ts +9 -0
  12. package/dist/load.d.ts.map +1 -0
  13. package/dist/load.js +11 -0
  14. package/dist/load.js.map +1 -0
  15. package/dist/module.d.ts.map +1 -1
  16. package/dist/module.js +104 -62
  17. package/dist/module.js.map +1 -1
  18. package/dist/procedures/db/backup.d.ts +5 -7
  19. package/dist/procedures/db/backup.d.ts.map +1 -1
  20. package/dist/procedures/db/backup.js +22 -27
  21. package/dist/procedures/db/backup.js.map +1 -1
  22. package/dist/procedures/db/migrate.d.ts +1 -1
  23. package/dist/procedures/db/migrate.d.ts.map +1 -1
  24. package/dist/procedures/db/migrate.js +32 -38
  25. package/dist/procedures/db/migrate.js.map +1 -1
  26. package/dist/procedures/db/schema.d.ts.map +1 -1
  27. package/dist/procedures/db/schema.js +8 -10
  28. package/dist/procedures/db/schema.js.map +1 -1
  29. package/dist/procedures/db/shared.d.ts +75 -10
  30. package/dist/procedures/db/shared.d.ts.map +1 -1
  31. package/dist/procedures/db/shared.js +148 -53
  32. package/dist/procedures/db/shared.js.map +1 -1
  33. package/dist/procedures/db/tables.d.ts.map +1 -1
  34. package/dist/procedures/db/tables.js +5 -7
  35. package/dist/procedures/db/tables.js.map +1 -1
  36. package/dist/procedures/db/transaction.d.ts +3 -4
  37. package/dist/procedures/db/transaction.d.ts.map +1 -1
  38. package/dist/procedures/db/transaction.js +18 -26
  39. package/dist/procedures/db/transaction.js.map +1 -1
  40. package/dist/storage.d.ts +18 -29
  41. package/dist/storage.d.ts.map +1 -1
  42. package/dist/storage.js +32 -118
  43. package/dist/storage.js.map +1 -1
  44. package/dist/types.d.ts +1 -1
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/types.js +1 -1
  47. package/dist/types.js.map +1 -1
  48. package/package.json +8 -10
  49. package/src/engines.ts +50 -132
  50. package/src/index.ts +3 -31
  51. package/src/load.ts +15 -0
  52. package/src/module.ts +128 -84
  53. package/src/procedures/db/backup.ts +21 -27
  54. package/src/procedures/db/migrate.ts +35 -40
  55. package/src/procedures/db/schema.ts +10 -12
  56. package/src/procedures/db/shared.ts +178 -50
  57. package/src/procedures/db/tables.ts +5 -7
  58. package/src/procedures/db/transaction.ts +17 -24
  59. package/src/storage.ts +39 -136
  60. package/src/types.ts +2 -2
@@ -1,15 +1,13 @@
1
1
  /**
2
2
  * sqlite.backup procedure (roadmap R44)
3
3
  *
4
- * A copy of a database in a new file. The package runs SQLite in WebAssembly (sql.js): the
5
- * database is in the memory of the module, and `VACUUM INTO` and the backup API write into the
6
- * file system of the module, not to the disk. So the procedure takes the image of the database
7
- * (`export()`, the serialized database) in the file queue of the database, where no other call
8
- * of this process changes it. It writes the image to a file next to the target, checks it with
9
- * `PRAGMA integrity_check`, and renames it.
4
+ * A copy of a database in a new file. The procedure writes the copy with `snapshot` of `@mark1russell7/sqlite` (`VACUUM
5
+ * INTO`) to a temporary file next to the target. It checks the copy with `PRAGMA integrity_check`, and renames it.
10
6
  *
7
+ * - The copy is one consistent state of the database, with the changes in its WAL file. Writers can continue during the
8
+ * copy.
9
+ * - The copy is compact: it has no free pages.
11
10
  * - The procedure does not replace a file, and it does not write the source.
12
- * - With `vacuum: true`, it compacts the copy (VACUUM on the copy): the result of `VACUUM INTO`.
13
11
  */
14
12
  import type { DbBackupInput, DbBackupOutput } from "../../types.js";
15
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/backup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AASpE;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CA+B5E"}
1
+ {"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/backup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAgBpE;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAqB5E"}
@@ -1,55 +1,50 @@
1
1
  /**
2
2
  * sqlite.backup procedure (roadmap R44)
3
3
  *
4
- * A copy of a database in a new file. The package runs SQLite in WebAssembly (sql.js): the
5
- * database is in the memory of the module, and `VACUUM INTO` and the backup API write into the
6
- * file system of the module, not to the disk. So the procedure takes the image of the database
7
- * (`export()`, the serialized database) in the file queue of the database, where no other call
8
- * of this process changes it. It writes the image to a file next to the target, checks it with
9
- * `PRAGMA integrity_check`, and renames it.
4
+ * A copy of a database in a new file. The procedure writes the copy with `snapshot` of `@mark1russell7/sqlite` (`VACUUM
5
+ * INTO`) to a temporary file next to the target. It checks the copy with `PRAGMA integrity_check`, and renames it.
10
6
  *
7
+ * - The copy is one consistent state of the database, with the changes in its WAL file. Writers can continue during the
8
+ * copy.
9
+ * - The copy is compact: it has no free pages.
11
10
  * - The procedure does not replace a file, and it does not write the source.
12
- * - With `vacuum: true`, it compacts the copy (VACUUM on the copy): the result of `VACUUM INTO`.
13
11
  */
14
12
  import { existsSync } from "node:fs";
15
- import { rename, stat, unlink, writeFile } from "node:fs/promises";
13
+ import { rename, stat, unlink } from "node:fs/promises";
16
14
  import { resolve } from "node:path";
17
- import { query, withConnection } from "@mark1russell7/docker-sqlite";
18
- import { databasePath, requireDatabaseFile } from "./shared.js";
15
+ import { databasePath, withDatabase } from "./shared.js";
19
16
  /** The key of a file path: Windows file names do not depend on case. */
20
17
  function fileKey(path) {
21
18
  const absolute = resolve(path);
22
19
  return process.platform === "win32" ? absolute.toLowerCase() : absolute;
23
20
  }
21
+ /** The error for a target that exists. */
22
+ function targetExists(target) {
23
+ const error = new Error(`sqlite.backup: the file exists already: ${target}. The procedure does not replace a file.`);
24
+ error.code = "EEXIST";
25
+ return error;
26
+ }
24
27
  /**
25
28
  * Copy a database to a new file
26
29
  */
27
30
  export async function dbBackup(input) {
28
31
  const source = databasePath(input.dbPath);
29
- requireDatabaseFile("sqlite.backup", source);
30
32
  const target = resolve(input.to);
31
33
  if (source !== ":memory:" && fileKey(source) === fileKey(target)) {
32
34
  throw new Error("sqlite.backup: the copy cannot be the database file itself");
33
35
  }
34
- if (existsSync(target)) {
35
- const error = new Error(`sqlite.backup: the file exists already: ${target}. The procedure does not replace a file.`);
36
- error.code = "EEXIST";
37
- throw error;
38
- }
39
- const image = await withConnection({ dbPath: source }, (db) => db.export());
36
+ if (existsSync(target))
37
+ throw targetExists(target);
40
38
  const temporary = `${target}.${process.pid}.${Date.now()}.tmp`;
41
39
  try {
42
- await writeFile(temporary, image);
43
- if (input.vacuum) {
44
- // The VACUUM changes the copy only: withConnection saves it to the temporary file
45
- await withConnection({ dbPath: temporary }, (db) => db.run("VACUUM"));
46
- }
47
- const check = await withConnection({ dbPath: temporary }, (db) => query(db, "PRAGMA integrity_check").rows);
48
- const verdict = check.map((row) => row.integrity_check).join("; ");
49
- if (verdict !== "ok")
50
- throw new Error(`sqlite.backup: the copy is not valid: ${verdict}`);
40
+ const read = { procedure: "sqlite.backup", missing: "error", queryOnly: false, callerSql: false };
41
+ await withDatabase(source, read, (db, sqlite) => sqlite.snapshot(db, temporary));
42
+ const check = { procedure: "sqlite.backup", missing: "error", queryOnly: true, callerSql: false };
43
+ const integrity = await withDatabase(temporary, check, (db, sqlite) => sqlite.checkIntegrity(db));
44
+ if (!integrity.ok)
45
+ throw new Error(`sqlite.backup: the copy is not valid: ${integrity.problems.join("; ")}`);
51
46
  if (existsSync(target))
52
- throw new Error(`sqlite.backup: the file exists already: ${target}. The procedure does not replace a file.`);
47
+ throw targetExists(target);
53
48
  await rename(temporary, target);
54
49
  }
55
50
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"backup.js","sourceRoot":"","sources":["../../../src/procedures/db/backup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEhE,wEAAwE;AACxE,SAAS,OAAO,CAAC,IAAY;IAC3B,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,KAAoB;IACjD,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1C,mBAAmB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACjC,IAAI,MAAM,KAAK,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;Q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7G,IAAI,UAAU,CAAC,MAAM,CAAC;YAAE,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/C,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5D,CAAC"}
@@ -7,7 +7,7 @@
7
7
  * migration with the sha256 of its SQL.
8
8
  *
9
9
  * - The pending migrations run in one transaction: when one fails, none is applied.
10
- * - A second call applies nothing, and does not write the file.
10
+ * - A second call applies nothing, and does not change the file.
11
11
  * - The SQL of an applied migration must not change: a different sha256 is an error, and the
12
12
  * call applies nothing. (The sha256 reads line ends as LF, so a checkout with CRLF is the same.)
13
13
  * - A migration must not hold BEGIN, COMMIT or ROLLBACK: the procedure runs the transaction.
@@ -1 +1 @@
1
- {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,EAA2B,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMtH,mDAAmD;AACnD,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAa3D,mGAAmG;AACnG,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAU/E;AAgBD;;GAEG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAmD/E"}
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,EAA2B,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMtH,mDAAmD;AACnD,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAa3D,mGAAmG;AACnG,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAU/E;AAgBD;;GAEG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CA+C/E"}
@@ -7,7 +7,7 @@
7
7
  * migration with the sha256 of its SQL.
8
8
  *
9
9
  * - The pending migrations run in one transaction: when one fails, none is applied.
10
- * - A second call applies nothing, and does not write the file.
10
+ * - A second call applies nothing, and does not change the file.
11
11
  * - The SQL of an applied migration must not change: a different sha256 is an error, and the
12
12
  * call applies nothing. (The sha256 reads line ends as LF, so a checkout with CRLF is the same.)
13
13
  * - A migration must not hold BEGIN, COMMIT or ROLLBACK: the procedure runs the transaction.
@@ -15,9 +15,8 @@
15
15
  import { createHash } from "node:crypto";
16
16
  import { readdir, readFile } from "node:fs/promises";
17
17
  import { join } from "node:path";
18
- import { query, withConnection } from "@mark1russell7/docker-sqlite";
19
18
  import { MIGRATION_TABLE_PATTERN } from "../../types.js";
20
- import { databasePath, runStatements } from "./shared.js";
19
+ import { databasePath, errorText, rowsOf, runStatements, withDatabase } from "./shared.js";
21
20
  /** The name of a migration file: a number, then "_" or "-", then a name, then ".sql". */
22
21
  const MIGRATION_FILE = /^(\d+)[_-](.+)\.sql$/i;
23
22
  /** The default table of the applied migrations. */
@@ -64,46 +63,41 @@ export async function dbMigrate(input) {
64
63
  if (!MIGRATION_TABLE_PATTERN.test(table))
65
64
  throw new Error(`sqlite.migrate: the table name ${JSON.stringify(table)} is not valid`);
66
65
  const migrations = ordered(input.folder !== undefined ? await migrationsOfFolder(input.folder) : input.migrations);
67
- return withConnection({ dbPath: databasePath(input.dbPath) }, (db) => {
68
- db.run("BEGIN");
66
+ const mode = { procedure: "sqlite.migrate", missing: "make", queryOnly: false, callerSql: true };
67
+ return withDatabase(databasePath(input.dbPath), mode, (db, sqlite) => {
69
68
  try {
70
- db.run(`CREATE TABLE IF NOT EXISTS "${table}" (version INTEGER PRIMARY KEY, name TEXT NOT NULL, checksum TEXT NOT NULL, applied_at TEXT NOT NULL DEFAULT (datetime('now')))`);
71
- const applied = new Map(query(db, `SELECT version, checksum FROM "${table}"`).rows.map((row) => [row.version, row.checksum]));
72
- for (const migration of migrations) {
73
- const known = applied.get(migration.version);
74
- if (known !== undefined && known !== migration.checksum) {
75
- throw new Error(`sqlite.migrate: the migration ${migration.version} (${migration.name}) changed after it was applied: its sha256 is different`);
69
+ return sqlite.transaction(db, () => {
70
+ db.exec(`CREATE TABLE IF NOT EXISTS "${table}" (version INTEGER PRIMARY KEY, name TEXT NOT NULL, checksum TEXT NOT NULL, applied_at TEXT NOT NULL DEFAULT (datetime('now')))`);
71
+ const applied = new Map(rowsOf(db, `SELECT version, checksum FROM "${table}"`).map((row) => [Number(row.version), row.checksum]));
72
+ for (const migration of migrations) {
73
+ const known = applied.get(migration.version);
74
+ if (known !== undefined && known !== migration.checksum) {
75
+ throw new Error(`sqlite.migrate: the migration ${migration.version} (${migration.name}) changed after it was applied: its sha256 is different`);
76
+ }
76
77
  }
77
- }
78
- const pending = migrations.filter((migration) => !applied.has(migration.version));
79
- for (const migration of pending) {
80
- const label = `the migration ${migration.version} (${migration.name})`;
81
- try {
82
- runStatements(db, migration.sql, [], label);
78
+ const pending = migrations.filter((migration) => !applied.has(migration.version));
79
+ const record = db.prepare(`INSERT INTO "${table}" (version, name, checksum) VALUES (?, ?, ?)`);
80
+ for (const migration of pending) {
81
+ const label = `the migration ${migration.version} (${migration.name})`;
82
+ try {
83
+ runStatements(sqlite, db, migration.sql, [], label);
84
+ }
85
+ catch (error) {
86
+ const message = errorText(error);
87
+ throw new Error(message.startsWith(label) ? `sqlite.migrate: ${message}` : `sqlite.migrate: ${label} failed: ${message}`);
88
+ }
89
+ record.run(migration.version, migration.name, migration.checksum);
83
90
  }
84
- catch (error) {
85
- const message = error instanceof Error ? error.message : String(error);
86
- throw new Error(message.startsWith(label) ? `sqlite.migrate: ${message}` : `sqlite.migrate: ${label} failed: ${message}`);
87
- }
88
- db.run(`INSERT INTO "${table}" (version, name, checksum) VALUES (?, ?, ?)`, [migration.version, migration.name, migration.checksum]);
89
- }
90
- db.run("COMMIT");
91
- const versions = [...applied.keys(), ...pending.map((migration) => migration.version)];
92
- return {
93
- applied: pending.map((migration) => ({ version: migration.version, name: migration.name })),
94
- skipped: migrations.length - pending.length,
95
- version: versions.length > 0 ? Math.max(...versions) : 0,
96
- };
91
+ const versions = [...applied.keys(), ...pending.map((migration) => migration.version)];
92
+ return {
93
+ applied: pending.map((migration) => ({ version: migration.version, name: migration.name })),
94
+ skipped: migrations.length - pending.length,
95
+ version: versions.length > 0 ? Math.max(...versions) : 0,
96
+ };
97
+ });
97
98
  }
98
99
  catch (error) {
99
- try {
100
- db.run("ROLLBACK");
101
- }
102
- catch {
103
- // SQLite ended the transaction already
104
- }
105
- const message = error instanceof Error ? error.message : String(error);
106
- throw new Error(`${message}. No migration was applied.`);
100
+ throw new Error(`${errorText(error)}. No migration was applied.`);
107
101
  }
108
102
  });
109
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../../src/procedures/db/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,8B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,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;iBACzD,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACpE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAA+C,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA0BjH;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAgC5E"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAA+C,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA0BjH;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CA+B5E"}
@@ -5,28 +5,26 @@
5
5
  * procedure reads them with the table-valued PRAGMA functions, so the name of the table is a
6
6
  * bound value, not a part of the SQL text. The connection is read only.
7
7
  */
8
- import { query, withConnection } from "@mark1russell7/docker-sqlite";
9
- import { databasePath, requireDatabaseFile } from "./shared.js";
8
+ import { databasePath, rowsOf, withDatabase } from "./shared.js";
10
9
  /**
11
10
  * The columns and indexes of a table
12
11
  */
13
12
  export async function dbSchema(input) {
14
13
  const path = databasePath(input.dbPath);
15
- requireDatabaseFile("sqlite.schema", path);
16
- return withConnection({ dbPath: path }, (db) => {
17
- db.run("PRAGMA query_only = 1");
18
- const found = query(db, "SELECT type, sql FROM sqlite_master WHERE name = ? AND type IN ('table', 'view')", [input.table]).rows[0];
14
+ const mode = { procedure: "sqlite.schema", missing: "error", queryOnly: true, callerSql: false };
15
+ return withDatabase(path, mode, (db) => {
16
+ const found = rowsOf(db, "SELECT type, sql FROM sqlite_master WHERE name = ? AND type IN ('table', 'view')", [input.table])[0];
19
17
  if (!found)
20
18
  throw new Error(`sqlite.schema: no table or view named ${JSON.stringify(input.table)}`);
21
- const columns = query(db, "SELECT name, type, \"notnull\", dflt_value, pk FROM pragma_table_info(?) ORDER BY cid", [input.table]).rows.map((row) => ({ name: row.name, type: row.type, notNull: row.notnull === 1, defaultValue: row.dflt_value, primaryKey: row.pk }));
22
- const indexes = query(db, "SELECT name, \"unique\", origin, partial FROM pragma_index_list(?) ORDER BY name", [input.table]).rows.map((row) => ({
19
+ const columns = rowsOf(db, "SELECT name, type, \"notnull\", dflt_value, pk FROM pragma_table_info(?) ORDER BY cid", [input.table]).map((row) => ({ name: row.name, type: row.type, notNull: row.notnull === 1, defaultValue: row.dflt_value, primaryKey: row.pk }));
20
+ const indexes = rowsOf(db, "SELECT name, \"unique\", origin, partial FROM pragma_index_list(?) ORDER BY name", [input.table]).map((row) => ({
23
21
  name: row.name,
24
22
  unique: row.unique === 1,
25
23
  origin: row.origin,
26
24
  partial: row.partial === 1,
27
- columns: query(db, "SELECT name FROM pragma_index_info(?) ORDER BY seqno", [row.name]).rows.map((column) => column.name ?? "<expression>"),
25
+ columns: rowsOf(db, "SELECT name FROM pragma_index_info(?) ORDER BY seqno", [row.name]).map((column) => column.name ?? "<expression>"),
28
26
  }));
29
- const foreignKeys = query(db, "SELECT \"from\", \"table\", \"to\", on_update, on_delete FROM pragma_foreign_key_list(?) ORDER BY id, seq", [input.table]).rows.map((row) => ({ from: row.from, table: row.table, to: row.to, onUpdate: row.on_update, onDelete: row.on_delete }));
27
+ const foreignKeys = rowsOf(db, "SELECT \"from\", \"table\", \"to\", on_update, on_delete FROM pragma_foreign_key_list(?) ORDER BY id, seq", [input.table]).map((row) => ({ from: row.from, table: row.table, to: row.to, onUpdate: row.on_update, onDelete: row.on_delete }));
30
28
  return { table: input.table, type: found.type, sql: found.sql, columns, indexes, foreignKeys };
31
29
  });
32
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/procedures/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAyBhE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,KAAoB;IACjD,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC,mBAAmB,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAC3C,OAAO,cAAc,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;QAC7C,EAAE,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,KAAK,CACjB,EAAE,EACF,kFAAkF,EAClF,CAAC,KAAK,CAAC,KAAK,CAAC,CACd,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACV,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,yCAAyC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAEpG,MAAM,OAAO,GAAmB,KAAK,CAAY,EAAE,EAAE,uFAAuF,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CACnK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EA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,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CACxJ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACR,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,CAAC;YACxB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,OAAO,EAAE,GAAG,CAAC,OAAO,KAAK,CAAC;YAC1B,OAAO,EAAE,MAAM,CAA0B,EAAE,EAAE,sDAAsD,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,cAAc,CAAC;SAChK,CAAC,CACH,CAAC;QACF,MAAM,WAAW,GAAuB,MAAM,CAC5C,EAAE,EACF,2GAA2G,EAC3G,CAAC,KAAK,CAAC,KAAK,CAAC,CACd,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAErH,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IACjG,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,25 +1,90 @@
1
1
  /**
2
- * The helpers of the sqlite.* procedures of roadmap R44.
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
- import type { Database } from "@mark1russell7/docker-sqlite";
12
+ import type { DatabaseSync, StatementSync } from "node:sqlite";
13
+ import { type Sqlite } from "../../load.js";
14
+ /** The time that a call waits for the lock of another connection, in milliseconds. */
15
+ export declare const BUSY_TIMEOUT_MS = 5000;
5
16
  /** The database file of an input: `dbPath`, or the CLI log database. */
6
17
  export declare function databasePath(dbPath: string | undefined): string;
18
+ /** This function throws ENOENT for a database file that does not exist. */
19
+ export declare function requireDatabaseFile(procedure: string, path: string): void;
20
+ /** How a procedure opens its database. */
21
+ export interface OpenMode {
22
+ /** The name of the procedure, for the errors. */
23
+ readonly procedure: string;
24
+ /**
25
+ * What a missing file does:
26
+ * - `error`: the call throws ENOENT.
27
+ * - `empty`: the call reads an empty database in memory, and does not make the file.
28
+ * - `make`: the call makes the file and its folder at the open, also when its work then changes nothing or fails.
29
+ */
30
+ readonly missing: "error" | "empty" | "make";
31
+ /** True when the connection only reads: `PRAGMA query_only` refuses each change. */
32
+ readonly queryOnly: boolean;
33
+ /** True when the call runs the SQL of its caller. Then `confineToFile` keeps that SQL on the file. */
34
+ readonly callerSql: boolean;
35
+ }
7
36
  /**
8
- * This function throws ENOENT for a database file that does not exist. A procedure that only
9
- * reads uses it: sql.js opens a missing file as an empty database, so a wrong path gave no tables.
37
+ * This function tells if this Node.js has the guard `confineToFile`. It tries the guard one time on a database in
38
+ * memory. The procedures and their tests use this one check.
10
39
  */
11
- export declare function requireDatabaseFile(procedure: string, path: string): void;
40
+ export declare function isConfineAvailable(sqlite: Sqlite): boolean;
41
+ /**
42
+ * This function opens the database of a call, gives it to the work, and closes it. The work is synchronous, so no
43
+ * other call of this process uses the connection.
44
+ */
45
+ export declare function withDatabase<T>(path: string, mode: OpenMode, work: (db: DatabaseSync, sqlite: Sqlite) => T): Promise<T>;
46
+ /** A value that a statement takes. */
47
+ export type SqlParam = null | number | bigint | string | Uint8Array;
48
+ /**
49
+ * This function gives the values of the `?` placeholders. A boolean becomes 1 or 0, and an undefined value becomes
50
+ * null. Another value is an error: an object would bind as named parameters.
51
+ */
52
+ export declare function toSqlParams(params: readonly unknown[] | undefined, label: string): SqlParam[];
53
+ /** The rows of one statement, as objects. */
54
+ export declare function rowsOf<T>(db: DatabaseSync, sql: string, params?: readonly SqlParam[]): T[];
55
+ /** The number of rows that the connection changed since it opened. */
56
+ export declare function totalChanges(db: DatabaseSync): number;
57
+ /** This function runs one statement to its end, and gives its rows when it has columns. */
58
+ export declare function runStatement(statement: StatementSync, params: readonly SqlParam[]): Record<string, unknown>[] | undefined;
59
+ /** The text of an error. */
60
+ export declare function errorText(error: unknown): string;
12
61
  /** True for a statement that starts, ends or names a transaction (BEGIN, COMMIT, SAVEPOINT, ...). */
13
62
  export declare function controlsTransaction(sql: string): boolean;
14
- /** The result of one statement: the rows that it changed, and its rows when it gives rows. */
63
+ /** The result of one SQL text: the rows that it changed, and the rows of its last statement that gives rows. */
15
64
  export interface StatementRun {
16
65
  changes: number;
17
66
  rows?: Record<string, unknown>[];
18
67
  }
19
68
  /**
20
- * This function runs the statements of one SQL text in order, and gives one result for the text.
21
- * The params bind to the first statement, so a text with params must hold one statement. A
22
- * statement that controls a transaction is refused: the caller owns the transaction.
69
+ * This function runs the statements of one SQL text in order, and gives one result for the text. The params bind to the
70
+ * first statement, so a text with params must hold one statement.
71
+ *
72
+ * - With `control: "refuse"` (the default), the text runs in the transaction of the caller, and a statement that
73
+ * controls a transaction is an error.
74
+ * - With `control: "allow"`, the text controls its own transactions.
75
+ */
76
+ export declare function runStatements(sqlite: Sqlite, db: DatabaseSync, sql: string, params: readonly SqlParam[], label: string, control?: "refuse" | "allow"): StatementRun;
77
+ /** The first statements of a SQL text, before a statement runs. */
78
+ export interface StatementCount {
79
+ /** The number of statements: 0, 1, or 2 for two or more. */
80
+ readonly count: 0 | 1 | 2;
81
+ /** True when the first statement controls a transaction (BEGIN, COMMIT, SAVEPOINT, ...). */
82
+ readonly firstControls: boolean;
83
+ }
84
+ /**
85
+ * This function counts the statements of a SQL text up to two, and runs none. It compiles the first statement and asks
86
+ * `eachStatement` for the second. A second statement that does not compile before the first one runs, for example an
87
+ * `INSERT` into a table that the first one makes, also counts.
23
88
  */
24
- export declare function runStatements(db: Database, sql: string, params: unknown[], label: string): StatementRun;
89
+ export declare function countStatements(sqlite: Sqlite, db: DatabaseSync, sql: string): StatementCount;
25
90
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/procedures/db/shared.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAG7D,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAE/D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAKzE;AAsBD,qGAAqG;AACrG,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,8FAA8F;AAC9F,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CAClC;AAMD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CA4CvG"}
1
+ {"version":3,"file":"shared.d.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