@xnetjs/sqlite 0.0.3 → 0.1.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/dist/{adapter-t2aqQ__n.d.ts → adapter-imtxkmXZ.d.ts} +22 -1
- package/dist/adapters/electron.d.ts +66 -6
- package/dist/adapters/electron.js +629 -47
- package/dist/adapters/expo.d.ts +6 -2
- package/dist/adapters/expo.js +8 -1
- package/dist/adapters/memory.d.ts +6 -2
- package/dist/adapters/memory.js +8 -1
- package/dist/adapters/reader-thread.d.ts +78 -0
- package/dist/adapters/reader-thread.js +57 -0
- package/dist/adapters/web-proxy.d.ts +54 -2
- package/dist/adapters/web-proxy.js +458 -55
- package/dist/adapters/web-router-worker.d.ts +76 -0
- package/dist/adapters/web-router-worker.js +91 -0
- package/dist/adapters/web-worker.d.ts +45 -1
- package/dist/adapters/web-worker.js +232 -17
- package/dist/adapters/web.d.ts +82 -3
- package/dist/adapters/web.js +7 -4
- package/dist/browser-support.d.ts +10 -1
- package/dist/browser-support.js +5 -1
- package/dist/chunk-5HC5V73T.js +191 -0
- package/dist/{chunk-DCY4LAUD.js → chunk-BBZDKLA3.js} +246 -13
- package/dist/chunk-CGI2YBZY.js +16 -0
- package/dist/{chunk-2OK46ZBU.js → chunk-S6MT6KCI.js} +22 -1
- package/dist/chunk-SV475UL5.js +44 -0
- package/dist/{chunk-NVD7G7DZ.js → chunk-W3L4FXU5.js} +11 -2
- package/dist/index.d.ts +93 -8
- package/dist/index.js +92 -10
- package/dist/schema-C4gufY3B.d.ts +35 -0
- package/dist/types-BTabr_VP.d.ts +225 -0
- package/dist/worker-scheduler-D04DqMmR.d.ts +56 -0
- package/package.json +5 -1
- package/dist/schema-BEgIA-rZ.d.ts +0 -35
- package/dist/types-DMrj3K4o.d.ts +0 -132
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as SQLiteConfig, a as SQLRow, S as SQLValue, R as RunResult,
|
|
1
|
+
import { b as SQLiteConfig, a as SQLRow, S as SQLValue, R as RunResult, c as SQLBatchRead, l as SQLiteNodeBatchApplyInput, m as SQLiteNodeBatchApplyResult, e as SQLiteOperationStats } from './types-BTabr_VP.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @xnetjs/sqlite - SQLite adapter interface definitions
|
|
@@ -67,6 +67,14 @@ interface SQLiteAdapter {
|
|
|
67
67
|
* @param sql - SQL statements (may be multiple, separated by semicolons)
|
|
68
68
|
*/
|
|
69
69
|
exec(sql: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Execute several reads in one call, returning one row array per read
|
|
72
|
+
* (positionally). For worker/port-backed adapters this crosses the RPC
|
|
73
|
+
* boundary ONCE for the whole batch instead of once per query — the
|
|
74
|
+
* amortization matters for multi-query screens and chunked hydrates
|
|
75
|
+
* (exploration 0263). In-process adapters may simply loop.
|
|
76
|
+
*/
|
|
77
|
+
queryBatch?(reads: SQLBatchRead[]): Promise<SQLRow[][]>;
|
|
70
78
|
/**
|
|
71
79
|
* Execute a function within a transaction.
|
|
72
80
|
* Automatically commits on success, rolls back on error.
|
|
@@ -147,6 +155,19 @@ interface SQLiteAdapter {
|
|
|
147
155
|
* Vacuum the database to reclaim space.
|
|
148
156
|
*/
|
|
149
157
|
vacuum(): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Return freelist pages to the filesystem under `auto_vacuum=INCREMENTAL`,
|
|
160
|
+
* optionally capped at `maxPages`. Returns the number of pages freed.
|
|
161
|
+
*
|
|
162
|
+
* This exists because `exec('PRAGMA incremental_vacuum')` is a silent
|
|
163
|
+
* near-no-op on the WASM build: SQLite frees ONE page per `sqlite3_step` of
|
|
164
|
+
* that pragma, and the oo1 `exec` path steps a statement only once when no
|
|
165
|
+
* rows are collected — so the freelist shrank by a single page per call.
|
|
166
|
+
* Implementations must step the pragma to completion. Optional: adapters
|
|
167
|
+
* for engines that step pragmas fully anyway (or that never run under
|
|
168
|
+
* incremental auto-vacuum) may omit it; callers fall back to `exec`.
|
|
169
|
+
*/
|
|
170
|
+
incrementalVacuum?(maxPages?: number): Promise<number>;
|
|
150
171
|
/**
|
|
151
172
|
* Checkpoint WAL file (for WAL mode databases).
|
|
152
173
|
* Returns the number of frames checkpointed.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { S as SQLiteAdapter, P as PreparedStatement } from '../adapter-
|
|
2
|
-
import { b as SQLiteConfig, a as SQLRow, S as SQLValue, R as RunResult } from '../types-
|
|
3
|
-
import
|
|
4
|
-
export { a as SCHEMA_DDL, S as SCHEMA_VERSION } from '../schema-
|
|
1
|
+
import { S as SQLiteAdapter, P as PreparedStatement } from '../adapter-imtxkmXZ.js';
|
|
2
|
+
import { b as SQLiteConfig, a as SQLRow, S as SQLValue, R as RunResult, l as SQLiteNodeBatchApplyInput, m as SQLiteNodeBatchApplyResult, E as ElectronSQLiteDiagnostics } from '../types-BTabr_VP.js';
|
|
3
|
+
import DatabaseType from 'better-sqlite3';
|
|
4
|
+
export { a as SCHEMA_DDL, S as SCHEMA_VERSION } from '../schema-C4gufY3B.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @xnetjs/sqlite - Electron SQLite adapter using better-sqlite3
|
|
@@ -26,13 +26,26 @@ export { a as SCHEMA_DDL, S as SCHEMA_VERSION } from '../schema-BEgIA-rZ.js';
|
|
|
26
26
|
*/
|
|
27
27
|
declare class ElectronSQLiteAdapter implements SQLiteAdapter {
|
|
28
28
|
private db;
|
|
29
|
+
/** Optional read-only secondary connection (exploration 0230, Phase 0.5). */
|
|
30
|
+
private readDb;
|
|
29
31
|
private config;
|
|
30
32
|
private inTransaction;
|
|
31
33
|
private statementCache;
|
|
34
|
+
private readStatementCache;
|
|
35
|
+
/** Priority scheduler fronting the writer connection (exploration 0230). */
|
|
36
|
+
private scheduler;
|
|
37
|
+
/** Read-only reader-thread pool for heavy parallel reads (Phase 1). */
|
|
38
|
+
private readerPool;
|
|
39
|
+
/** Monotonic clock of the most recent commit, for read-your-writes routing. */
|
|
40
|
+
private lastCommitAt;
|
|
32
41
|
open(config: SQLiteConfig): Promise<void>;
|
|
33
42
|
close(): Promise<void>;
|
|
34
43
|
isOpen(): boolean;
|
|
35
44
|
query<T extends SQLRow = SQLRow>(sql: string, params?: SQLValue[]): Promise<T[]>;
|
|
45
|
+
queryBatch(reads: Array<{
|
|
46
|
+
sql: string;
|
|
47
|
+
params?: SQLValue[];
|
|
48
|
+
}>): Promise<SQLRow[][]>;
|
|
36
49
|
queryOne<T extends SQLRow = SQLRow>(sql: string, params?: SQLValue[]): Promise<T | null>;
|
|
37
50
|
run(sql: string, params?: SQLValue[]): Promise<RunResult>;
|
|
38
51
|
exec(sql: string): Promise<void>;
|
|
@@ -55,20 +68,67 @@ declare class ElectronSQLiteAdapter implements SQLiteAdapter {
|
|
|
55
68
|
applySchema(version: number, sql: string): Promise<boolean>;
|
|
56
69
|
getDatabaseSize(): Promise<number>;
|
|
57
70
|
vacuum(): Promise<void>;
|
|
71
|
+
incrementalVacuum(maxPages?: number): Promise<number>;
|
|
58
72
|
checkpoint(): Promise<number>;
|
|
59
73
|
getStorageMode(): 'opfs' | 'memory';
|
|
60
74
|
/**
|
|
61
|
-
*
|
|
75
|
+
* Apply a node-store batch with cooperative yielding (exploration 0230).
|
|
76
|
+
*
|
|
77
|
+
* A bulk import is the one synchronous op long enough to head-of-line block
|
|
78
|
+
* interactive reads on the data-process thread. This splits the batch into
|
|
79
|
+
* chunks, each its own exclusive transaction, and yields to the event loop
|
|
80
|
+
* between chunks so a queued interactive read (or a reader-pool read) can
|
|
81
|
+
* interleave. Whole-batch atomicity is traded for yield points — safe here
|
|
82
|
+
* because node-batch writes are idempotent LWW upserts.
|
|
83
|
+
*/
|
|
84
|
+
applyNodeBatch(input: SQLiteNodeBatchApplyInput): Promise<SQLiteNodeBatchApplyResult>;
|
|
85
|
+
/** Scheduler queue depths (diagnostics / desktop perf panel). */
|
|
86
|
+
getSchedulerSnapshot(): ElectronSQLiteDiagnostics['scheduler'];
|
|
87
|
+
/** Reader-thread pool occupancy, or null when no pool is configured. */
|
|
88
|
+
getReaderPoolStats(): ElectronSQLiteDiagnostics['readerPool'];
|
|
89
|
+
/**
|
|
90
|
+
* WAL growth: `-wal` sidecar size + page count. Long-lived readers can pin an
|
|
91
|
+
* old snapshot and hold back checkpointing; our one-shot reader selects don't,
|
|
92
|
+
* so this should stay bounded. Surfaced to the diagnostics seam (0230).
|
|
93
|
+
*/
|
|
94
|
+
getWalStats(): Promise<ElectronSQLiteDiagnostics['wal']>;
|
|
95
|
+
/** Run a passive WAL checkpoint; returns frames checkpointed (best-effort). */
|
|
96
|
+
checkpointWal(): Promise<number>;
|
|
97
|
+
private runCheckpoint;
|
|
98
|
+
/** Combined point-in-time diagnostics for the desktop diagnostics seam. */
|
|
99
|
+
getDiagnostics(): Promise<ElectronSQLiteDiagnostics>;
|
|
100
|
+
/** Whether a heavy, non-transactional read should be offloaded to the pool. */
|
|
101
|
+
private shouldUsePool;
|
|
102
|
+
/** Reads within the configured window after a commit route to the writer. */
|
|
103
|
+
private inReadYourWritesWindow;
|
|
104
|
+
/** Pick the connection (+ its statement cache) a plain read should use. */
|
|
105
|
+
private readConnection;
|
|
106
|
+
/**
|
|
107
|
+
* Run `apply` as a single atomic chunk transaction. Scheduled as one write-lane
|
|
108
|
+
* job so it is indivisible w.r.t. the scheduler — no queued read or write can
|
|
109
|
+
* interleave mid-chunk — while the surrounding `applyNodeBatch` yields *between*
|
|
110
|
+
* chunks. `apply` is fully synchronous (no awaits), so `inTransaction` is set
|
|
111
|
+
* only for its duration and is invisible to other async callers.
|
|
112
|
+
*/
|
|
113
|
+
private runChunkTransaction;
|
|
114
|
+
private queryRaw;
|
|
115
|
+
private queryOneRaw;
|
|
116
|
+
private runRaw;
|
|
117
|
+
private execRaw;
|
|
118
|
+
/**
|
|
119
|
+
* Get a statement from cache or prepare it on the writer connection.
|
|
62
120
|
* Statement caching significantly improves performance for repeated queries.
|
|
63
121
|
*/
|
|
64
122
|
private getOrPrepare;
|
|
123
|
+
/** Statement cache keyed per connection (writer + read-only differ). */
|
|
124
|
+
private getOrPrepareOn;
|
|
65
125
|
private ensureOpen;
|
|
66
126
|
private wrapError;
|
|
67
127
|
/**
|
|
68
128
|
* Get the underlying better-sqlite3 database instance.
|
|
69
129
|
* Use for advanced operations not covered by the interface.
|
|
70
130
|
*/
|
|
71
|
-
getRawDatabase():
|
|
131
|
+
getRawDatabase(): DatabaseType.Database;
|
|
72
132
|
/**
|
|
73
133
|
* Create a batch writer for efficient bulk inserts.
|
|
74
134
|
*/
|