@jini-ai/db 0.7.2 → 0.7.3-next.1
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 +1 -7
- package/README.md +33 -17
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.js +0 -1
- package/dist/core/pg-types.d.ts +4 -1
- package/dist/core/pg-types.js +1 -1
- package/dist/core/row-values.d.ts +0 -30
- package/dist/core/row-values.js +1 -41
- package/dist/data-modules/data-module.d.ts +260 -4
- package/dist/data-modules/data-module.js +105 -83
- package/dist/data-modules/disk-headroom.js +1 -1
- package/dist/data-modules/index.d.ts +2 -2
- package/dist/data-modules/index.js +2 -2
- package/dist/data-modules/migration-journal.js +6 -6
- package/dist/data-modules/migration-recovery.js +2 -2
- package/dist/data-modules/plugin-identity.js +5 -5
- package/dist/data-modules/plugin-store.d.ts +4 -4
- package/dist/data-modules/restore.js +5 -5
- package/dist/data-modules/snapshot.d.ts +1 -1
- package/dist/data-modules/snapshot.js +3 -3
- package/dist/events/change-set-repo.sql.d.ts +70 -0
- package/dist/events/change-set-repo.sql.js +72 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +3 -0
- package/dist/events/outbox-repo.sql.d.ts +91 -0
- package/dist/events/outbox-repo.sql.js +108 -0
- package/dist/events/repo.rows.d.ts +44 -0
- package/dist/events/repo.rows.js +59 -0
- package/dist/gated-mutations/index.d.ts +3 -0
- package/dist/gated-mutations/index.js +2 -0
- package/dist/gated-mutations/repo.rows.d.ts +19 -0
- package/dist/gated-mutations/repo.rows.js +23 -0
- package/dist/gated-mutations/repo.sql.d.ts +67 -0
- package/dist/gated-mutations/repo.sql.js +71 -0
- package/dist/kernel/dialect.d.ts +53 -31
- package/dist/kernel/dialect.js +14 -36
- package/dist/kernel/index.d.ts +2 -2
- package/dist/kernel/index.js +1 -7
- package/dist/kernel/kernel-core.d.ts +7 -3
- package/dist/kernel/kernel-core.js +75 -66
- package/dist/kernel/ops.d.ts +9 -3
- package/dist/kernel/ops.js +2 -2
- package/dist/kernel/owned-transaction.d.ts +7 -7
- package/dist/kernel/owned-transaction.js +2 -2
- package/dist/kernel/pglite/driver.d.ts +2 -2
- package/dist/kernel/pglite/driver.js +18 -18
- package/dist/kernel/pglite/ops.d.ts +8 -3
- package/dist/kernel/pglite/ops.js +5 -5
- package/dist/kernel/port.d.ts +9 -76
- package/dist/kernel/port.js +1 -10
- package/dist/kernel/postgres/driver.d.ts +4 -2
- package/dist/kernel/postgres/driver.js +17 -17
- package/dist/kernel/postgres/ops.d.ts +5 -3
- package/dist/kernel/postgres/ops.js +3 -3
- package/dist/kernel/postgres/pglite-socket.d.ts +2 -2
- package/dist/kernel/postgres/pglite-socket.js +13 -13
- package/dist/kernel/schema-scope.d.ts +5 -2
- package/dist/kernel/schema-scope.js +1 -1
- package/dist/kernel/schema-shape.d.ts +7 -3
- package/dist/kernel/schema-shape.js +2 -2
- package/dist/kernel/session-lock.d.ts +6 -6
- package/dist/kernel/sqlite/driver.d.ts +16 -8
- package/dist/kernel/sqlite/driver.js +38 -38
- package/dist/kernel/sqlite/index.d.ts +1 -0
- package/dist/kernel/sqlite/index.js +1 -0
- package/dist/kernel/sqlite/ops.d.ts +4 -2
- package/dist/kernel/sqlite/ops.js +3 -3
- package/dist/kernel/sqlite/sqlite-only.d.ts +81 -0
- package/dist/kernel/sqlite/sqlite-only.js +58 -0
- package/dist/kernel/store-copy.d.ts +7 -7
- package/dist/kernel/store-copy.js +22 -14
- package/dist/kernel/typegen.d.ts +5 -3
- package/dist/kernel/typegen.js +1 -1
- package/dist/migrate/checksum.d.ts +3 -1
- package/dist/migrate/checksum.js +1 -1
- package/dist/migrate/index.d.ts +1 -1
- package/dist/migrate/legacy-ledger.d.ts +4 -4
- package/dist/migrate/runner.d.ts +12 -7
- package/dist/migrate/runner.js +7 -6
- package/dist/migrate/step.d.ts +3 -28
- package/dist/migrate/step.js +3 -3
- package/dist/owner-store/index.d.ts +47 -1
- package/dist/owner-store/index.js +28 -1
- package/dist/owner-store/migrations/0000_owner_store.d.ts +3 -2
- package/dist/owner-store/migrations/index.d.ts +1 -1
- package/dist/pglite/owner.d.ts +12 -4
- package/dist/pglite/owner.js +33 -27
- package/dist/pglite/socket-server.d.ts +5 -1
- package/dist/pglite/socket-server.js +5 -4
- package/dist/recovery/deep-link.d.ts +3 -3
- package/dist/recovery/degraded-banners.d.ts +3 -3
- package/dist/recovery/degraded-banners.js +3 -3
- package/dist/recovery/disclosure.d.ts +6 -6
- package/dist/recovery/disclosure.js +6 -6
- package/dist/recovery/evaluate-boot-migration-policy.d.ts +5 -5
- package/dist/recovery/evaluate-boot-migration-policy.js +5 -5
- package/dist/recovery/lookup-adapters.d.ts +1 -1
- package/dist/recovery/lookup-adapters.js +1 -1
- package/dist/recovery/migrate-forward-execute.d.ts +1 -1
- package/dist/recovery/migrate-forward-execute.js +5 -5
- package/dist/recovery/migrate-forward-hooks.d.ts +6 -6
- package/dist/recovery/migrate-forward-hooks.js +5 -5
- package/dist/recovery/operation-lock.d.ts +11 -11
- package/dist/recovery/operation-lock.js +3 -3
- package/dist/recovery/reconcile-interrupted-migration.d.ts +7 -7
- package/dist/recovery/reconcile-interrupted-migration.js +7 -7
- package/dist/recovery/recovery-orchestrator.d.ts +21 -21
- package/dist/recovery/recovery-orchestrator.js +9 -9
- package/dist/recovery/restore-hooks.d.ts +8 -8
- package/dist/recovery/restore-hooks.js +7 -7
- package/dist/recovery/restore-point-create.d.ts +3 -3
- package/dist/secrets-vault/repo.sql.d.ts +3 -3
- package/dist/secrets-vault/repo.sql.js +5 -4
- package/dist/settings/index.d.ts +3 -0
- package/dist/settings/index.js +2 -0
- package/dist/settings/repo.rows.d.ts +117 -0
- package/dist/settings/repo.rows.js +106 -0
- package/dist/settings/repo.sql.d.ts +99 -0
- package/dist/settings/repo.sql.js +219 -0
- package/dist/sqlite/checked-client.d.ts +1 -1
- package/dist/sqlite/checked-state.d.ts +3 -3
- package/dist/sqlite/db-ops.d.ts +1 -1
- package/dist/sqlite/db-ops.js +1 -1
- package/dist/sqlite/index.d.ts +1 -3
- package/dist/sqlite/index.js +2 -0
- package/dist/sqlite/inspect.d.ts +2 -2
- package/dist/sqlite/inspect.js +1 -1
- package/dist/sqlite/open.d.ts +1 -2
- package/dist/sqlite/stopped.d.ts +46 -0
- package/dist/sqlite/stopped.js +86 -0
- package/dist/sqlite/transaction.d.ts +2 -2
- package/dist/tools/database-catalog.d.ts +2 -2
- package/dist/tools/database-catalog.js +13 -3
- package/dist/tools/read-tools.js +70 -59
- package/dist/tools/restore-points.d.ts +1 -1
- package/dist/tools/transfer-tools.d.ts +0 -1
- package/dist/tools/transfer-tools.js +5 -4
- package/dist/transfer/copy-engine.js +10 -10
- package/dist/transfer/copy-order.d.ts +47 -0
- package/dist/transfer/copy-order.js +103 -0
- package/dist/transfer/index.d.ts +1 -0
- package/dist/transfer/index.js +1 -0
- package/dist/transfer/internal-ddl.d.ts +28 -6
- package/dist/transfer/internal-ddl.js +15 -15
- package/dist/transfer/postgres-ddl.js +6 -6
- package/dist/transfer/sqlite-source.d.ts +2 -3
- package/dist/transfer/sqlite-source.js +1 -1
- package/dist/verified-origin/index.d.ts +4 -0
- package/dist/verified-origin/index.js +3 -0
- package/dist/verified-origin/register.d.ts +43 -0
- package/dist/verified-origin/register.js +51 -0
- package/dist/verified-origin/repo.rows.d.ts +42 -0
- package/dist/verified-origin/repo.rows.js +47 -0
- package/dist/verified-origin/repo.sql.d.ts +67 -0
- package/dist/verified-origin/repo.sql.js +34 -0
- package/package.json +38 -11
- package/dist/sqlite/restore-types.d.ts +0 -46
- package/dist/sqlite/restore-types.js +0 -2
- package/dist/sqlite/sync-types.d.ts +0 -34
- package/dist/sqlite/sync-types.js +0 -2
- package/dist/sqlite/types.d.ts +0 -37
- package/dist/sqlite/types.js +0 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import { type
|
|
2
|
+
import { type KyselyKernel, type StorageOps } from "../index.js";
|
|
3
3
|
import type { PgliteClass } from "../../pglite/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* @file The storage ops for PGlite: an in-process kernel (`openPgliteKernel`), or a socket client
|
|
@@ -26,7 +26,9 @@ export interface PgliteRestore {
|
|
|
26
26
|
* @throws {Error} a kernel that is neither in-process PGlite nor a socket client given its owner.
|
|
27
27
|
* @complexity each op is one full pass over the data dir, O(size).
|
|
28
28
|
*/
|
|
29
|
-
export declare function pgliteOps<DB>(kernel
|
|
29
|
+
export declare function pgliteOps<DB>({ kernel, ...required }: {
|
|
30
|
+
kernel: KyselyKernel<DB>;
|
|
31
|
+
} & PgliteRestore & {
|
|
30
32
|
ledgerTable: string;
|
|
31
33
|
}, optional?: {
|
|
32
34
|
pgliteOwner?: PgliteExclusive;
|
|
@@ -35,5 +37,8 @@ export declare function pgliteOps<DB>(kernel: StorageKernel<DB>, required: Pglit
|
|
|
35
37
|
* `copyTo` for a PGlite data dir served by `owner` (in this process): the dump is taken inside the
|
|
36
38
|
* owner's exclusive window, then restored into `targetPath` (which must not exist).
|
|
37
39
|
*/
|
|
38
|
-
export declare function copyServedPgliteTo(owner
|
|
40
|
+
export declare function copyServedPgliteTo({ owner, targetPath, ...required }: {
|
|
41
|
+
owner: PgliteExclusive;
|
|
42
|
+
targetPath: string;
|
|
43
|
+
} & PgliteRestore, _optional?: Record<string, never>): Promise<void>;
|
|
39
44
|
//# sourceMappingURL=ops.d.ts.map
|
|
@@ -12,18 +12,18 @@ import { outsideTransactionOf, verifyLedgerReadBack, } from "../index.js";
|
|
|
12
12
|
* @throws {Error} a kernel that is neither in-process PGlite nor a socket client given its owner.
|
|
13
13
|
* @complexity each op is one full pass over the data dir, O(size).
|
|
14
14
|
*/
|
|
15
|
-
export function pgliteOps(kernel, required, optional = {}) {
|
|
15
|
+
export function pgliteOps({ kernel, ...required }, optional = {}) {
|
|
16
16
|
const owner = optional.pgliteOwner;
|
|
17
17
|
const ownedSocket = kernel.transport === "pglite-socket" && owner !== undefined;
|
|
18
18
|
if (kernel.transport !== "pglite" && !ownedSocket) {
|
|
19
19
|
throw new Error(`pgliteOps: a ${kernel.transport} kernel is not PGlite in this process (a socket client needs pgliteOwner)`);
|
|
20
20
|
}
|
|
21
|
-
const outsideTransaction = outsideTransactionOf(kernel);
|
|
21
|
+
const outsideTransaction = outsideTransactionOf({ kernel: kernel });
|
|
22
22
|
return {
|
|
23
23
|
async copyTo(targetPath) {
|
|
24
24
|
outsideTransaction("copyTo");
|
|
25
25
|
if (owner !== undefined) {
|
|
26
|
-
await copyServedPgliteTo(owner, targetPath, required);
|
|
26
|
+
await copyServedPgliteTo({ owner, targetPath, ...required });
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
await restoreDataDir(targetPath, required, async () => {
|
|
@@ -50,7 +50,7 @@ export function pgliteOps(kernel, required, optional = {}) {
|
|
|
50
50
|
await kernel.execute(sql `VACUUM`);
|
|
51
51
|
await kernel.execute(sql `CHECKPOINT`);
|
|
52
52
|
}
|
|
53
|
-
await verifyLedgerReadBack(kernel, required.ledgerTable);
|
|
53
|
+
await verifyLedgerReadBack({ kernel: kernel, ledgerTable: required.ledgerTable });
|
|
54
54
|
},
|
|
55
55
|
};
|
|
56
56
|
}
|
|
@@ -58,7 +58,7 @@ export function pgliteOps(kernel, required, optional = {}) {
|
|
|
58
58
|
* `copyTo` for a PGlite data dir served by `owner` (in this process): the dump is taken inside the
|
|
59
59
|
* owner's exclusive window, then restored into `targetPath` (which must not exist).
|
|
60
60
|
*/
|
|
61
|
-
export async function copyServedPgliteTo(owner, targetPath, required) {
|
|
61
|
+
export async function copyServedPgliteTo({ owner, targetPath, ...required }, _optional = {}) {
|
|
62
62
|
await restoreDataDir(targetPath, required, () => owner.runExclusive((db) => db.dumpDataDir("none")));
|
|
63
63
|
}
|
|
64
64
|
/** Restores `dump()` into a new PGlite data dir at `targetPath`; removes a partial dir on failure. */
|
package/dist/kernel/port.d.ts
CHANGED
|
@@ -1,88 +1,21 @@
|
|
|
1
1
|
import type { Kysely, RawBuilder } from "kysely";
|
|
2
|
+
import type { StorageKernel } from "@jini-ai/core/contracts/storage";
|
|
2
3
|
export type { RawBuilder } from "kysely";
|
|
3
4
|
/**
|
|
4
|
-
* @file
|
|
5
|
+
* @file `@jini-ai/db`'s kernel: the neutral `@jini-ai/core/contracts/storage` {@link StorageKernel} bound to a Kysely
|
|
6
|
+
* handle, plus raw statements. Hosts that chose Kysely type their kernels with this; domain packages see only the core
|
|
7
|
+
* contract (`StorageKernel<Kysely<DB>, DB>` in their SQL adapter subpaths) and never import this package.
|
|
5
8
|
* Package: `@jini-ai/db/kernel` (no driver is imported here; each driver lives in its own subpath).
|
|
6
9
|
*
|
|
7
|
-
*
|
|
8
|
-
* `BEGIN`, never calls a driver API. It asks the kernel:
|
|
9
|
-
*
|
|
10
|
-
* - {@link StorageKernel.run} — run statements on the right executor: the open transaction when the
|
|
11
|
-
* caller is inside {@link StorageKernel.transaction}, else the base handle.
|
|
12
|
-
* - {@link StorageKernel.transaction} — one unit of work. A NESTED call joins the outer one (no
|
|
13
|
-
* savepoint), so a service composing two repos that each wrap themselves still commits or rolls
|
|
14
|
-
* back as one. Calling it from inside a `run()` body throws: that body holds the handle a
|
|
15
|
-
* transaction would wait for.
|
|
16
|
-
* - {@link StorageKernel.lockKey} — the explicit concurrency strategy for "nothing else may
|
|
17
|
-
* interleave here" (read-then-write sequences such as a ledger append). A transaction alone does
|
|
18
|
-
* not give that on Postgres (READ COMMITTED); this does, on every dialect.
|
|
19
|
-
* - {@link StorageKernel.query} — a portable Kysely `sql` statement returning rows. For dialect
|
|
10
|
+
* - {@link KyselyKernel.query} — a portable Kysely `sql` statement returning rows. For dialect
|
|
20
11
|
* helpers, migrations and introspection (`dialect.ts`), not for repos.
|
|
21
|
-
*
|
|
22
|
-
* Three separate things describe a kernel (never inferred from each other, never cached per process):
|
|
23
|
-
* the SQL {@link StorageDialect}, the connection {@link StorageTransport}, and its
|
|
24
|
-
* {@link StorageCapabilities}. Asking for a capability the kernel lacks throws
|
|
25
|
-
* {@link UnsupportedCapabilityError}; nothing silently downgrades (e.g. a transaction never becomes
|
|
26
|
-
* "run the statements one by one").
|
|
27
|
-
*
|
|
28
|
-
* Drivers live in the `sqlite`, `pglite` and `postgres` subpaths. None of them imports a driver
|
|
29
|
-
* package: the consumer passes its own client, pool or class in.
|
|
30
12
|
*/
|
|
31
|
-
/**
|
|
32
|
-
export type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/** What this kernel instance can do. Checked per call; a missing one is an explicit error. */
|
|
36
|
-
export interface StorageCapabilities {
|
|
37
|
-
/** `transaction(fn)` with awaits (reads, logic) between statements. D1 and HTTP drivers: no. */
|
|
38
|
-
readonly interactiveTransactions: boolean;
|
|
39
|
-
/** Several statements applied all-or-nothing without an interactive transaction. */
|
|
40
|
-
readonly atomicBatch: boolean;
|
|
41
|
-
/** DDL inside a transaction rolls back with it. */
|
|
42
|
-
readonly transactionalDdl: boolean;
|
|
43
|
-
/** A consistent copy of the whole database can be taken through the driver (restore points). */
|
|
44
|
-
readonly backup: boolean;
|
|
45
|
-
}
|
|
46
|
-
export type StorageCapability = keyof StorageCapabilities;
|
|
47
|
-
export declare class UnsupportedCapabilityError extends Error {
|
|
48
|
-
readonly capability: StorageCapability;
|
|
49
|
-
readonly transport: StorageTransport;
|
|
50
|
-
constructor(capability: StorageCapability, transport: StorageTransport);
|
|
51
|
-
}
|
|
52
|
-
declare const storageKernelSchema: unique symbol;
|
|
53
|
-
export interface StorageKernel<DB> {
|
|
54
|
-
/** Type-only schema witness: retain DB independently of Kysely's structural method
|
|
55
|
-
* signatures so stores reject kernels missing required tables.
|
|
56
|
-
* Optional so existing host implementations need no runtime property. */
|
|
57
|
-
readonly [storageKernelSchema]?: DB;
|
|
58
|
-
readonly dialect: StorageDialect;
|
|
59
|
-
readonly transport: StorageTransport;
|
|
60
|
-
readonly capabilities: StorageCapabilities;
|
|
61
|
-
/** Resolves once the driver is open and its schema is in place. Every call below awaits it. */
|
|
62
|
-
readonly ready: Promise<void>;
|
|
63
|
-
run<T>(fn: (db: Kysely<DB>) => T | Promise<T>): Promise<T>;
|
|
64
|
-
/** Throws {@link UnsupportedCapabilityError} without `interactiveTransactions`. */
|
|
65
|
-
transaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
66
|
-
/**
|
|
67
|
-
* Inside a transaction: blocks every other transaction that locks the same `key` until this one
|
|
68
|
-
* ends. Postgres: a transaction-scoped advisory lock. SQLite: nothing to do — the kernel's
|
|
69
|
-
* transactions take the database write lock at `BEGIN IMMEDIATE`, which already serializes them.
|
|
70
|
-
* Throws outside a transaction (a lock with no transaction to end it would never be released).
|
|
71
|
-
*/
|
|
72
|
-
lockKey(key: string): Promise<void>;
|
|
13
|
+
/** The connections this package's drivers open (core's `StorageTransport` is open-ended). */
|
|
14
|
+
export type DbTransport = "better-sqlite3" | "pglite" | "node-postgres" | "pglite-socket";
|
|
15
|
+
export interface KyselyKernel<DB> extends StorageKernel<Kysely<DB>, DB> {
|
|
16
|
+
readonly transport: DbTransport;
|
|
73
17
|
query<Row>(statement: RawBuilder<Row>): Promise<Row[]>;
|
|
74
18
|
/** {@link query} for a statement that returns no rows (DDL, a write without `RETURNING`). */
|
|
75
19
|
execute(statement: RawBuilder<unknown>): Promise<void>;
|
|
76
|
-
/** True inside this kernel's own transaction (the caller's async context). */
|
|
77
|
-
inTransaction(): boolean;
|
|
78
|
-
/** Throws {@link UnsupportedCapabilityError} when this kernel lacks `capability`. */
|
|
79
|
-
require(capability: StorageCapability): void;
|
|
80
|
-
/**
|
|
81
|
-
* A consistent copy of the whole database written to `destPath` (SQLite: the online backup API,
|
|
82
|
-
* a normal SQLite file; PGlite: a data-dir tarball). Throws {@link UnsupportedCapabilityError}
|
|
83
|
-
* without `backup`. Call it outside a transaction.
|
|
84
|
-
*/
|
|
85
|
-
backupTo(destPath: string): Promise<void>;
|
|
86
|
-
close(): Promise<void>;
|
|
87
20
|
}
|
|
88
21
|
//# sourceMappingURL=port.d.ts.map
|
package/dist/kernel/port.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
capability;
|
|
3
|
-
transport;
|
|
4
|
-
constructor(capability, transport) {
|
|
5
|
-
super(`the ${transport} storage driver does not support ${capability}`);
|
|
6
|
-
this.capability = capability;
|
|
7
|
-
this.transport = transport;
|
|
8
|
-
this.name = "UnsupportedCapabilityError";
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
export {};
|
|
11
2
|
//# sourceMappingURL=port.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Logger } from "@jini-ai/core/primitives";
|
|
2
|
+
import { type KyselyKernel } from "../index.js";
|
|
2
3
|
import { type PgModule } from "../../core/pg-types.js";
|
|
3
4
|
/**
|
|
4
5
|
* @file The node-postgres driver: a connection POOL to any Postgres server (local, Supabase, Neon).
|
|
@@ -19,5 +20,6 @@ export declare function openPostgresKernel<DB>(required: {
|
|
|
19
20
|
connectionString: string;
|
|
20
21
|
}, optional?: {
|
|
21
22
|
max?: number;
|
|
22
|
-
|
|
23
|
+
report?: Pick<Logger, "warn">;
|
|
24
|
+
}): KyselyKernel<DB>;
|
|
23
25
|
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { redactSecrets } from '@jini-ai/core';
|
|
1
|
+
import { createConsoleLogger } from "@jini-ai/core/primitives";
|
|
3
2
|
import { Kysely, PostgresDialect } from "kysely";
|
|
4
3
|
import { PG_PARSERS } from "../../core/index.js";
|
|
5
4
|
import { buildKernel, postgresLockKey } from "../index.js";
|
|
@@ -19,15 +18,16 @@ import { pgTypesFor } from "../../core/pg-types.js";
|
|
|
19
18
|
* @param optional.max pool size, default 10.
|
|
20
19
|
*/
|
|
21
20
|
export function openPostgresKernel(required, optional = {}) {
|
|
21
|
+
const logger = optional.report ?? createConsoleLogger({ prefix: "[postgres]" });
|
|
22
22
|
const pool = new required.pg.Pool({
|
|
23
23
|
connectionString: required.connectionString,
|
|
24
24
|
max: optional.max ?? 10,
|
|
25
|
-
types: pgTypesFor(required.pg, PG_PARSERS),
|
|
25
|
+
types: pgTypesFor({ pg: required.pg, parsers: PG_PARSERS }),
|
|
26
26
|
});
|
|
27
27
|
// An idle connection dropped by the server (restart, failover, pg_terminate_backend, a pooler's
|
|
28
28
|
// idle cut) is evicted by the pool and reopened on next use; without a listener it would crash the
|
|
29
29
|
// process.
|
|
30
|
-
pool.on("error", (err) =>
|
|
30
|
+
pool.on("error", (err) => logger.warn({ message: "Idle pool connection dropped." }, { error: err }));
|
|
31
31
|
// Pool error listeners cover idle clients only. Session-owned workers hold a client for
|
|
32
32
|
// longer, so absorb its error event while the next query rejects and stops that owner.
|
|
33
33
|
const connected = new WeakSet();
|
|
@@ -36,22 +36,22 @@ export function openPostgresKernel(required, optional = {}) {
|
|
|
36
36
|
const client = await connect();
|
|
37
37
|
if (!connected.has(client)) {
|
|
38
38
|
connected.add(client);
|
|
39
|
-
client.on?.("error", () =>
|
|
39
|
+
client.on?.("error", (error) => logger.warn({ message: "Active pool connection dropped; its operation will stop." }, { error }));
|
|
40
40
|
}
|
|
41
41
|
return client;
|
|
42
42
|
};
|
|
43
43
|
const base = new Kysely({ dialect: new PostgresDialect({ pool }) });
|
|
44
|
-
return buildKernel({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
return buildKernel({ driver: {
|
|
45
|
+
dialect: "postgres",
|
|
46
|
+
transport: "node-postgres",
|
|
47
|
+
capabilities: { interactiveTransactions: true, atomicBatch: true, transactionalDdl: true, backup: false },
|
|
48
|
+
ready: Promise.resolve(),
|
|
49
|
+
base,
|
|
50
|
+
oneConnection: false,
|
|
51
|
+
poolMax: optional.max ?? 10,
|
|
52
|
+
begin: (body) => base.transaction().execute((tx) => body(tx)),
|
|
53
|
+
lockKey: postgresLockKey,
|
|
54
|
+
close: () => base.destroy(),
|
|
55
|
+
} });
|
|
56
56
|
}
|
|
57
57
|
//# sourceMappingURL=driver.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type KyselyKernel, type StorageOps } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* The ops for a node-postgres kernel. Must be used outside a transaction.
|
|
4
4
|
*
|
|
@@ -6,7 +6,9 @@ import { type StorageKernel, type StorageOps } from "../index.js";
|
|
|
6
6
|
* @throws {Error} a kernel of another transport.
|
|
7
7
|
* @complexity `compactAndVerify` is one full `VACUUM` pass, O(size).
|
|
8
8
|
*/
|
|
9
|
-
export declare function postgresOps<DB>(kernel
|
|
9
|
+
export declare function postgresOps<DB>({ kernel, ...required }: {
|
|
10
|
+
kernel: KyselyKernel<DB>;
|
|
11
|
+
} & {
|
|
10
12
|
ledgerTable: string;
|
|
11
|
-
}): StorageOps;
|
|
13
|
+
}, _optional?: Record<string, never>): StorageOps;
|
|
12
14
|
//# sourceMappingURL=ops.d.ts.map
|
|
@@ -18,11 +18,11 @@ const SOCKET_COPY_REASON = "a PGlite socket client copies through its owner's ex
|
|
|
18
18
|
* @throws {Error} a kernel of another transport.
|
|
19
19
|
* @complexity `compactAndVerify` is one full `VACUUM` pass, O(size).
|
|
20
20
|
*/
|
|
21
|
-
export function postgresOps(kernel, required) {
|
|
21
|
+
export function postgresOps({ kernel, ...required }, _optional = {}) {
|
|
22
22
|
if (kernel.transport !== "node-postgres" && kernel.transport !== "pglite-socket") {
|
|
23
23
|
throw new Error(`postgresOps: a ${kernel.transport} kernel is not a node-postgres connection`);
|
|
24
24
|
}
|
|
25
|
-
const outsideTransaction = outsideTransactionOf(kernel);
|
|
25
|
+
const outsideTransaction = outsideTransactionOf({ kernel: kernel });
|
|
26
26
|
return {
|
|
27
27
|
async copyTo() {
|
|
28
28
|
outsideTransaction("copyTo");
|
|
@@ -39,7 +39,7 @@ export function postgresOps(kernel, required) {
|
|
|
39
39
|
// A hosted server rarely lets an app's role CHECKPOINT; a commit is durable anyway.
|
|
40
40
|
await kernel.execute(sql `VACUUM (ANALYZE)`);
|
|
41
41
|
}
|
|
42
|
-
await verifyLedgerReadBack(kernel, required.ledgerTable);
|
|
42
|
+
await verifyLedgerReadBack({ kernel: kernel, ledgerTable: required.ledgerTable });
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type KyselyKernel } from "../index.js";
|
|
2
2
|
import { type PgModule } from "../../core/pg-types.js";
|
|
3
3
|
/**
|
|
4
4
|
* @file A storage kernel that reaches a PGlite data dir through its owner's Unix socket
|
|
@@ -19,5 +19,5 @@ import { type PgModule } from "../../core/pg-types.js";
|
|
|
19
19
|
export declare function openPgliteSocketKernel<DB>(required: {
|
|
20
20
|
pg: PgModule;
|
|
21
21
|
socketPath: string;
|
|
22
|
-
}):
|
|
22
|
+
}, _optional?: Record<string, never>): KyselyKernel<DB>;
|
|
23
23
|
//# sourceMappingURL=pglite-socket.d.ts.map
|
|
@@ -19,7 +19,7 @@ import { pgTypesFor } from "../../core/pg-types.js";
|
|
|
19
19
|
* @param required.pg the consumer's node-postgres module (`import pg from "pg"`).
|
|
20
20
|
* @throws {Error} a path that does not end in the Postgres socket file name.
|
|
21
21
|
*/
|
|
22
|
-
export function openPgliteSocketKernel(required) {
|
|
22
|
+
export function openPgliteSocketKernel(required, _optional = {}) {
|
|
23
23
|
if (!required.socketPath.endsWith(`/${PGLITE_SOCKET_FILE}`)) {
|
|
24
24
|
throw new Error(`a PGlite socket path ends in /${PGLITE_SOCKET_FILE}: ${required.socketPath}`);
|
|
25
25
|
}
|
|
@@ -31,22 +31,22 @@ export function openPgliteSocketKernel(required) {
|
|
|
31
31
|
max: 1,
|
|
32
32
|
// Keep the one connection: every new one's startup waits behind any open transaction.
|
|
33
33
|
idleTimeoutMillis: 0,
|
|
34
|
-
types: pgTypesFor(required.pg, PG_PARSERS),
|
|
34
|
+
types: pgTypesFor({ pg: required.pg, parsers: PG_PARSERS }),
|
|
35
35
|
});
|
|
36
36
|
// An idle connection dropped by the owner (restart, idle-in-transaction timeout) is evicted by the
|
|
37
37
|
// pool and reopened on next use; without a listener it would crash the process.
|
|
38
38
|
pool.on("error", () => { });
|
|
39
39
|
const base = new Kysely({ dialect: new PostgresDialect({ pool }) });
|
|
40
|
-
return buildKernel({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
return buildKernel({ driver: {
|
|
41
|
+
dialect: "postgres",
|
|
42
|
+
transport: "pglite-socket",
|
|
43
|
+
capabilities: { interactiveTransactions: true, atomicBatch: true, transactionalDdl: true, backup: false },
|
|
44
|
+
ready: Promise.resolve(),
|
|
45
|
+
base,
|
|
46
|
+
oneConnection: true,
|
|
47
|
+
begin: (body) => base.transaction().execute((tx) => body(tx)),
|
|
48
|
+
lockKey: postgresLockKey,
|
|
49
|
+
close: () => base.destroy(),
|
|
50
|
+
} });
|
|
51
51
|
}
|
|
52
52
|
//# sourceMappingURL=pglite-socket.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { KyselyKernel } from "./port.js";
|
|
2
2
|
/**
|
|
3
3
|
* @file A kernel whose query-builder statements address one Postgres schema: every `run()` body gets
|
|
4
4
|
* `db.withSchema(schema)` (Kysely's own plugin prefixes each table it names). Used when one
|
|
@@ -10,5 +10,8 @@ import type { StorageKernel } from "./port.js";
|
|
|
10
10
|
*
|
|
11
11
|
* Transactions, locks and `close` are the underlying kernel's: one database, one connection pool.
|
|
12
12
|
*/
|
|
13
|
-
export declare function scopeToSchema<DB>(kernel
|
|
13
|
+
export declare function scopeToSchema<DB>({ kernel, schema }: {
|
|
14
|
+
kernel: KyselyKernel<DB>;
|
|
15
|
+
schema: string;
|
|
16
|
+
}, _optional?: Record<string, never>): KyselyKernel<DB>;
|
|
14
17
|
//# sourceMappingURL=schema-scope.d.ts.map
|
|
@@ -11,7 +11,7 @@ import { inheritOwnedTransaction } from "./owned-transaction.js";
|
|
|
11
11
|
*
|
|
12
12
|
* Transactions, locks and `close` are the underlying kernel's: one database, one connection pool.
|
|
13
13
|
*/
|
|
14
|
-
export function scopeToSchema(kernel, schema) {
|
|
14
|
+
export function scopeToSchema({ kernel, schema }, _optional = {}) {
|
|
15
15
|
if (kernel.dialect !== "postgres")
|
|
16
16
|
throw new Error(`schema '${schema}' needs a Postgres kernel, not ${kernel.dialect}`);
|
|
17
17
|
const scoped = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { KyselyKernel } from "./port.js";
|
|
2
2
|
/**
|
|
3
3
|
* @file The physical schema of a database as comparable text, per table: columns (type, NOT NULL,
|
|
4
4
|
* default, key position), indexes (uniqueness, columns, partial predicate), foreign keys and — on
|
|
@@ -18,9 +18,13 @@ export interface SchemaShape {
|
|
|
18
18
|
others: string[];
|
|
19
19
|
}
|
|
20
20
|
/** Every user table's shape (internal and `sqlite_`/`pg_` tables excluded), keyed by table name. */
|
|
21
|
-
export declare function readSchemaShape(kernel:
|
|
21
|
+
export declare function readSchemaShape({ kernel }: {
|
|
22
|
+
kernel: KyselyKernel<unknown>;
|
|
23
|
+
}, optional?: {
|
|
22
24
|
exclude?: readonly string[];
|
|
23
25
|
}): Promise<SchemaShape>;
|
|
24
26
|
/** The main database file of a SQLite kernel; null for an in-memory database or a Postgres kernel. */
|
|
25
|
-
export declare function databaseFile<DB>(kernel
|
|
27
|
+
export declare function databaseFile<DB>({ kernel }: {
|
|
28
|
+
kernel: KyselyKernel<DB>;
|
|
29
|
+
}, _optional?: Record<string, never>): Promise<string | null>;
|
|
26
30
|
//# sourceMappingURL=schema-shape.d.ts.map
|
|
@@ -5,7 +5,7 @@ function defaultClause(value) {
|
|
|
5
5
|
}
|
|
6
6
|
const squash = (text) => text.replace(/\s+/g, " ").trim();
|
|
7
7
|
/** Every user table's shape (internal and `sqlite_`/`pg_` tables excluded), keyed by table name. */
|
|
8
|
-
export async function readSchemaShape(kernel, optional = {}) {
|
|
8
|
+
export async function readSchemaShape({ kernel }, optional = {}) {
|
|
9
9
|
const exclude = new Set(optional.exclude ?? []);
|
|
10
10
|
const shape = kernel.dialect === "sqlite" ? await sqliteShape(kernel) : await postgresShape(kernel);
|
|
11
11
|
for (const name of exclude)
|
|
@@ -85,7 +85,7 @@ async function postgresShape(kernel) {
|
|
|
85
85
|
return { tables, others: views.map((v) => `view ${v.name}: ${squash(v.definition)}`) };
|
|
86
86
|
}
|
|
87
87
|
/** The main database file of a SQLite kernel; null for an in-memory database or a Postgres kernel. */
|
|
88
|
-
export async function databaseFile(kernel) {
|
|
88
|
+
export async function databaseFile({ kernel }, _optional = {}) {
|
|
89
89
|
if (kernel.dialect !== "sqlite")
|
|
90
90
|
return null;
|
|
91
91
|
const rows = await kernel.query(sql `SELECT file FROM pragma_database_list WHERE name = 'main'`);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { type Kysely } from 'kysely';
|
|
2
|
-
import type {
|
|
2
|
+
import type { KyselyKernel } from './port.js';
|
|
3
3
|
/** Private driver registration, kept separate from run() so the callback owns no transaction scope. */
|
|
4
4
|
export declare function registerKernelSessionDatabase({ kernel, database, poolMax }: {
|
|
5
|
-
kernel:
|
|
5
|
+
kernel: KyselyKernel<unknown>;
|
|
6
6
|
database: Kysely<unknown>;
|
|
7
7
|
poolMax?: number;
|
|
8
8
|
}, _optional?: Record<string, never>): void;
|
|
9
9
|
/** A schema wrapper uses the same pool and therefore the same database ownership scope. */
|
|
10
10
|
export declare function inheritKernelSessionDatabase({ from, to }: {
|
|
11
|
-
from:
|
|
12
|
-
to:
|
|
11
|
+
from: KyselyKernel<unknown>;
|
|
12
|
+
to: KyselyKernel<unknown>;
|
|
13
13
|
}, _optional?: Record<string, never>): void;
|
|
14
14
|
/** Read the registered pool capacity without reserving a connection; schema wrappers share it. O(1). */
|
|
15
15
|
export declare function kernelSessionPoolMax({ kernel }: {
|
|
16
|
-
kernel:
|
|
16
|
+
kernel: KyselyKernel<unknown>;
|
|
17
17
|
}, _optional?: Record<string, never>): number | undefined;
|
|
18
18
|
/**
|
|
19
19
|
* Run one background owner under a dedicated PostgreSQL session advisory lock.
|
|
@@ -26,7 +26,7 @@ export declare function kernelSessionPoolMax({ kernel }: {
|
|
|
26
26
|
* @complexity Two O(1) lock queries and one reserved pool connection for the callback lifetime.
|
|
27
27
|
*/
|
|
28
28
|
export declare function withKernelSessionLock<T>({ kernel, key, run }: {
|
|
29
|
-
kernel:
|
|
29
|
+
kernel: KyselyKernel<unknown>;
|
|
30
30
|
key: string;
|
|
31
31
|
run: (lease: {
|
|
32
32
|
assertOwned(): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { SqliteClient, SqliteOpener } from "@jini-ai/core/contracts/storage";
|
|
2
|
+
import { type KyselyKernel } from "../index.js";
|
|
3
3
|
/**
|
|
4
4
|
* @file The better-sqlite3 driver: a kernel over an ALREADY OPEN SQLite connection the consumer
|
|
5
5
|
* opened (and migrated) itself. Wrapping instead of opening keeps an existing database exactly as it
|
|
@@ -24,14 +24,18 @@ import type { SqliteClient, SqliteOpener } from "../../sqlite/types.js";
|
|
|
24
24
|
*
|
|
25
25
|
* The connection's opener closes it; `close()` here does nothing.
|
|
26
26
|
*/
|
|
27
|
-
export type SqliteKernel<DB> =
|
|
27
|
+
export type SqliteKernel<DB> = KyselyKernel<DB>;
|
|
28
28
|
/** An ORM handle that carries its better-sqlite3 client as `$client`, or the client itself. */
|
|
29
29
|
export type SqliteConnectionSource = SqliteClient | {
|
|
30
30
|
readonly $client: SqliteClient;
|
|
31
31
|
};
|
|
32
32
|
/** The better-sqlite3 client under `source` (a handle's `$client`, or the client itself). */
|
|
33
|
-
export declare function sqliteClientOf(source
|
|
34
|
-
|
|
33
|
+
export declare function sqliteClientOf({ source }: {
|
|
34
|
+
source: SqliteConnectionSource;
|
|
35
|
+
}, _optional?: Record<string, never>): SqliteClient;
|
|
36
|
+
export declare function sqliteKernel<DB>({ source }: {
|
|
37
|
+
source: SqliteConnectionSource;
|
|
38
|
+
}, _optional?: Record<string, never>): SqliteKernel<DB>;
|
|
35
39
|
/**
|
|
36
40
|
* A kernel over a new private in-memory SQLite database (foreign keys on). `close()` closes the
|
|
37
41
|
* connection. For scratch work, e.g. building a reference schema.
|
|
@@ -40,7 +44,7 @@ export declare function sqliteKernel<DB>(source: SqliteConnectionSource): Sqlite
|
|
|
40
44
|
*/
|
|
41
45
|
export declare function openMemorySqliteKernel<DB>(required: {
|
|
42
46
|
open: SqliteOpener;
|
|
43
|
-
}): SqliteKernel<DB>;
|
|
47
|
+
}, _optional?: Record<string, never>): SqliteKernel<DB>;
|
|
44
48
|
/**
|
|
45
49
|
* A kernel over its OWN connection to the SQLite file at `filePath`, opened as-is: no migration, no
|
|
46
50
|
* WAL switch, foreign keys on, a 5 s busy timeout. `close()` closes the connection.
|
|
@@ -65,7 +69,11 @@ export declare function openSqliteFileKernel<DB>(required: {
|
|
|
65
69
|
* and forgets its kernel. For callers that opened a database themselves and must
|
|
66
70
|
* release it; the kernel's own `close()` never closes a connection it did not open.
|
|
67
71
|
*/
|
|
68
|
-
export declare function closeSqliteConnection(source
|
|
72
|
+
export declare function closeSqliteConnection({ source }: {
|
|
73
|
+
source: SqliteConnectionSource;
|
|
74
|
+
}, _optional?: Record<string, never>): void;
|
|
69
75
|
/** The connection under a kernel this driver built, for the SQLite `StorageOps` (`./ops.ts`). */
|
|
70
|
-
export declare function sqliteConnectionOf<DB>(kernel
|
|
76
|
+
export declare function sqliteConnectionOf<DB>({ kernel }: {
|
|
77
|
+
kernel: KyselyKernel<DB>;
|
|
78
|
+
}, _optional?: Record<string, never>): SqliteClient | undefined;
|
|
71
79
|
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -19,7 +19,7 @@ function turnLockFor(client) {
|
|
|
19
19
|
return lock;
|
|
20
20
|
}
|
|
21
21
|
/** The better-sqlite3 client under `source` (a handle's `$client`, or the client itself). */
|
|
22
|
-
export function sqliteClientOf(source) {
|
|
22
|
+
export function sqliteClientOf({ source }, _optional = {}) {
|
|
23
23
|
return "$client" in source ? source.$client : source;
|
|
24
24
|
}
|
|
25
25
|
/** Rolls back a failed transaction; a checked kernel reports a failing rollback with the original error. */
|
|
@@ -54,8 +54,8 @@ function bindingShim(client) {
|
|
|
54
54
|
},
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
export function sqliteKernel(source) {
|
|
58
|
-
const client = sqliteClientOf(source);
|
|
57
|
+
export function sqliteKernel({ source }, _optional = {}) {
|
|
58
|
+
const client = sqliteClientOf({ source });
|
|
59
59
|
const checked = checkedClients.has(client);
|
|
60
60
|
if (checkedStates.has(client) && !checked)
|
|
61
61
|
throw new Error("cannot mix raw and checked SQLite kernel ownership");
|
|
@@ -65,35 +65,35 @@ export function sqliteKernel(source) {
|
|
|
65
65
|
if (known !== undefined)
|
|
66
66
|
return known;
|
|
67
67
|
const base = new Kysely({ dialect: new SqliteDialect({ database: bindingShim(client) }) });
|
|
68
|
-
const kernel = buildKernel({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
68
|
+
const kernel = buildKernel({ driver: {
|
|
69
|
+
dialect: "sqlite",
|
|
70
|
+
transport: "better-sqlite3",
|
|
71
|
+
capabilities: { interactiveTransactions: true, atomicBatch: true, transactionalDdl: true, backup: true },
|
|
72
|
+
ready: Promise.resolve(),
|
|
73
|
+
base,
|
|
74
|
+
oneConnection: true,
|
|
75
|
+
turnLock: turnLockFor(client),
|
|
76
|
+
async begin(body) {
|
|
77
|
+
client.exec("BEGIN IMMEDIATE");
|
|
78
|
+
try {
|
|
79
|
+
const result = await body(base);
|
|
80
|
+
client.exec("COMMIT");
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
rollbackAfterFailure({ client, error, checked });
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
// BEGIN IMMEDIATE already holds the database write lock for the whole transaction.
|
|
89
|
+
lockKey: async () => { },
|
|
90
|
+
foreignTransactionOpen: () => client.inTransaction,
|
|
91
|
+
backup: async (destPath) => {
|
|
92
|
+
await assertDatabaseCopySpace({ sourcePath: client.memory ? ':memory:' : client.name, destinationPath: destPath });
|
|
93
|
+
await client.backup(destPath);
|
|
94
|
+
},
|
|
95
|
+
close: async () => { },
|
|
96
|
+
} });
|
|
97
97
|
kernels.set(client, kernel);
|
|
98
98
|
connectionsByKernel.set(kernel, client);
|
|
99
99
|
return kernel;
|
|
@@ -104,7 +104,7 @@ export function sqliteKernel(source) {
|
|
|
104
104
|
*
|
|
105
105
|
* @param required.open the consumer's better-sqlite3 opener, e.g. `(p, o) => new Database(p, o)`.
|
|
106
106
|
*/
|
|
107
|
-
export function openMemorySqliteKernel(required) {
|
|
107
|
+
export function openMemorySqliteKernel(required, _optional = {}) {
|
|
108
108
|
return openSqliteFileKernel({ filePath: ":memory:", open: required.open });
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
@@ -128,10 +128,10 @@ export function openSqliteFileKernel(required, optional = {}) {
|
|
|
128
128
|
client.pragma("busy_timeout = 5000");
|
|
129
129
|
if (!readOnly)
|
|
130
130
|
client.pragma("foreign_keys = ON");
|
|
131
|
-
const kernel = sqliteKernel(client);
|
|
131
|
+
const kernel = sqliteKernel({ source: client });
|
|
132
132
|
const owned = {
|
|
133
133
|
...kernel,
|
|
134
|
-
close: async () => closeSqliteConnection(client),
|
|
134
|
+
close: async () => closeSqliteConnection({ source: client }),
|
|
135
135
|
};
|
|
136
136
|
connectionsByKernel.set(owned, client);
|
|
137
137
|
inheritOwnedTransaction({ from: kernel, to: owned });
|
|
@@ -142,13 +142,13 @@ export function openSqliteFileKernel(required, optional = {}) {
|
|
|
142
142
|
* and forgets its kernel. For callers that opened a database themselves and must
|
|
143
143
|
* release it; the kernel's own `close()` never closes a connection it did not open.
|
|
144
144
|
*/
|
|
145
|
-
export function closeSqliteConnection(source) {
|
|
146
|
-
const client = sqliteClientOf(source);
|
|
145
|
+
export function closeSqliteConnection({ source }, _optional = {}) {
|
|
146
|
+
const client = sqliteClientOf({ source });
|
|
147
147
|
kernels.delete(client);
|
|
148
148
|
client.close();
|
|
149
149
|
}
|
|
150
150
|
/** The connection under a kernel this driver built, for the SQLite `StorageOps` (`./ops.ts`). */
|
|
151
|
-
export function sqliteConnectionOf(kernel) {
|
|
151
|
+
export function sqliteConnectionOf({ kernel }, _optional = {}) {
|
|
152
152
|
return connectionsByKernel.get(kernel);
|
|
153
153
|
}
|
|
154
154
|
//# sourceMappingURL=driver.js.map
|