@jini-ai/db 0.2.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/LICENSE.pglite-socket +176 -0
- package/NOTICE.md +27 -0
- package/README.md +210 -0
- package/dist/core/artifact-naming.d.ts +34 -0
- package/dist/core/artifact-naming.js +34 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +10 -0
- package/dist/core/messages.d.ts +43 -0
- package/dist/core/messages.js +26 -0
- package/dist/core/pg-types.d.ts +22 -0
- package/dist/core/pg-types.js +26 -0
- package/dist/core/ports.d.ts +70 -0
- package/dist/core/ports.js +22 -0
- package/dist/core/row-values.d.ts +32 -0
- package/dist/core/row-values.js +42 -0
- package/dist/core/socket.d.ts +8 -0
- package/dist/core/socket.js +8 -0
- package/dist/kernel/dialect.d.ts +83 -0
- package/dist/kernel/dialect.js +191 -0
- package/dist/kernel/index.d.ts +15 -0
- package/dist/kernel/index.js +15 -0
- package/dist/kernel/kernel-core.d.ts +43 -0
- package/dist/kernel/kernel-core.js +98 -0
- package/dist/kernel/ops.d.ts +48 -0
- package/dist/kernel/ops.js +49 -0
- package/dist/kernel/pg-types.d.ts +22 -0
- package/dist/kernel/pg-types.js +26 -0
- package/dist/kernel/pglite/dialect.d.ts +11 -0
- package/dist/kernel/pglite/dialect.js +88 -0
- package/dist/kernel/pglite/driver.d.ts +30 -0
- package/dist/kernel/pglite/driver.js +47 -0
- package/dist/kernel/pglite/index.d.ts +5 -0
- package/dist/kernel/pglite/index.js +5 -0
- package/dist/kernel/pglite/ops.d.ts +39 -0
- package/dist/kernel/pglite/ops.js +78 -0
- package/dist/kernel/port.d.ts +82 -0
- package/dist/kernel/port.js +11 -0
- package/dist/kernel/postgres/driver.d.ts +23 -0
- package/dist/kernel/postgres/driver.js +42 -0
- package/dist/kernel/postgres/index.d.ts +5 -0
- package/dist/kernel/postgres/index.js +5 -0
- package/dist/kernel/postgres/ops.d.ts +12 -0
- package/dist/kernel/postgres/ops.js +46 -0
- package/dist/kernel/postgres/pglite-socket.d.ts +23 -0
- package/dist/kernel/postgres/pglite-socket.js +52 -0
- package/dist/kernel/postgres-lock.d.ts +8 -0
- package/dist/kernel/postgres-lock.js +10 -0
- package/dist/kernel/schema-scope.d.ts +14 -0
- package/dist/kernel/schema-scope.js +20 -0
- package/dist/kernel/schema-shape.d.ts +26 -0
- package/dist/kernel/schema-shape.js +83 -0
- package/dist/kernel/socket.d.ts +8 -0
- package/dist/kernel/socket.js +8 -0
- package/dist/kernel/sqlite/driver.d.ts +71 -0
- package/dist/kernel/sqlite/driver.js +132 -0
- package/dist/kernel/sqlite/index.d.ts +4 -0
- package/dist/kernel/sqlite/index.js +4 -0
- package/dist/kernel/sqlite/ops.d.ts +12 -0
- package/dist/kernel/sqlite/ops.js +40 -0
- package/dist/kernel/store-copy.d.ts +82 -0
- package/dist/kernel/store-copy.js +240 -0
- package/dist/kernel/turn-lock.d.ts +21 -0
- package/dist/kernel/turn-lock.js +42 -0
- package/dist/kernel/typegen.d.ts +13 -0
- package/dist/kernel/typegen.js +76 -0
- package/dist/migrate/checksum.d.ts +11 -0
- package/dist/migrate/checksum.js +14 -0
- package/dist/migrate/index.d.ts +8 -0
- package/dist/migrate/index.js +8 -0
- package/dist/migrate/runner.d.ts +33 -0
- package/dist/migrate/runner.js +126 -0
- package/dist/migrate/step.d.ts +37 -0
- package/dist/migrate/step.js +31 -0
- package/dist/pglite/dialect.d.ts +11 -0
- package/dist/pglite/dialect.js +88 -0
- package/dist/pglite/driver.d.ts +30 -0
- package/dist/pglite/driver.js +46 -0
- package/dist/pglite/index.d.ts +5 -0
- package/dist/pglite/index.js +4 -0
- package/dist/pglite/ops.d.ts +39 -0
- package/dist/pglite/ops.js +78 -0
- package/dist/pglite/owner.d.ts +107 -0
- package/dist/pglite/owner.js +359 -0
- package/dist/pglite/socket-server.d.ts +38 -0
- package/dist/pglite/socket-server.js +375 -0
- package/dist/pglite/types.d.ts +9 -0
- package/dist/pglite/types.js +2 -0
- package/dist/postgres/driver.d.ts +23 -0
- package/dist/postgres/driver.js +41 -0
- package/dist/postgres/index.d.ts +3 -0
- package/dist/postgres/index.js +3 -0
- package/dist/postgres/ops.d.ts +12 -0
- package/dist/postgres/ops.js +46 -0
- package/dist/postgres/pglite-socket.d.ts +23 -0
- package/dist/postgres/pglite-socket.js +51 -0
- package/dist/postgres/types.d.ts +53 -0
- package/dist/postgres/types.js +14 -0
- package/dist/sqlite/db-ops.d.ts +59 -0
- package/dist/sqlite/db-ops.js +82 -0
- package/dist/sqlite/driver.d.ts +71 -0
- package/dist/sqlite/driver.js +132 -0
- package/dist/sqlite/index.d.ts +9 -0
- package/dist/sqlite/index.js +4 -0
- package/dist/sqlite/inspect.d.ts +60 -0
- package/dist/sqlite/inspect.js +153 -0
- package/dist/sqlite/open.d.ts +58 -0
- package/dist/sqlite/open.js +43 -0
- package/dist/sqlite/ops.d.ts +12 -0
- package/dist/sqlite/ops.js +40 -0
- package/dist/sqlite/restore-types.d.ts +42 -0
- package/dist/sqlite/restore-types.js +2 -0
- package/dist/sqlite/sync-types.d.ts +34 -0
- package/dist/sqlite/sync-types.js +2 -0
- package/dist/sqlite/types.d.ts +37 -0
- package/dist/sqlite/types.js +8 -0
- package/dist/tools/database-catalog.d.ts +61 -0
- package/dist/tools/database-catalog.js +201 -0
- package/dist/tools/destination-port.d.ts +27 -0
- package/dist/tools/destination-port.js +2 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/plan-store.d.ts +61 -0
- package/dist/tools/plan-store.js +39 -0
- package/dist/tools/read-tools.d.ts +53 -0
- package/dist/tools/read-tools.js +97 -0
- package/dist/tools/registration.d.ts +18 -0
- package/dist/tools/registration.js +10 -0
- package/dist/tools/restore-points.d.ts +125 -0
- package/dist/tools/restore-points.js +54 -0
- package/dist/tools/surface-port.d.ts +43 -0
- package/dist/tools/surface-port.js +2 -0
- package/dist/tools/timeline.d.ts +63 -0
- package/dist/tools/timeline.js +46 -0
- package/dist/tools/transfer-catalog.d.ts +25 -0
- package/dist/tools/transfer-catalog.js +59 -0
- package/dist/tools/transfer-tools.d.ts +82 -0
- package/dist/tools/transfer-tools.js +346 -0
- package/dist/transfer/copy-engine.d.ts +129 -0
- package/dist/transfer/copy-engine.js +233 -0
- package/dist/transfer/index.d.ts +9 -0
- package/dist/transfer/index.js +9 -0
- package/dist/transfer/internal-ddl.d.ts +23 -0
- package/dist/transfer/internal-ddl.js +119 -0
- package/dist/transfer/plan.d.ts +28 -0
- package/dist/transfer/plan.js +19 -0
- package/dist/transfer/postgres-ddl.d.ts +36 -0
- package/dist/transfer/postgres-ddl.js +16 -0
- package/dist/transfer/postgres-target.d.ts +65 -0
- package/dist/transfer/postgres-target.js +95 -0
- package/dist/transfer/sqlite-source.d.ts +78 -0
- package/dist/transfer/sqlite-source.js +79 -0
- package/dist/transfer/table-catalog.d.ts +44 -0
- package/dist/transfer/table-catalog.js +109 -0
- package/dist/transfer/types.d.ts +47 -0
- package/dist/transfer/types.js +2 -0
- package/package.json +184 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { DbOpsPort, RestoreCapability, RestorePoint, WatermarkReader } from '../core/ports.js';
|
|
2
|
+
import type { SqliteBackupSource } from './restore-types.js';
|
|
3
|
+
export interface SqliteDbOpsAdapterDeps {
|
|
4
|
+
/**
|
|
5
|
+
* The raw driver handle, not an ORM wrapper. This adapter needs `backup` and nothing else, so a
|
|
6
|
+
* caller passes the connection directly — a host using Drizzle passes `handle.$client`. Taking
|
|
7
|
+
* the raw source rather than an object with a `$client` property keeps an ORM's naming
|
|
8
|
+
* convention off this package's surface entirely.
|
|
9
|
+
*/
|
|
10
|
+
readonly connection: SqliteBackupSource;
|
|
11
|
+
readonly filePath: string;
|
|
12
|
+
readonly readWatermark: WatermarkReader;
|
|
13
|
+
/** Injectable clock, so artifact names are deterministic under test. Defaults to `Date.now`. */
|
|
14
|
+
readonly now?: () => number;
|
|
15
|
+
}
|
|
16
|
+
export declare class SqliteDbOpsAdapter implements DbOpsPort {
|
|
17
|
+
private readonly connection;
|
|
18
|
+
private readonly filePath;
|
|
19
|
+
private readonly readWatermark;
|
|
20
|
+
private readonly now;
|
|
21
|
+
constructor(deps: SqliteDbOpsAdapterDeps);
|
|
22
|
+
/** Pure and side-effect-free — SQLite reports the same static capability every time. */
|
|
23
|
+
getCapabilities(): Promise<{
|
|
24
|
+
restorePoint: RestoreCapability;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Captures a whole-file online-backup copy, stamped with the watermark value at capture time.
|
|
28
|
+
* Never a partial or logical export — the artifact is byte-restorable by definition.
|
|
29
|
+
*
|
|
30
|
+
* An in-memory connection has no directory of its own, so its artifacts land in the OS temp
|
|
31
|
+
* directory rather than failing: the backup itself is still a real, consistent file.
|
|
32
|
+
*/
|
|
33
|
+
captureRestorePoint(required: {
|
|
34
|
+
scopeId: string;
|
|
35
|
+
}): Promise<RestorePoint>;
|
|
36
|
+
/**
|
|
37
|
+
* Physically swaps the live database file for a previously-captured artifact.
|
|
38
|
+
*
|
|
39
|
+
* Crash-safety: the artifact is copied to a same-directory temp file first, then moved with a
|
|
40
|
+
* single `fs.rename()` — atomic on the same filesystem under POSIX rename semantics. If the
|
|
41
|
+
* process dies before the rename, the live file is untouched; the rename itself either fully
|
|
42
|
+
* completes or does not happen, never a partial file.
|
|
43
|
+
*
|
|
44
|
+
* `restartRequired` is always `true` here, and that is causal rather than incidental: the
|
|
45
|
+
* running process keeps its own file descriptor pointed at the now-unlinked old inode and
|
|
46
|
+
* goes on serving from it, unaware anything changed, until it reopens `filePath` fresh.
|
|
47
|
+
*
|
|
48
|
+
* Stale `-wal`/`-shm` sidecar cleanup is best-effort. SQLite's WAL header carries a salt tied
|
|
49
|
+
* to the specific main-file version it was written against, so an un-cleaned sidecar cannot
|
|
50
|
+
* silently corrupt the swapped-in file on next boot — SQLite detects the mismatch and discards
|
|
51
|
+
* it. This cleanup removes ambiguity; skipping it would not be unsafe.
|
|
52
|
+
*/
|
|
53
|
+
restoreFromArtifact(required: {
|
|
54
|
+
artifactRef: string;
|
|
55
|
+
}): Promise<{
|
|
56
|
+
restartRequired: boolean;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=db-ops.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The SQLite implementation of `DbOpsPort`.
|
|
3
|
+
*
|
|
4
|
+
* SQLite-backed hosts always have a cheap restore mechanism available: a whole-file online
|
|
5
|
+
* backup via `better-sqlite3`'s native backup API, which produces a consistent copy even while
|
|
6
|
+
* the source connection has an open WAL. That is why this driver reports `costClass: 'cheap'`
|
|
7
|
+
* unconditionally, and why a networked driver implementing the same port would not.
|
|
8
|
+
*
|
|
9
|
+
* The watermark is injected (`readWatermark`) rather than read from a table this package would
|
|
10
|
+
* have to know the name of — see `WatermarkReader` in `db/core/ports.ts`.
|
|
11
|
+
*/
|
|
12
|
+
import { randomBytes } from 'node:crypto';
|
|
13
|
+
import fs from 'node:fs/promises';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { restorePointFilename } from '../core/artifact-naming.js';
|
|
17
|
+
/** Sentinel `filePath` for an ephemeral connection with no file behind it. */
|
|
18
|
+
const IN_MEMORY = ':memory:';
|
|
19
|
+
export class SqliteDbOpsAdapter {
|
|
20
|
+
connection;
|
|
21
|
+
filePath;
|
|
22
|
+
readWatermark;
|
|
23
|
+
now;
|
|
24
|
+
constructor(deps) {
|
|
25
|
+
this.connection = deps.connection;
|
|
26
|
+
this.filePath = deps.filePath;
|
|
27
|
+
this.readWatermark = deps.readWatermark;
|
|
28
|
+
this.now = deps.now ?? Date.now;
|
|
29
|
+
}
|
|
30
|
+
/** Pure and side-effect-free — SQLite reports the same static capability every time. */
|
|
31
|
+
async getCapabilities() {
|
|
32
|
+
return { restorePoint: { costClass: 'cheap', kind: 'file-snapshot' } };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Captures a whole-file online-backup copy, stamped with the watermark value at capture time.
|
|
36
|
+
* Never a partial or logical export — the artifact is byte-restorable by definition.
|
|
37
|
+
*
|
|
38
|
+
* An in-memory connection has no directory of its own, so its artifacts land in the OS temp
|
|
39
|
+
* directory rather than failing: the backup itself is still a real, consistent file.
|
|
40
|
+
*/
|
|
41
|
+
async captureRestorePoint(required) {
|
|
42
|
+
const watermarkAtCapture = await this.readWatermark();
|
|
43
|
+
const targetDir = this.filePath === IN_MEMORY ? os.tmpdir() : path.dirname(this.filePath);
|
|
44
|
+
const artifactRef = path.join(targetDir, restorePointFilename({ scopeId: required.scopeId, watermarkAtCapture, timestamp: this.now() }));
|
|
45
|
+
await this.connection.backup(artifactRef);
|
|
46
|
+
return { artifactRef, watermarkAtCapture };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Physically swaps the live database file for a previously-captured artifact.
|
|
50
|
+
*
|
|
51
|
+
* Crash-safety: the artifact is copied to a same-directory temp file first, then moved with a
|
|
52
|
+
* single `fs.rename()` — atomic on the same filesystem under POSIX rename semantics. If the
|
|
53
|
+
* process dies before the rename, the live file is untouched; the rename itself either fully
|
|
54
|
+
* completes or does not happen, never a partial file.
|
|
55
|
+
*
|
|
56
|
+
* `restartRequired` is always `true` here, and that is causal rather than incidental: the
|
|
57
|
+
* running process keeps its own file descriptor pointed at the now-unlinked old inode and
|
|
58
|
+
* goes on serving from it, unaware anything changed, until it reopens `filePath` fresh.
|
|
59
|
+
*
|
|
60
|
+
* Stale `-wal`/`-shm` sidecar cleanup is best-effort. SQLite's WAL header carries a salt tied
|
|
61
|
+
* to the specific main-file version it was written against, so an un-cleaned sidecar cannot
|
|
62
|
+
* silently corrupt the swapped-in file on next boot — SQLite detects the mismatch and discards
|
|
63
|
+
* it. This cleanup removes ambiguity; skipping it would not be unsafe.
|
|
64
|
+
*/
|
|
65
|
+
async restoreFromArtifact(required) {
|
|
66
|
+
if (this.filePath === IN_MEMORY) {
|
|
67
|
+
// No file to restore into, and no descriptor to invalidate — so no restart either.
|
|
68
|
+
return { restartRequired: false };
|
|
69
|
+
}
|
|
70
|
+
await fs.access(required.artifactRef);
|
|
71
|
+
const dir = path.dirname(this.filePath);
|
|
72
|
+
const tmpPath = path.join(dir, `.${path.basename(this.filePath)}.restoring-${randomBytes(6).toString('hex')}`);
|
|
73
|
+
await fs.copyFile(required.artifactRef, tmpPath);
|
|
74
|
+
await fs.rename(tmpPath, this.filePath);
|
|
75
|
+
await Promise.allSettled([
|
|
76
|
+
fs.rm(`${this.filePath}-wal`, { force: true }),
|
|
77
|
+
fs.rm(`${this.filePath}-shm`, { force: true }),
|
|
78
|
+
]);
|
|
79
|
+
return { restartRequired: true };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=db-ops.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type StorageKernel } from "../kernel/index.js";
|
|
2
|
+
import type { SqliteClient, SqliteOpener } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file The better-sqlite3 driver: a kernel over an ALREADY OPEN SQLite connection the consumer
|
|
5
|
+
* opened (and migrated) itself. Wrapping instead of opening keeps an existing database exactly as it
|
|
6
|
+
* was: same file, same pragmas, same migrations.
|
|
7
|
+
*
|
|
8
|
+
* This package never imports better-sqlite3: the consumer passes its own client (or, for
|
|
9
|
+
* {@link openSqliteFileKernel}, its own opener). Two copies of the SQLite library in one process
|
|
10
|
+
* would share POSIX locks, a documented way to corrupt a database. Accepts an ORM handle that
|
|
11
|
+
* carries its client as `$client` (Drizzle's shape) and reads the client; the handle itself is not
|
|
12
|
+
* used. ONE kernel per connection ({@link sqliteKernel} memoizes on the
|
|
13
|
+
* client): the transaction scope only protects callers that share it. The turn lock is per FILE:
|
|
14
|
+
* every connection to one database file in this process takes turns on the same lock (see
|
|
15
|
+
* `KernelDriver.turnLock`).
|
|
16
|
+
*
|
|
17
|
+
* Queries go through Kysely's own SQLite dialect over a thin binding shim: SQLite cannot bind a
|
|
18
|
+
* boolean, so `true`/`false` are written as `1`/`0` (the usual SQLite boolean encoding). Reads
|
|
19
|
+
* of those columns come back as `0`/`1` — the generated types say `SqlBool` so a repo converts.
|
|
20
|
+
*
|
|
21
|
+
* Transactions are `BEGIN IMMEDIATE` on the connection, not Kysely's `transaction()` (which issues a
|
|
22
|
+
* deferred `BEGIN`): IMMEDIATE takes the write lock up front, which is what makes `lockKey` a no-op
|
|
23
|
+
* here and keeps read-then-write sequences from failing with SQLITE_BUSY halfway through.
|
|
24
|
+
*
|
|
25
|
+
* The connection's opener closes it; `close()` here does nothing.
|
|
26
|
+
*/
|
|
27
|
+
export type SqliteKernel<DB> = StorageKernel<DB>;
|
|
28
|
+
/** An ORM handle that carries its better-sqlite3 client as `$client`, or the client itself. */
|
|
29
|
+
export type SqliteConnectionSource = SqliteClient | {
|
|
30
|
+
readonly $client: SqliteClient;
|
|
31
|
+
};
|
|
32
|
+
/** The better-sqlite3 client under `source` (a handle's `$client`, or the client itself). */
|
|
33
|
+
export declare function sqliteClientOf(source: SqliteConnectionSource): SqliteClient;
|
|
34
|
+
export declare function sqliteKernel<DB>(source: SqliteConnectionSource): SqliteKernel<DB>;
|
|
35
|
+
/**
|
|
36
|
+
* A kernel over a new private in-memory SQLite database (foreign keys on). `close()` closes the
|
|
37
|
+
* connection. For scratch work, e.g. building a reference schema.
|
|
38
|
+
*
|
|
39
|
+
* @param required.open the consumer's better-sqlite3 opener, e.g. `(p, o) => new Database(p, o)`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function openMemorySqliteKernel<DB>(required: {
|
|
42
|
+
open: SqliteOpener;
|
|
43
|
+
}): SqliteKernel<DB>;
|
|
44
|
+
/**
|
|
45
|
+
* A kernel over its OWN connection to the SQLite file at `filePath`, opened as-is: no migration, no
|
|
46
|
+
* WAL switch, foreign keys on, a 5 s busy timeout. `close()` closes the connection.
|
|
47
|
+
*
|
|
48
|
+
* For ops on a database file that is not the running app's (a duplicate being prepared, a directory
|
|
49
|
+
* being inspected). `readOnly` opens with better-sqlite3's own `readonly` mode, so SQLite itself
|
|
50
|
+
* rejects any write, and requires the file to exist.
|
|
51
|
+
*
|
|
52
|
+
* @param required.open the consumer's better-sqlite3 opener, e.g. `(p, o) => new Database(p, o)`,
|
|
53
|
+
* so the connection comes from the consumer's own copy of the library.
|
|
54
|
+
* @throws whatever the opener throws opening the file (missing file when `readOnly`, not a
|
|
55
|
+
* database, locked).
|
|
56
|
+
*/
|
|
57
|
+
export declare function openSqliteFileKernel<DB>(required: {
|
|
58
|
+
filePath: string;
|
|
59
|
+
open: SqliteOpener;
|
|
60
|
+
}, optional?: {
|
|
61
|
+
readOnly?: boolean;
|
|
62
|
+
}): SqliteKernel<DB>;
|
|
63
|
+
/**
|
|
64
|
+
* Closes the better-sqlite3 connection under `source` (a handle carrying `$client`, or the client)
|
|
65
|
+
* and forgets its kernel. For callers that opened a database themselves and must
|
|
66
|
+
* release it; the kernel's own `close()` never closes a connection it did not open.
|
|
67
|
+
*/
|
|
68
|
+
export declare function closeSqliteConnection(source: SqliteConnectionSource): void;
|
|
69
|
+
/** The connection under a kernel this driver built, for the SQLite `StorageOps` (`./ops.ts`). */
|
|
70
|
+
export declare function sqliteConnectionOf<DB>(kernel: StorageKernel<DB>): SqliteClient | undefined;
|
|
71
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { Kysely, SqliteDialect } from "kysely";
|
|
3
|
+
import { buildKernel, TurnLock } from "../kernel/index.js";
|
|
4
|
+
const kernels = new WeakMap();
|
|
5
|
+
/** The reverse of `kernels`, plus the owning kernels {@link openSqliteFileKernel} hands out. */
|
|
6
|
+
const connectionsByKernel = new WeakMap();
|
|
7
|
+
/** One turn lock per database FILE, shared by every connection to it in this process. */
|
|
8
|
+
const fileTurnLocks = new Map();
|
|
9
|
+
function turnLockFor(client) {
|
|
10
|
+
if (client.memory)
|
|
11
|
+
return undefined;
|
|
12
|
+
const file = path.resolve(client.name);
|
|
13
|
+
let lock = fileTurnLocks.get(file);
|
|
14
|
+
if (lock === undefined) {
|
|
15
|
+
lock = new TurnLock();
|
|
16
|
+
fileTurnLocks.set(file, lock);
|
|
17
|
+
}
|
|
18
|
+
return lock;
|
|
19
|
+
}
|
|
20
|
+
/** The better-sqlite3 client under `source` (a handle's `$client`, or the client itself). */
|
|
21
|
+
export function sqliteClientOf(source) {
|
|
22
|
+
return "$client" in source ? source.$client : source;
|
|
23
|
+
}
|
|
24
|
+
const bindable = (value) => (typeof value === "boolean" ? (value ? 1 : 0) : value);
|
|
25
|
+
/** better-sqlite3 as Kysely's `SqliteDatabase`, with booleans bound as integers. */
|
|
26
|
+
function bindingShim(client) {
|
|
27
|
+
return {
|
|
28
|
+
close: () => { },
|
|
29
|
+
prepare(sqlText) {
|
|
30
|
+
const statement = client.prepare(sqlText);
|
|
31
|
+
const bind = (parameters) => parameters.map(bindable);
|
|
32
|
+
return {
|
|
33
|
+
reader: statement.reader,
|
|
34
|
+
all: (parameters) => statement.all(bind(parameters)),
|
|
35
|
+
run: (parameters) => statement.run(bind(parameters)),
|
|
36
|
+
iterate: (parameters) => statement.iterate(bind(parameters)),
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function sqliteKernel(source) {
|
|
42
|
+
const client = sqliteClientOf(source);
|
|
43
|
+
const known = kernels.get(client);
|
|
44
|
+
if (known !== undefined)
|
|
45
|
+
return known;
|
|
46
|
+
const base = new Kysely({ dialect: new SqliteDialect({ database: bindingShim(client) }) });
|
|
47
|
+
const kernel = buildKernel({
|
|
48
|
+
dialect: "sqlite",
|
|
49
|
+
transport: "better-sqlite3",
|
|
50
|
+
capabilities: { interactiveTransactions: true, atomicBatch: true, transactionalDdl: true, backup: true },
|
|
51
|
+
ready: Promise.resolve(),
|
|
52
|
+
base,
|
|
53
|
+
oneConnection: true,
|
|
54
|
+
turnLock: turnLockFor(client),
|
|
55
|
+
async begin(body) {
|
|
56
|
+
client.exec("BEGIN IMMEDIATE");
|
|
57
|
+
try {
|
|
58
|
+
const result = await body(base);
|
|
59
|
+
client.exec("COMMIT");
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (client.inTransaction)
|
|
64
|
+
client.exec("ROLLBACK");
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
// BEGIN IMMEDIATE already holds the database write lock for the whole transaction.
|
|
69
|
+
lockKey: async () => { },
|
|
70
|
+
foreignTransactionOpen: () => client.inTransaction,
|
|
71
|
+
backup: async (destPath) => {
|
|
72
|
+
await client.backup(destPath);
|
|
73
|
+
},
|
|
74
|
+
close: async () => { },
|
|
75
|
+
});
|
|
76
|
+
kernels.set(client, kernel);
|
|
77
|
+
connectionsByKernel.set(kernel, client);
|
|
78
|
+
return kernel;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A kernel over a new private in-memory SQLite database (foreign keys on). `close()` closes the
|
|
82
|
+
* connection. For scratch work, e.g. building a reference schema.
|
|
83
|
+
*
|
|
84
|
+
* @param required.open the consumer's better-sqlite3 opener, e.g. `(p, o) => new Database(p, o)`.
|
|
85
|
+
*/
|
|
86
|
+
export function openMemorySqliteKernel(required) {
|
|
87
|
+
return openSqliteFileKernel({ filePath: ":memory:", open: required.open });
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A kernel over its OWN connection to the SQLite file at `filePath`, opened as-is: no migration, no
|
|
91
|
+
* WAL switch, foreign keys on, a 5 s busy timeout. `close()` closes the connection.
|
|
92
|
+
*
|
|
93
|
+
* For ops on a database file that is not the running app's (a duplicate being prepared, a directory
|
|
94
|
+
* being inspected). `readOnly` opens with better-sqlite3's own `readonly` mode, so SQLite itself
|
|
95
|
+
* rejects any write, and requires the file to exist.
|
|
96
|
+
*
|
|
97
|
+
* @param required.open the consumer's better-sqlite3 opener, e.g. `(p, o) => new Database(p, o)`,
|
|
98
|
+
* so the connection comes from the consumer's own copy of the library.
|
|
99
|
+
* @throws whatever the opener throws opening the file (missing file when `readOnly`, not a
|
|
100
|
+
* database, locked).
|
|
101
|
+
*/
|
|
102
|
+
export function openSqliteFileKernel(required, optional = {}) {
|
|
103
|
+
const readOnly = optional.readOnly === true;
|
|
104
|
+
const client = required.open(required.filePath, readOnly ? { readonly: true, fileMustExist: true } : {});
|
|
105
|
+
// A second connection to a file another may be writing: wait out a transient lock rather than
|
|
106
|
+
// throwing SQLITE_BUSY at once.
|
|
107
|
+
client.pragma("busy_timeout = 5000");
|
|
108
|
+
if (!readOnly)
|
|
109
|
+
client.pragma("foreign_keys = ON");
|
|
110
|
+
const kernel = sqliteKernel(client);
|
|
111
|
+
const owned = {
|
|
112
|
+
...kernel,
|
|
113
|
+
close: async () => closeSqliteConnection(client),
|
|
114
|
+
};
|
|
115
|
+
connectionsByKernel.set(owned, client);
|
|
116
|
+
return owned;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Closes the better-sqlite3 connection under `source` (a handle carrying `$client`, or the client)
|
|
120
|
+
* and forgets its kernel. For callers that opened a database themselves and must
|
|
121
|
+
* release it; the kernel's own `close()` never closes a connection it did not open.
|
|
122
|
+
*/
|
|
123
|
+
export function closeSqliteConnection(source) {
|
|
124
|
+
const client = sqliteClientOf(source);
|
|
125
|
+
kernels.delete(client);
|
|
126
|
+
client.close();
|
|
127
|
+
}
|
|
128
|
+
/** The connection under a kernel this driver built, for the SQLite `StorageOps` (`./ops.ts`). */
|
|
129
|
+
export function sqliteConnectionOf(kernel) {
|
|
130
|
+
return connectionsByKernel.get(kernel);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** SQLite connection policy and restore operations; inject the consumer's opener. */
|
|
2
|
+
export type { SqliteClient, SqliteOpener, SqliteOpenOptions, SqliteStatement } from "./types.js";
|
|
3
|
+
export { openSqliteConnection, DEFAULT_PRAGMAS } from "./open.js";
|
|
4
|
+
export { SqliteDbOpsAdapter, type SqliteDbOpsAdapterDeps } from "./db-ops.js";
|
|
5
|
+
export type { SqliteBackupSource, SqliteRecoveryHook, OpenSqliteConnectionOptions } from "./restore-types.js";
|
|
6
|
+
export type { SqliteSyncClient, SqliteSyncStatement, SqliteSyncTransaction, SqliteSyncOpener, SqliteDb } from "./sync-types.js";
|
|
7
|
+
export { inspectSqliteDatabase, verifySqliteIntegrity } from "./inspect.js";
|
|
8
|
+
export type { DaemonDbTableInfo, DaemonDbStatusReport, DbIntegrityIssueKind, DbIntegrityIssue, DbIntegrityReport, VerifyDbOptions } from "./inspect.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { SqliteDb } from './sync-types.js';
|
|
2
|
+
export interface DaemonDbTableInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
rowCount: number;
|
|
5
|
+
}
|
|
6
|
+
export interface DaemonDbStatusReport {
|
|
7
|
+
kind: 'sqlite' | 'postgres';
|
|
8
|
+
/** Absolute path on disk (sqlite); connection identifier (postgres, e.g. `'host:port/db'`). */
|
|
9
|
+
location: string;
|
|
10
|
+
/**
|
|
11
|
+
* Total bytes the DB file occupies. Sums the primary file plus `-wal`/`-shm`
|
|
12
|
+
* so the report matches `du -h` rather than just the primary file.
|
|
13
|
+
*/
|
|
14
|
+
sizeBytes: number;
|
|
15
|
+
schemaVersion: number | null;
|
|
16
|
+
tables: DaemonDbTableInfo[];
|
|
17
|
+
generatedAt: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Builds a structured inventory of a `better-sqlite3` database: schema version,
|
|
21
|
+
* per-table row counts (system tables excluded), and total on-disk size
|
|
22
|
+
* (primary file + `-wal` + `-shm`).
|
|
23
|
+
*
|
|
24
|
+
* @param input - The open database handle and its on-disk file path.
|
|
25
|
+
* @returns The status report. Never throws — schema-read and per-table failures
|
|
26
|
+
* degrade to `null`/`0`/an empty list rather than failing the whole report.
|
|
27
|
+
*/
|
|
28
|
+
export declare function inspectSqliteDatabase(input: {
|
|
29
|
+
db: SqliteDb;
|
|
30
|
+
file: string;
|
|
31
|
+
}): Promise<DaemonDbStatusReport>;
|
|
32
|
+
export type DbIntegrityIssueKind = 'integrity' | 'foreign_key';
|
|
33
|
+
export interface DbIntegrityIssue {
|
|
34
|
+
kind: DbIntegrityIssueKind;
|
|
35
|
+
message: string;
|
|
36
|
+
}
|
|
37
|
+
export interface DbIntegrityReport {
|
|
38
|
+
ok: boolean;
|
|
39
|
+
/** `'integrity_check'` (default) or `'quick_check'` — quick is faster but skips the index-content check. */
|
|
40
|
+
mode: 'integrity_check' | 'quick_check';
|
|
41
|
+
issues: DbIntegrityIssue[];
|
|
42
|
+
elapsedMs: number;
|
|
43
|
+
generatedAt: number;
|
|
44
|
+
}
|
|
45
|
+
export interface VerifyDbOptions {
|
|
46
|
+
db: SqliteDb;
|
|
47
|
+
quick?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Runs `PRAGMA integrity_check` (or `quick_check`) plus `PRAGMA foreign_key_check`
|
|
51
|
+
* against an open database and returns a structured report so a CLI can
|
|
52
|
+
* pretty-print it and automation can parse the JSON.
|
|
53
|
+
*
|
|
54
|
+
* @param opts - The open database handle and whether to use the faster `quick_check` variant.
|
|
55
|
+
* @returns `{ ok: true }` when both pragmas report clean; otherwise the list of issues found.
|
|
56
|
+
* A pragma that throws is itself recorded as one `integrity`/`foreign_key` issue rather than
|
|
57
|
+
* propagating — a caller polling DB health should always get a report, not an exception.
|
|
58
|
+
*/
|
|
59
|
+
export declare function verifySqliteIntegrity(opts: VerifyDbOptions): DbIntegrityReport;
|
|
60
|
+
//# sourceMappingURL=inspect.d.ts.map
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module db-inspect
|
|
3
|
+
*
|
|
4
|
+
* Pure `better-sqlite3` inspection helpers: a structured inventory (file size,
|
|
5
|
+
* table list, per-table row count, `user_version` schema pragma) and an
|
|
6
|
+
* integrity check (`PRAGMA integrity_check`/`quick_check` + `foreign_key_check`).
|
|
7
|
+
* Useful behind a host daemon's own ops CLI (a `db status` subcommand) or a
|
|
8
|
+
* diagnostics aggregator that folds the summary in without re-implementing the
|
|
9
|
+
* SQLite read.
|
|
10
|
+
*
|
|
11
|
+
* Pure relative to its inputs: callers pass the SQLite handle + the on-disk
|
|
12
|
+
* file path. Neither function opens a new connection or mutates state.
|
|
13
|
+
*/
|
|
14
|
+
import { promises as fsp } from 'node:fs';
|
|
15
|
+
const SYSTEM_TABLE_PREFIXES = ['sqlite_', 'better_sqlite3_'];
|
|
16
|
+
function isSystemTable(name) {
|
|
17
|
+
return SYSTEM_TABLE_PREFIXES.some((p) => name.startsWith(p));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Builds a structured inventory of a `better-sqlite3` database: schema version,
|
|
21
|
+
* per-table row counts (system tables excluded), and total on-disk size
|
|
22
|
+
* (primary file + `-wal` + `-shm`).
|
|
23
|
+
*
|
|
24
|
+
* @param input - The open database handle and its on-disk file path.
|
|
25
|
+
* @returns The status report. Never throws — schema-read and per-table failures
|
|
26
|
+
* degrade to `null`/`0`/an empty list rather than failing the whole report.
|
|
27
|
+
*/
|
|
28
|
+
export async function inspectSqliteDatabase(input) {
|
|
29
|
+
const { db, file } = input;
|
|
30
|
+
// 1. Schema version (user_version pragma).
|
|
31
|
+
let schemaVersion = null;
|
|
32
|
+
try {
|
|
33
|
+
const v = db.pragma('user_version', { simple: true });
|
|
34
|
+
schemaVersion = typeof v === 'number' ? v : Number(v);
|
|
35
|
+
if (!Number.isFinite(schemaVersion))
|
|
36
|
+
schemaVersion = null;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
schemaVersion = null;
|
|
40
|
+
}
|
|
41
|
+
// 2. Table list with row counts.
|
|
42
|
+
const tables = [];
|
|
43
|
+
try {
|
|
44
|
+
const names = db.prepare(`SELECT name FROM sqlite_master WHERE type='table' ORDER BY name`).all();
|
|
45
|
+
for (const { name } of names) {
|
|
46
|
+
if (isSystemTable(name))
|
|
47
|
+
continue;
|
|
48
|
+
try {
|
|
49
|
+
const safe = sanitizeTableName(name);
|
|
50
|
+
if (!safe)
|
|
51
|
+
continue;
|
|
52
|
+
const row = db.prepare(`SELECT count(*) AS c FROM "${safe}"`).get();
|
|
53
|
+
tables.push({ name: safe, rowCount: row?.c ?? 0 });
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// A malformed view / corrupted table shouldn't fail the whole report; record 0 rows.
|
|
57
|
+
tables.push({ name, rowCount: 0 });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// ignore — empty tables[] surfaces "cannot read schema" to the caller (a CLI shows 0 tables,
|
|
63
|
+
// which is itself a useful signal).
|
|
64
|
+
}
|
|
65
|
+
// 3. File size = primary + -wal + -shm so the number matches du.
|
|
66
|
+
const sizeBytes = await sumFileSizes([file, `${file}-wal`, `${file}-shm`]);
|
|
67
|
+
return {
|
|
68
|
+
kind: 'sqlite',
|
|
69
|
+
location: file,
|
|
70
|
+
sizeBytes,
|
|
71
|
+
schemaVersion,
|
|
72
|
+
tables,
|
|
73
|
+
generatedAt: Date.now(),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async function sumFileSizes(paths) {
|
|
77
|
+
let total = 0;
|
|
78
|
+
for (const p of paths) {
|
|
79
|
+
try {
|
|
80
|
+
const stat = await fsp.stat(p);
|
|
81
|
+
total += stat.size;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// missing -wal / -shm is normal when the DB hasn't been written since open.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return total;
|
|
88
|
+
}
|
|
89
|
+
function sanitizeTableName(name) {
|
|
90
|
+
// Allow ASCII alphanumerics + underscore; SQLite identifier sanity check. Prevents accidental
|
|
91
|
+
// SQL injection if a malicious migration ever invents a hostile table name.
|
|
92
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
93
|
+
return null;
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Runs `PRAGMA integrity_check` (or `quick_check`) plus `PRAGMA foreign_key_check`
|
|
98
|
+
* against an open database and returns a structured report so a CLI can
|
|
99
|
+
* pretty-print it and automation can parse the JSON.
|
|
100
|
+
*
|
|
101
|
+
* @param opts - The open database handle and whether to use the faster `quick_check` variant.
|
|
102
|
+
* @returns `{ ok: true }` when both pragmas report clean; otherwise the list of issues found.
|
|
103
|
+
* A pragma that throws is itself recorded as one `integrity`/`foreign_key` issue rather than
|
|
104
|
+
* propagating — a caller polling DB health should always get a report, not an exception.
|
|
105
|
+
*/
|
|
106
|
+
export function verifySqliteIntegrity(opts) {
|
|
107
|
+
const { db, quick = false } = opts;
|
|
108
|
+
const startedAt = Date.now();
|
|
109
|
+
const issues = [];
|
|
110
|
+
// 1. integrity_check / quick_check.
|
|
111
|
+
const pragma = quick ? 'quick_check' : 'integrity_check';
|
|
112
|
+
try {
|
|
113
|
+
const rows = db.pragma(pragma);
|
|
114
|
+
for (const row of rows) {
|
|
115
|
+
// SQLite returns the string under either `integrity_check`, `quick_check`, or just the
|
|
116
|
+
// first column. Normalise to the first string-valued field.
|
|
117
|
+
const message = (row[pragma] ?? Object.values(row)[0]);
|
|
118
|
+
if (typeof message !== 'string')
|
|
119
|
+
continue;
|
|
120
|
+
if (message.toLowerCase() === 'ok')
|
|
121
|
+
continue;
|
|
122
|
+
issues.push({ kind: 'integrity', message });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
issues.push({ kind: 'integrity', message: `pragma ${pragma} threw: ${err.message}` });
|
|
127
|
+
}
|
|
128
|
+
// 2. foreign_key_check.
|
|
129
|
+
try {
|
|
130
|
+
const rows = db.pragma('foreign_key_check');
|
|
131
|
+
for (const row of rows) {
|
|
132
|
+
const tbl = row.table ?? '?';
|
|
133
|
+
const parent = row.parent ?? '?';
|
|
134
|
+
const fkid = row.fkid ?? '?';
|
|
135
|
+
const rowid = row.rowid ?? '?';
|
|
136
|
+
issues.push({
|
|
137
|
+
kind: 'foreign_key',
|
|
138
|
+
message: `FK violation in ${tbl} (rowid=${rowid}) referencing ${parent} (fkid=${fkid})`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
issues.push({ kind: 'foreign_key', message: `pragma foreign_key_check threw: ${err.message}` });
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
ok: issues.length === 0,
|
|
147
|
+
mode: quick ? 'quick_check' : 'integrity_check',
|
|
148
|
+
issues,
|
|
149
|
+
elapsedMs: Date.now() - startedAt,
|
|
150
|
+
generatedAt: Date.now(),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=inspect.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Opens a SQLite connection: connect, apply pragmas, hand back the raw driver handle.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately ORM-free. An earlier version of this function took a Drizzle schema, ran Drizzle's
|
|
5
|
+
* migrator, and returned a Drizzle handle — which made `drizzle-orm` a peer dependency of this
|
|
6
|
+
* package and put an ORM's types on its public surface. Two things were wrong with that:
|
|
7
|
+
*
|
|
8
|
+
* 1. **It coupled every consumer of this package to one ORM.** A host using Kysely, raw SQL, or a
|
|
9
|
+
* future replacement for Drizzle could not use the connection helper at all, even though
|
|
10
|
+
* opening a file and setting pragmas has nothing to do with how you then query it.
|
|
11
|
+
* 2. **It did not actually work across the package boundary.** Drizzle's classes carry
|
|
12
|
+
* `protected config` and `private shouldInlineParams`, so TypeScript compares them nominally.
|
|
13
|
+
* A consumer resolving a second physical copy of `drizzle-orm` (which a `file:`-linked checkout
|
|
14
|
+
* does, through the symlink's real path) cannot pass its own tables into a signature typed
|
|
15
|
+
* against this package's copy — measured at 604 errors across 34 files in one real host.
|
|
16
|
+
*
|
|
17
|
+
* So the ORM, the schema, and the migrations all stay with the host. What is genuinely reusable —
|
|
18
|
+
* and what this package keeps — is the connection lifecycle: where the file is, which pragmas make
|
|
19
|
+
* a single-file database viable under concurrent load, and the pre-open recovery seam.
|
|
20
|
+
*
|
|
21
|
+
* Migration running moved out with the ORM. A host wraps this handle in whatever it uses
|
|
22
|
+
* (`drizzle(conn, { schema })`) and runs its own migrator; migrations are product schema, and this
|
|
23
|
+
* package has no business knowing a host's tables.
|
|
24
|
+
*/
|
|
25
|
+
import type { SqliteClient } from './types.js';
|
|
26
|
+
import type { OpenSqliteConnectionOptions } from './restore-types.js';
|
|
27
|
+
/**
|
|
28
|
+
* Applied when a caller passes no `pragmas`.
|
|
29
|
+
*
|
|
30
|
+
* Measured baseline (better-sqlite3 11.x opened with no pragmas at all): `foreign_keys=1`,
|
|
31
|
+
* `busy_timeout=5000`, `journal_mode='delete'` for a file db and `'memory'` for `:memory:`.
|
|
32
|
+
* So of the three below, **only `journal_mode = WAL` changes behaviour** — the other two restate a
|
|
33
|
+
* default the driver already applies.
|
|
34
|
+
*
|
|
35
|
+
* - `journal_mode = WAL` — the load-bearing one. Readers stop blocking the writer, which is what
|
|
36
|
+
* makes a single-file database viable under a web server's concurrent request load.
|
|
37
|
+
* - `foreign_keys = ON` — raw SQLite defaults this OFF for backwards compatibility and
|
|
38
|
+
* better-sqlite3 turns it back on. Restated so the guarantee survives a driver change rather
|
|
39
|
+
* than being silently inherited.
|
|
40
|
+
* - `busy_timeout = 5000` — a second connection (a plugin's own handle, a migration runner) can
|
|
41
|
+
* transiently hold a write lock; retrying inside the driver beats surfacing SQLITE_BUSY to a
|
|
42
|
+
* request handler with no better recourse than to retry anyway.
|
|
43
|
+
*
|
|
44
|
+
* Consequence worth knowing when writing tests: neither `foreign_keys` nor `busy_timeout` can tell
|
|
45
|
+
* you whether this list ran, because both read the same value if it did not. `journal_mode` on a
|
|
46
|
+
* file-backed database is the only usable probe.
|
|
47
|
+
*/
|
|
48
|
+
export declare const DEFAULT_PRAGMAS: readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* Opens (or creates) a SQLite database and applies pragmas.
|
|
51
|
+
*
|
|
52
|
+
* Returns the exact handle supplied by the injected `open`, preserving its structural type.
|
|
53
|
+
* Recovery runs before opening; pragma policy runs immediately afterwards.
|
|
54
|
+
* @throws Any error from the recovery hook, opener, or pragma application.
|
|
55
|
+
* @complexity O(p) calls for p pragmas; storage costs belong to the injected driver.
|
|
56
|
+
*/
|
|
57
|
+
export declare function openSqliteConnection<Connection extends SqliteClient>(options: OpenSqliteConnectionOptions<Connection>): Connection;
|
|
58
|
+
//# sourceMappingURL=open.d.ts.map
|