@xnetjs/sqlite 0.0.2 → 0.1.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/dist/{adapter-I7yAV6iu.d.ts → adapter-imtxkmXZ.d.ts} +48 -1
- package/dist/adapters/electron.d.ts +70 -6
- package/dist/adapters/electron.js +662 -36
- package/dist/adapters/expo.d.ts +6 -2
- package/dist/adapters/expo.js +34 -6
- 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 +71 -3
- package/dist/adapters/web-proxy.js +554 -39
- 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 +56 -1
- package/dist/adapters/web-worker.js +253 -14
- package/dist/adapters/web.d.ts +90 -3
- package/dist/adapters/web.js +10 -4
- package/dist/browser-support.d.ts +65 -1
- package/dist/browser-support.js +15 -3
- package/dist/chunk-5HC5V73T.js +191 -0
- package/dist/chunk-BBZDKLA3.js +727 -0
- package/dist/chunk-CBU263LI.js +30 -0
- package/dist/chunk-CGI2YBZY.js +16 -0
- package/dist/chunk-S6MT6KCI.js +279 -0
- package/dist/chunk-SV475UL5.js +44 -0
- package/dist/chunk-W3L4FXU5.js +415 -0
- package/dist/index.d.ts +111 -8
- package/dist/index.js +219 -130
- 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/chunk-BXYZU3OL.js +0 -245
- package/dist/chunk-HIREU5S5.js +0 -193
- package/dist/chunk-ZRR5D2OD.js +0 -140
- package/dist/schema-CjkXTqxn.d.ts +0 -35
- package/dist/types-C_aHfRDF.d.ts +0 -42
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as SQLiteConfig, a as SQLRow, S as SQLValue, R as RunResult } from './types-
|
|
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.
|
|
@@ -81,6 +89,24 @@ interface SQLiteAdapter {
|
|
|
81
89
|
* })
|
|
82
90
|
*/
|
|
83
91
|
transaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
92
|
+
/**
|
|
93
|
+
* Execute a list of SQL statements inside one transaction.
|
|
94
|
+
*
|
|
95
|
+
* This is primarily for proxy/worker-backed adapters where a callback
|
|
96
|
+
* transaction would cross a serialization boundary. Implementations should
|
|
97
|
+
* execute all operations atomically and roll back on the first failure.
|
|
98
|
+
*/
|
|
99
|
+
transactionBatch?(operations: Array<{
|
|
100
|
+
sql: string;
|
|
101
|
+
params?: SQLValue[];
|
|
102
|
+
}>): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Execute a node-store batch using compact typed row payloads.
|
|
105
|
+
*
|
|
106
|
+
* Worker-backed adapters can use this to avoid transferring a very large
|
|
107
|
+
* array of repeated SQL strings over Comlink.
|
|
108
|
+
*/
|
|
109
|
+
applyNodeBatch?(input: SQLiteNodeBatchApplyInput): Promise<SQLiteNodeBatchApplyResult>;
|
|
84
110
|
/**
|
|
85
111
|
* Begin a manual transaction.
|
|
86
112
|
* Must be followed by commit() or rollback().
|
|
@@ -129,6 +155,19 @@ interface SQLiteAdapter {
|
|
|
129
155
|
* Vacuum the database to reclaim space.
|
|
130
156
|
*/
|
|
131
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>;
|
|
132
171
|
/**
|
|
133
172
|
* Checkpoint WAL file (for WAL mode databases).
|
|
134
173
|
* Returns the number of frames checkpointed.
|
|
@@ -140,6 +179,14 @@ interface SQLiteAdapter {
|
|
|
140
179
|
* or 'memory' if using in-memory fallback.
|
|
141
180
|
*/
|
|
142
181
|
getStorageMode(): Promise<'opfs' | 'memory'> | 'opfs' | 'memory';
|
|
182
|
+
/**
|
|
183
|
+
* Optional cumulative operation counters for import diagnostics.
|
|
184
|
+
*/
|
|
185
|
+
getOperationStats?(): Promise<SQLiteOperationStats> | SQLiteOperationStats;
|
|
186
|
+
/**
|
|
187
|
+
* Reset cumulative operation counters when starting a focused measurement.
|
|
188
|
+
*/
|
|
189
|
+
resetOperationStats?(): Promise<void> | void;
|
|
143
190
|
}
|
|
144
191
|
/**
|
|
145
192
|
* Prepared statement for repeated execution.
|
|
@@ -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,17 +26,34 @@ export { a as SCHEMA_DDL, S as SCHEMA_VERSION } from '../schema-CjkXTqxn.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>;
|
|
39
52
|
transaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
53
|
+
transactionBatch(operations: Array<{
|
|
54
|
+
sql: string;
|
|
55
|
+
params?: SQLValue[];
|
|
56
|
+
}>): Promise<void>;
|
|
40
57
|
/**
|
|
41
58
|
* Synchronous transaction for performance-critical batch operations.
|
|
42
59
|
* Prefer this over async transaction when the body is synchronous.
|
|
@@ -51,20 +68,67 @@ declare class ElectronSQLiteAdapter implements SQLiteAdapter {
|
|
|
51
68
|
applySchema(version: number, sql: string): Promise<boolean>;
|
|
52
69
|
getDatabaseSize(): Promise<number>;
|
|
53
70
|
vacuum(): Promise<void>;
|
|
71
|
+
incrementalVacuum(maxPages?: number): Promise<number>;
|
|
54
72
|
checkpoint(): Promise<number>;
|
|
55
73
|
getStorageMode(): 'opfs' | 'memory';
|
|
56
74
|
/**
|
|
57
|
-
*
|
|
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.
|
|
58
120
|
* Statement caching significantly improves performance for repeated queries.
|
|
59
121
|
*/
|
|
60
122
|
private getOrPrepare;
|
|
123
|
+
/** Statement cache keyed per connection (writer + read-only differ). */
|
|
124
|
+
private getOrPrepareOn;
|
|
61
125
|
private ensureOpen;
|
|
62
126
|
private wrapError;
|
|
63
127
|
/**
|
|
64
128
|
* Get the underlying better-sqlite3 database instance.
|
|
65
129
|
* Use for advanced operations not covered by the interface.
|
|
66
130
|
*/
|
|
67
|
-
getRawDatabase():
|
|
131
|
+
getRawDatabase(): DatabaseType.Database;
|
|
68
132
|
/**
|
|
69
133
|
* Create a batch writer for efficient bulk inserts.
|
|
70
134
|
*/
|