@event-driven-io/dumbo 0.13.0-beta.36 → 0.13.0-beta.37
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/cloudflare.cjs +12 -16
- package/dist/cloudflare.cjs.map +1 -1
- package/dist/cloudflare.d.cts +1 -1
- package/dist/cloudflare.d.ts +1 -1
- package/dist/cloudflare.js +12 -16
- package/dist/cloudflare.js.map +1 -1
- package/dist/{core-DDo4m0Z_.js → core-BG__WVn6.js} +2 -2
- package/dist/{core-DDo4m0Z_.js.map → core-BG__WVn6.js.map} +1 -1
- package/dist/{core-Bf2ujUFy.js → core-BchvTX3G.js} +3 -3
- package/dist/{core-Bf2ujUFy.js.map → core-BchvTX3G.js.map} +1 -1
- package/dist/{core-DmbB4qMn.cjs → core-CWZb0zOY.cjs} +23 -91
- package/dist/core-CWZb0zOY.cjs.map +1 -0
- package/dist/{core-BgYtAxCm.cjs → core-D-smW7cm.cjs} +7 -1
- package/dist/{core-BgYtAxCm.cjs.map → core-D-smW7cm.cjs.map} +1 -1
- package/dist/{core-Go_IA78L.cjs → core-DXCRR5A9.cjs} +3 -3
- package/dist/{core-Go_IA78L.cjs.map → core-DXCRR5A9.cjs.map} +1 -1
- package/dist/{core-BeyC5tHn.js → core-DlV8ua1P.js} +23 -91
- package/dist/core-DlV8ua1P.js.map +1 -0
- package/dist/{index-D1jryNqo.d.ts → index-BgFHGsuP.d.ts} +2 -14
- package/dist/{index-DqVvUav9.d.cts → index-N2ly5shv.d.cts} +2 -14
- package/dist/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/pg.cjs +3 -3
- package/dist/pg.js +3 -3
- package/dist/{postgreSQLMetadata-zMq8yJo_.js → postgreSQLMetadata-BTz6vdwE.js} +2 -2
- package/dist/{postgreSQLMetadata-zMq8yJo_.js.map → postgreSQLMetadata-BTz6vdwE.js.map} +1 -1
- package/dist/{postgreSQLMetadata-LqX-Z_wo.cjs → postgreSQLMetadata-WGXySO7a.cjs} +2 -2
- package/dist/{postgreSQLMetadata-LqX-Z_wo.cjs.map → postgreSQLMetadata-WGXySO7a.cjs.map} +1 -1
- package/dist/postgresql.cjs +2 -2
- package/dist/postgresql.js +2 -2
- package/dist/sqlite.cjs +2 -2
- package/dist/sqlite.d.cts +1 -1
- package/dist/sqlite.d.ts +1 -1
- package/dist/sqlite.js +2 -2
- package/dist/sqlite3.cjs +133 -13
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +7 -7
- package/dist/sqlite3.d.ts +7 -7
- package/dist/sqlite3.js +133 -13
- package/dist/sqlite3.js.map +1 -1
- package/dist/{sqliteMetadata-BoQ7Sc9I.js → sqliteMetadata-7qBjsMBN.js} +2 -2
- package/dist/{sqliteMetadata-BoQ7Sc9I.js.map → sqliteMetadata-7qBjsMBN.js.map} +1 -1
- package/dist/{sqliteMetadata-D_2pKeCC.cjs → sqliteMetadata-PJTRPIZ1.cjs} +2 -2
- package/dist/{sqliteMetadata-D_2pKeCC.cjs.map → sqliteMetadata-PJTRPIZ1.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/core-BeyC5tHn.js.map +0 -1
- package/dist/core-DmbB4qMn.cjs.map +0 -1
package/dist/sqlite3.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as defaultSQLiteDatabase, r as tableExists, t as sqliteMetadata } from "./sqliteMetadata-
|
|
3
|
-
import { C as mapSqliteError, S as sqliteFormatter, _ as SQLiteConnectionString, a as sqliteAmbientConnectionPool, b as sqliteExecute, c as toSqlitePoolOptions, d as isSQLiteError, f as sqliteAmbientClientConnection, g as transactionNestingCounter, h as sqlitePoolClientConnection, i as sqliteAlwaysNewConnectionPool, l as DEFAULT_SQLITE_PRAGMA_OPTIONS, m as sqliteConnection, n as DefaultSQLiteMigratorOptions, o as sqlitePool, p as sqliteClientConnection, r as isInMemoryDatabase, s as sqliteSingletonConnectionPool, t as SQLiteDatabaseName, u as InMemorySQLiteDatabase, v as parsePragmasFromConnectionString, x as sqliteSQLExecutor, y as sqliteTransaction } from "./core-
|
|
1
|
+
import { On as canHandleDriverWithConnectionString, c as TaskProcessor, in as JSONSerializer, kn as dumboDatabaseDriverRegistry, o as createSingletonConnectionPool, r as createBoundedConnectionPool, s as guardInitializedOnce, v as BatchCommandNoChangesError, xt as SQL } from "./core-BG__WVn6.js";
|
|
2
|
+
import { n as defaultSQLiteDatabase, r as tableExists, t as sqliteMetadata } from "./sqliteMetadata-7qBjsMBN.js";
|
|
3
|
+
import { C as mapSqliteError, S as sqliteFormatter, _ as SQLiteConnectionString, a as sqliteAmbientConnectionPool, b as sqliteExecute, c as toSqlitePoolOptions, d as isSQLiteError, f as sqliteAmbientClientConnection, g as transactionNestingCounter, h as sqlitePoolClientConnection, i as sqliteAlwaysNewConnectionPool, l as DEFAULT_SQLITE_PRAGMA_OPTIONS, m as sqliteConnection, n as DefaultSQLiteMigratorOptions, o as sqlitePool, p as sqliteClientConnection, r as isInMemoryDatabase, s as sqliteSingletonConnectionPool, t as SQLiteDatabaseName, u as InMemorySQLiteDatabase, v as parsePragmasFromConnectionString, x as sqliteSQLExecutor, y as sqliteTransaction } from "./core-DlV8ua1P.js";
|
|
4
4
|
import sqlite3 from "sqlite3";
|
|
5
|
+
import { cpus } from "os";
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
7
|
|
|
6
8
|
//#region src/storage/sqlite/core/connections/pragmas.ts
|
|
7
9
|
const mergePragmaOptions = (connectionString, userOptions) => {
|
|
@@ -254,19 +256,137 @@ const sqlite3Connection = (options) => sqliteConnection({
|
|
|
254
256
|
serializer: options.serializer
|
|
255
257
|
});
|
|
256
258
|
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/storage/sqlite/sqlite3/pool/singletonPool.ts
|
|
261
|
+
const sqlite3SingletonPool = (options) => {
|
|
262
|
+
const inner = createSingletonConnectionPool({
|
|
263
|
+
driverType: options.driverType,
|
|
264
|
+
getConnection: options.getConnection,
|
|
265
|
+
...options.closeConnection ? { closeConnection: options.closeConnection } : {}
|
|
266
|
+
});
|
|
267
|
+
const taskProcessor = new TaskProcessor({
|
|
268
|
+
maxActiveTasks: 1,
|
|
269
|
+
maxQueueSize: options.maxQueueSize ?? 1e3
|
|
270
|
+
});
|
|
271
|
+
const insideWriterTask = new AsyncLocalStorage();
|
|
272
|
+
const enqueue = (op) => {
|
|
273
|
+
if (insideWriterTask.getStore() === true) return op();
|
|
274
|
+
return taskProcessor.enqueue(({ ack }) => insideWriterTask.run(true, async () => {
|
|
275
|
+
try {
|
|
276
|
+
return await op();
|
|
277
|
+
} finally {
|
|
278
|
+
ack();
|
|
279
|
+
}
|
|
280
|
+
}));
|
|
281
|
+
};
|
|
282
|
+
return {
|
|
283
|
+
driverType: inner.driverType,
|
|
284
|
+
connection: inner.connection.bind(inner),
|
|
285
|
+
transaction: inner.transaction.bind(inner),
|
|
286
|
+
withConnection: (handle, connectionOptions) => enqueue(() => inner.withConnection(handle, connectionOptions)),
|
|
287
|
+
withTransaction: (handle, transactionOptions) => enqueue(() => inner.withTransaction(handle, transactionOptions)),
|
|
288
|
+
execute: {
|
|
289
|
+
query: (sql, queryOptions) => enqueue(() => inner.execute.query(sql, queryOptions)),
|
|
290
|
+
batchQuery: (sqls, queryOptions) => enqueue(() => inner.execute.batchQuery(sqls, queryOptions)),
|
|
291
|
+
command: (sql, commandOptions) => enqueue(() => inner.execute.command(sql, commandOptions)),
|
|
292
|
+
batchCommand: (sqls, commandOptions) => enqueue(() => inner.execute.batchCommand(sqls, commandOptions))
|
|
293
|
+
},
|
|
294
|
+
close: async () => {
|
|
295
|
+
await taskProcessor.stop();
|
|
296
|
+
await inner.close();
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/storage/sqlite/sqlite3/pool/dualPool.ts
|
|
303
|
+
const sqliteDualConnectionPool = (options) => {
|
|
304
|
+
const { sqliteConnectionFactory, connectionOptions } = options;
|
|
305
|
+
const readerPoolSize = options.readerPoolSize ?? Math.max(4, cpus().length);
|
|
306
|
+
let databaseInitPromise = null;
|
|
307
|
+
const guardSingleConnection = guardInitializedOnce(async () => {
|
|
308
|
+
if (databaseInitPromise !== null) return databaseInitPromise;
|
|
309
|
+
const initConnection = sqliteConnectionFactory({
|
|
310
|
+
...connectionOptions,
|
|
311
|
+
skipDatabasePragmas: false,
|
|
312
|
+
readonly: false
|
|
313
|
+
});
|
|
314
|
+
const initPromise = initConnection.open();
|
|
315
|
+
databaseInitPromise = initPromise;
|
|
316
|
+
try {
|
|
317
|
+
await initPromise;
|
|
318
|
+
await initConnection.close();
|
|
319
|
+
} catch (error) {
|
|
320
|
+
databaseInitPromise = null;
|
|
321
|
+
await initConnection.close();
|
|
322
|
+
throw mapSqliteError(error);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
const ensureDatabaseInitialized = async () => {
|
|
326
|
+
if (databaseInitPromise !== null) return databaseInitPromise;
|
|
327
|
+
return guardSingleConnection.ensureInitialized();
|
|
328
|
+
};
|
|
329
|
+
const wrappedConnectionFactory = async (readonly, connectionOptions) => {
|
|
330
|
+
await ensureDatabaseInitialized();
|
|
331
|
+
const connection = sqliteConnectionFactory({
|
|
332
|
+
...connectionOptions,
|
|
333
|
+
skipDatabasePragmas: true,
|
|
334
|
+
readonly
|
|
335
|
+
});
|
|
336
|
+
await connection.open();
|
|
337
|
+
return connection;
|
|
338
|
+
};
|
|
339
|
+
const writerPool = sqlite3SingletonPool({
|
|
340
|
+
driverType: options.driverType,
|
|
341
|
+
getConnection: () => wrappedConnectionFactory(false, connectionOptions)
|
|
342
|
+
});
|
|
343
|
+
const readerPool = createBoundedConnectionPool({
|
|
344
|
+
driverType: options.driverType,
|
|
345
|
+
getConnection: () => wrappedConnectionFactory(true, connectionOptions),
|
|
346
|
+
maxConnections: readerPoolSize
|
|
347
|
+
});
|
|
348
|
+
return {
|
|
349
|
+
driverType: options.driverType,
|
|
350
|
+
connection: (connectionOptions) => connectionOptions?.readonly ? readerPool.connection(connectionOptions) : writerPool.connection(connectionOptions),
|
|
351
|
+
execute: {
|
|
352
|
+
query: (...args) => readerPool.execute.query(...args),
|
|
353
|
+
batchQuery: (...args) => readerPool.execute.batchQuery(...args),
|
|
354
|
+
command: (...args) => writerPool.execute.command(...args),
|
|
355
|
+
batchCommand: (...args) => writerPool.execute.batchCommand(...args)
|
|
356
|
+
},
|
|
357
|
+
withConnection: (handle, connectionOptions) => connectionOptions?.readonly ? readerPool.withConnection(handle, connectionOptions) : writerPool.withConnection(handle, connectionOptions),
|
|
358
|
+
transaction: writerPool.transaction,
|
|
359
|
+
withTransaction: writerPool.withTransaction,
|
|
360
|
+
close: async () => {
|
|
361
|
+
await guardSingleConnection.stop();
|
|
362
|
+
await Promise.all([writerPool.close(), readerPool.close()]);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
|
|
257
367
|
//#endregion
|
|
258
368
|
//#region src/storage/sqlite/sqlite3/index.ts
|
|
259
|
-
const sqlite3Pool = (options) =>
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
369
|
+
const sqlite3Pool = (options) => {
|
|
370
|
+
if ("connection" in options && options.connection) return sqlitePool(toSqlitePoolOptions({
|
|
371
|
+
...options,
|
|
372
|
+
driverType: SQLite3DriverType
|
|
373
|
+
}));
|
|
374
|
+
const sqliteConnectionFactory = (opts) => sqlite3Connection({
|
|
375
|
+
...opts,
|
|
376
|
+
serializer: options.serializer ?? JSONSerializer
|
|
377
|
+
});
|
|
378
|
+
if (isInMemoryDatabase(options) || "client" in options && Boolean(options.client) || options.singleton === true) return sqlite3SingletonPool({
|
|
379
|
+
driverType: SQLite3DriverType,
|
|
380
|
+
getConnection: () => sqliteConnectionFactory(options)
|
|
381
|
+
});
|
|
382
|
+
const readerPoolSize = options.readerPoolSize;
|
|
383
|
+
return sqliteDualConnectionPool({
|
|
384
|
+
driverType: SQLite3DriverType,
|
|
385
|
+
sqliteConnectionFactory,
|
|
263
386
|
connectionOptions: options,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
})
|
|
268
|
-
}
|
|
269
|
-
}));
|
|
387
|
+
...readerPoolSize !== void 0 ? { readerPoolSize } : {}
|
|
388
|
+
});
|
|
389
|
+
};
|
|
270
390
|
const tryParseConnectionString = (connectionString) => {
|
|
271
391
|
try {
|
|
272
392
|
return SQLiteConnectionString(connectionString);
|
package/dist/sqlite3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite3.js","names":[],"sources":["../src/storage/sqlite/core/connections/pragmas.ts","../src/storage/sqlite/sqlite3/connections/connection.ts","../src/storage/sqlite/sqlite3/index.ts"],"sourcesContent":["import { parsePragmasFromConnectionString } from './connectionString';\nimport {\n DEFAULT_SQLITE_PRAGMA_OPTIONS,\n type SQLitePragmaOptions,\n} from './index';\n\nexport const mergePragmaOptions = (\n connectionString: string,\n userOptions?: Partial<SQLitePragmaOptions>,\n): SQLitePragmaOptions => {\n const connectionStringPragmas =\n parsePragmasFromConnectionString(connectionString);\n\n return {\n ...DEFAULT_SQLITE_PRAGMA_OPTIONS,\n ...connectionStringPragmas,\n ...userOptions,\n };\n};\n\nexport const buildConnectionPragmaStatements = (\n pragmas: SQLitePragmaOptions,\n): Array<{ pragma: string; value: string | number }> => [\n // busy_timeout FIRST - enables waiting on locks for subsequent operations\n { pragma: 'busy_timeout', value: pragmas.busy_timeout! },\n { pragma: 'synchronous', value: pragmas.synchronous! },\n { pragma: 'cache_size', value: pragmas.cache_size! },\n { pragma: 'foreign_keys', value: pragmas.foreign_keys ? 'ON' : 'OFF' },\n { pragma: 'temp_store', value: pragmas.temp_store! },\n ...(pragmas.mmap_size !== undefined\n ? [{ pragma: 'mmap_size', value: pragmas.mmap_size }]\n : []),\n];\n\nexport const buildDatabasePragmaStatements = (\n pragmas: SQLitePragmaOptions,\n): Array<{ pragma: string; value: string | number }> => [\n { pragma: 'journal_mode', value: pragmas.journal_mode! },\n];\n","import sqlite3 from 'sqlite3';\nimport type { JSONSerializer } from '../../../../core';\nimport {\n BatchCommandNoChangesError,\n SQL,\n type Connection,\n type QueryResult,\n type QueryResultRow,\n type SQLQueryOptions,\n} from '../../../../core';\nimport type {\n SQLiteClient,\n SQLiteClientOrPoolClient,\n SQLiteConnectionOptions,\n SQLiteDriverType,\n SQLiteFileNameOrConnectionString,\n SQLiteTransaction,\n SQLiteTransactionOptions,\n} from '../../core';\nimport {\n DEFAULT_SQLITE_PRAGMA_OPTIONS,\n InMemorySQLiteDatabase,\n sqliteConnection,\n type BatchSQLiteCommandOptions,\n type SQLiteClientOptions,\n type SQLiteCommandOptions,\n type SQLiteParameters,\n} from '../../core/connections';\nimport {\n buildConnectionPragmaStatements,\n buildDatabasePragmaStatements,\n mergePragmaOptions,\n} from '../../core/connections/pragmas';\nimport { mapSqliteError } from '../../core/errors/errorMapper';\nimport { sqliteFormatter } from '../../core/sql/formatter';\n\nexport type SQLite3DriverType = SQLiteDriverType<'sqlite3'>;\nexport const SQLite3DriverType: SQLite3DriverType = 'SQLite:sqlite3';\n\nexport type ConnectionCheckResult =\n | { successful: true }\n | {\n successful: false;\n code: string | undefined;\n errorType: 'ConnectionRefused' | 'Authentication' | 'Unknown';\n error: unknown;\n };\n\nconst hasReturningClause = (sql: string): boolean => /\\bRETURNING\\b/i.test(sql);\n\nexport type SQLite3ClientOptions = SQLiteClientOptions &\n SQLiteFileNameOrConnectionString;\n\nexport type SQLite3Client = SQLiteClientOrPoolClient;\n\nexport type SQLite3ConnectionOptions = SQLiteConnectionOptions &\n ((SQLite3ClientOptions & { client?: never }) | { client: SQLite3Client });\n\nexport type SQLite3Connection<\n ClientType extends SQLiteClientOrPoolClient = SQLiteClientOrPoolClient,\n> = Connection<\n SQLite3Connection,\n SQLite3DriverType,\n ClientType,\n SQLiteTransaction<SQLite3Connection, SQLiteTransactionOptions>\n>;\n\nconst applyPragma = (\n database: sqlite3.Database,\n pragma: string,\n value: string | number,\n) => {\n return new Promise<void>((resolve, reject) => {\n database.run(`PRAGMA ${pragma} = ${value};`, (err) => {\n if (err) reject(err);\n else resolve();\n });\n });\n};\n\nconst queryPragma = (\n database: sqlite3.Database,\n pragma: string,\n): Promise<string> =>\n new Promise((resolve, reject) => {\n database.get(\n `PRAGMA ${pragma};`,\n (err: Error | null, row: { [key: string]: string } | null) => {\n if (err) reject(err);\n else resolve(row?.[pragma] ?? '');\n },\n );\n });\n\nconst applyPragmas = (\n database: sqlite3.Database,\n pragmas: Array<{ pragma: string; value: string | number }>,\n) =>\n pragmas.reduce(\n (promise, { pragma, value }) =>\n promise.then(() => applyPragma(database, pragma, value)),\n Promise.resolve(),\n );\n\nexport const sqlite3Client = (\n options: SQLite3ClientOptions & {\n serializer: JSONSerializer;\n },\n): SQLiteClient => {\n let db: sqlite3.Database;\n\n let isClosed = false;\n\n const { serializer } = options;\n\n const connectionString =\n options.fileName ?? options.connectionString ?? InMemorySQLiteDatabase;\n\n const finalPragmas = mergePragmaOptions(\n String(connectionString),\n options.pragmaOptions,\n );\n\n const connectionPragmas = buildConnectionPragmaStatements(finalPragmas);\n\n const connect: () => Promise<void> = () =>\n db\n ? Promise.resolve()\n : new Promise((resolve, reject) => {\n try {\n db = new sqlite3.Database(\n connectionString,\n sqlite3.OPEN_URI | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE,\n (err) => {\n if (err) {\n reject(err);\n return;\n }\n\n const busyTimeout =\n finalPragmas.busy_timeout ??\n DEFAULT_SQLITE_PRAGMA_OPTIONS.busy_timeout!;\n\n db.configure('busyTimeout', busyTimeout);\n\n applyPragmas(\n db,\n connectionPragmas.filter((p) => p.pragma !== 'busy_timeout'),\n )\n .then(async () => {\n if (options.skipDatabasePragmas) return;\n\n const databasePragmas =\n buildDatabasePragmaStatements(finalPragmas);\n for (const { pragma, value } of databasePragmas) {\n const current = await queryPragma(db, pragma);\n if (\n current.toUpperCase() !== String(value).toUpperCase()\n ) {\n await applyPragma(db, pragma, value);\n }\n }\n })\n .then(() => resolve())\n .catch(reject);\n },\n );\n\n // Apply connection-level pragmas first (busy_timeout is first)\n } catch (error) {\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n\n const executeQuery = <T>(\n sql: string,\n params?: SQLiteParameters[],\n ): Promise<T[]> =>\n new Promise((resolve, reject) => {\n try {\n db.all(sql, params ?? [], (err: Error | null, result: T[]) => {\n if (err) {\n reject(err);\n return;\n }\n\n resolve(result);\n });\n } catch (error) {\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n\n const executeCommand = <Result extends QueryResultRow = QueryResultRow>(\n sql: string,\n params?: SQLiteParameters[],\n options?: SQLiteCommandOptions,\n ): Promise<QueryResult<Result>> =>\n new Promise((resolve, reject) => {\n try {\n if (options?.ignoreChangesCount === true) {\n db.run(\n sql,\n params ?? [],\n function (err: Error | null, rows: Result[]) {\n if (err) {\n reject(err);\n return;\n }\n resolve({\n rowCount: 0,\n rows: rows ?? [],\n });\n },\n );\n return;\n }\n\n if (hasReturningClause(sql)) {\n db.all(sql, params ?? [], (err, rows: Result[]) => {\n if (err) return reject(err);\n resolve({ rowCount: rows.length, rows });\n });\n return;\n }\n\n // OD: 2026-01-21\n // This is needed as SQLite does not return changes count properly\n // We need to query it separately with SELECT changes()\n // This may be fixed eventually in sqlite3 library as Node.js team did here:\n // https://github.com/nodejs/node/issues/57344\n // But for now, we do it manually, as a workaround\n // We also serialize it to avoid race conditions\n db.serialize(() => {\n let hasFailed = false;\n let resultRows: Result[] = [];\n\n db.all(sql, params ?? [], (err, rows: Result[]) => {\n if (err) {\n hasFailed = true;\n return reject(err);\n }\n resultRows = rows;\n });\n\n db.get(\n 'SELECT changes() as changes',\n (err, row: { changes: number } | null) => {\n // If the first query failed, we exit immediately.\n // The promise is already rejected; we don't want to touch it.\n if (hasFailed) return;\n\n if (err) return reject(err);\n\n resolve({\n rowCount: row?.changes ?? 0,\n rows: resultRows,\n });\n },\n );\n });\n } catch (error) {\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n\n return {\n connect,\n close: async (): Promise<void> => {\n if (isClosed) {\n return;\n }\n isClosed = true;\n if (db) {\n try {\n await new Promise<void>((resolve, reject) => {\n db.close((err: Error | null) => {\n if (err) {\n reject(err);\n return;\n }\n resolve();\n });\n });\n } catch (error) {\n throw mapSqliteError(error);\n }\n }\n },\n query: async <Result extends QueryResultRow = QueryResultRow>(\n sql: SQL,\n _options?: SQLQueryOptions,\n ): Promise<QueryResult<Result>> => {\n try {\n const { query, params } = sqliteFormatter.format(sql, {\n serializer,\n });\n const result = await executeQuery<Result>(\n query,\n params as SQLiteParameters[],\n );\n return { rowCount: result.length, rows: result };\n } catch (error) {\n throw mapSqliteError(error);\n }\n },\n batchQuery: async <Result extends QueryResultRow = QueryResultRow>(\n sqls: SQL[],\n _options?: SQLQueryOptions,\n ): Promise<QueryResult<Result>[]> => {\n try {\n const results: QueryResult<Result>[] = [];\n for (const sql of sqls) {\n const { query, params } = sqliteFormatter.format(sql, {\n serializer,\n });\n const result = await executeQuery<Result>(\n query,\n params as SQLiteParameters[],\n );\n results.push({ rowCount: result.length, rows: result });\n }\n return results;\n } catch (error) {\n throw mapSqliteError(error);\n }\n },\n command: async <Result extends QueryResultRow = QueryResultRow>(\n sql: SQL,\n options?: SQLiteCommandOptions,\n ): Promise<QueryResult<Result>> => {\n try {\n const { query, params } = sqliteFormatter.format(sql, {\n serializer,\n });\n\n return await executeCommand<Result>(\n query,\n params as SQLiteParameters[],\n options,\n );\n } catch (error) {\n throw mapSqliteError(error);\n }\n },\n batchCommand: async <Result extends QueryResultRow = QueryResultRow>(\n sqls: SQL[],\n options?: BatchSQLiteCommandOptions,\n ): Promise<QueryResult<Result>[]> => {\n try {\n const results: QueryResult<Result>[] = [];\n\n for (let i = 0; i < sqls.length; i++) {\n const { query, params } = sqliteFormatter.format(sqls[i]!, {\n serializer,\n });\n const result = await executeCommand<Result>(\n query,\n params as SQLiteParameters[],\n options,\n );\n results.push(result);\n\n if (options?.assertChanges && (result.rowCount ?? 0) === 0) {\n throw new BatchCommandNoChangesError(i);\n }\n }\n return results;\n } catch (error) {\n throw mapSqliteError(error);\n }\n },\n };\n};\n\nexport const checkConnection = async (\n fileName: string,\n serializer: JSONSerializer,\n): Promise<ConnectionCheckResult> => {\n const client = sqlite3Client({\n fileName,\n serializer,\n });\n\n try {\n await client.query(SQL`SELECT 1`);\n return { successful: true };\n } catch (error) {\n const code =\n error instanceof Error &&\n 'code' in error &&\n typeof error.code === 'string'\n ? error.code\n : undefined;\n\n return {\n successful: false,\n errorType:\n code === 'SQLITE_CANTOPEN'\n ? 'ConnectionRefused'\n : code === 'SQLITE_AUTH'\n ? 'Authentication'\n : 'Unknown',\n code,\n error,\n };\n } finally {\n await client.close();\n }\n};\n\nexport const sqlite3Connection = (\n options: SQLite3ConnectionOptions & { serializer: JSONSerializer },\n) =>\n sqliteConnection<SQLite3Connection, SQLite3ConnectionOptions>({\n type: 'Client',\n driverType: SQLite3DriverType,\n sqliteClientFactory: (connectionOptions) => {\n if ('client' in connectionOptions && connectionOptions.client) {\n return connectionOptions.client;\n }\n return sqlite3Client({\n ...connectionOptions,\n serializer: options.serializer,\n });\n },\n connectionOptions: options,\n serializer: options.serializer,\n });\n","export * from './connections';\nimport {\n canHandleDriverWithConnectionString,\n dumboDatabaseDriverRegistry,\n JSONSerializer,\n type DumboConnectionOptions,\n type DumboDatabaseDriver,\n} from '../../../core';\nimport {\n DefaultSQLiteMigratorOptions,\n SQLiteConnectionString,\n sqliteFormatter,\n sqliteMetadata,\n sqlitePool,\n toSqlitePoolOptions,\n type SQLitePool,\n type SQLitePoolOptions,\n} from '../core';\nimport {\n sqlite3Connection,\n SQLite3DriverType,\n type SQLite3Connection,\n type SQLite3ConnectionOptions,\n} from './connections';\n\nexport type SQLite3DumboOptions = Omit<\n SQLitePoolOptions<SQLite3Connection, SQLite3ConnectionOptions>,\n 'driverType'\n> &\n SQLite3ConnectionOptions & { serializer?: JSONSerializer };\n\nexport type SQLite3PoolOptions = SQLite3DumboOptions;\n\nexport type Sqlite3Pool = SQLitePool<SQLite3Connection>;\n\nexport const sqlite3Pool = (options: SQLite3DumboOptions) =>\n sqlitePool(\n toSqlitePoolOptions({\n ...options,\n driverType: SQLite3DriverType,\n ...('connection' in options\n ? {}\n : {\n connectionOptions: options,\n sqliteConnectionFactory: (opts: SQLite3ConnectionOptions) =>\n sqlite3Connection({\n ...opts,\n serializer: options.serializer ?? JSONSerializer,\n }),\n }),\n }),\n );\n\nconst tryParseConnectionString = (connectionString: string) => {\n try {\n return SQLiteConnectionString(connectionString);\n } catch {\n return null;\n }\n};\n\nexport const sqlite3DumboDriver = {\n driverType: SQLite3DriverType,\n createPool: (options) => sqlite3Pool(options as SQLite3DumboOptions),\n sqlFormatter: sqliteFormatter,\n defaultMigratorOptions: DefaultSQLiteMigratorOptions,\n canHandle: canHandleDriverWithConnectionString(\n SQLite3DriverType,\n tryParseConnectionString,\n ),\n databaseMetadata: sqliteMetadata,\n} satisfies DumboDatabaseDriver<\n SQLite3Connection,\n SQLite3DumboOptions,\n Sqlite3Pool\n>;\n\nexport const useSqlite3DumboDriver = () => {\n dumboDatabaseDriverRegistry.register(SQLite3DriverType, sqlite3DumboDriver);\n};\n\nexport type SQLite3DumboConnectionOptions = DumboConnectionOptions<\n typeof sqlite3DumboDriver\n> & { connectionString: string | SQLiteConnectionString };\n\nuseSqlite3DumboDriver();\n\nexport * from './connections';\nexport * from './formatter';\nexport * from './transactions';\n"],"mappings":";;;;;;AAMA,MAAa,sBACX,kBACA,gBACwB;CACxB,MAAM,0BACJ,iCAAiC,iBAAiB;AAEpD,QAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACJ;;AAGH,MAAa,mCACX,YACsD;CAEtD;EAAE,QAAQ;EAAgB,OAAO,QAAQ;EAAe;CACxD;EAAE,QAAQ;EAAe,OAAO,QAAQ;EAAc;CACtD;EAAE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YAAY,QAAQ;GACrB,CAAC;;CAEJ,mBAAmB;CACnB,YAAY,QAAQ;CACrB,CAAC;;;;ACzYJ,MAAa,eAAe,YAC1B,WACE,oBAAoB;CAClB,GAAG;CACH,YAAY;CACZ,GAAI,gBAAgB,UAChB,EAAE,GACF;EACE,mBAAmB;EACnB,0BAA0B,SACxB,kBAAkB;GAChB,GAAG;GACH,YAAY,QAAQ,cAAc;GACnC,CAAC;EACL;CACN,CAAC,CACH;AAEH,MAAM,4BAA4B,qBAA6B;AAC7D,KAAI;AACF,SAAO,uBAAuB,iBAAiB;SACzC;AACN,SAAO;;;AAIX,MAAa,qBAAqB;CAChC,YAAY;CACZ,aAAa,YAAY,YAAY,QAA+B;CACpE,cAAc;CACd,wBAAwB;CACxB,WAAW,oCACT,mBACA,yBACD;CACD,kBAAkB;CACnB;AAMD,MAAa,8BAA8B;AACzC,6BAA4B,SAAS,mBAAmB,mBAAmB;;AAO7E,uBAAuB"}
|
|
1
|
+
{"version":3,"file":"sqlite3.js","names":[],"sources":["../src/storage/sqlite/core/connections/pragmas.ts","../src/storage/sqlite/sqlite3/connections/connection.ts","../src/storage/sqlite/sqlite3/pool/singletonPool.ts","../src/storage/sqlite/sqlite3/pool/dualPool.ts","../src/storage/sqlite/sqlite3/index.ts"],"sourcesContent":["import { parsePragmasFromConnectionString } from './connectionString';\nimport {\n DEFAULT_SQLITE_PRAGMA_OPTIONS,\n type SQLitePragmaOptions,\n} from './index';\n\nexport const mergePragmaOptions = (\n connectionString: string,\n userOptions?: Partial<SQLitePragmaOptions>,\n): SQLitePragmaOptions => {\n const connectionStringPragmas =\n parsePragmasFromConnectionString(connectionString);\n\n return {\n ...DEFAULT_SQLITE_PRAGMA_OPTIONS,\n ...connectionStringPragmas,\n ...userOptions,\n };\n};\n\nexport const buildConnectionPragmaStatements = (\n pragmas: SQLitePragmaOptions,\n): Array<{ pragma: string; value: string | number }> => [\n // busy_timeout FIRST - enables waiting on locks for subsequent operations\n { pragma: 'busy_timeout', value: pragmas.busy_timeout! },\n { pragma: 'synchronous', value: pragmas.synchronous! },\n { pragma: 'cache_size', value: pragmas.cache_size! },\n { pragma: 'foreign_keys', value: pragmas.foreign_keys ? 'ON' : 'OFF' },\n { pragma: 'temp_store', value: pragmas.temp_store! },\n ...(pragmas.mmap_size !== undefined\n ? [{ pragma: 'mmap_size', value: pragmas.mmap_size }]\n : []),\n];\n\nexport const buildDatabasePragmaStatements = (\n pragmas: SQLitePragmaOptions,\n): Array<{ pragma: string; value: string | number }> => [\n { pragma: 'journal_mode', value: pragmas.journal_mode! },\n];\n","import sqlite3 from 'sqlite3';\nimport type { JSONSerializer } from '../../../../core';\nimport {\n BatchCommandNoChangesError,\n SQL,\n type Connection,\n type QueryResult,\n type QueryResultRow,\n type SQLQueryOptions,\n} from '../../../../core';\nimport type {\n SQLiteClient,\n SQLiteClientOrPoolClient,\n SQLiteConnectionOptions,\n SQLiteDriverType,\n SQLiteFileNameOrConnectionString,\n SQLiteTransaction,\n SQLiteTransactionOptions,\n} from '../../core';\nimport {\n DEFAULT_SQLITE_PRAGMA_OPTIONS,\n InMemorySQLiteDatabase,\n sqliteConnection,\n type BatchSQLiteCommandOptions,\n type SQLiteClientOptions,\n type SQLiteCommandOptions,\n type SQLiteParameters,\n} from '../../core/connections';\nimport {\n buildConnectionPragmaStatements,\n buildDatabasePragmaStatements,\n mergePragmaOptions,\n} from '../../core/connections/pragmas';\nimport { mapSqliteError } from '../../core/errors/errorMapper';\nimport { sqliteFormatter } from '../../core/sql/formatter';\n\nexport type SQLite3DriverType = SQLiteDriverType<'sqlite3'>;\nexport const SQLite3DriverType: SQLite3DriverType = 'SQLite:sqlite3';\n\nexport type ConnectionCheckResult =\n | { successful: true }\n | {\n successful: false;\n code: string | undefined;\n errorType: 'ConnectionRefused' | 'Authentication' | 'Unknown';\n error: unknown;\n };\n\nconst hasReturningClause = (sql: string): boolean => /\\bRETURNING\\b/i.test(sql);\n\nexport type SQLite3ClientOptions = SQLiteClientOptions &\n SQLiteFileNameOrConnectionString;\n\nexport type SQLite3Client = SQLiteClientOrPoolClient;\n\nexport type SQLite3ConnectionOptions = SQLiteConnectionOptions &\n ((SQLite3ClientOptions & { client?: never }) | { client: SQLite3Client });\n\nexport type SQLite3Connection<\n ClientType extends SQLiteClientOrPoolClient = SQLiteClientOrPoolClient,\n> = Connection<\n SQLite3Connection,\n SQLite3DriverType,\n ClientType,\n SQLiteTransaction<SQLite3Connection, SQLiteTransactionOptions>\n>;\n\nconst applyPragma = (\n database: sqlite3.Database,\n pragma: string,\n value: string | number,\n) => {\n return new Promise<void>((resolve, reject) => {\n database.run(`PRAGMA ${pragma} = ${value};`, (err) => {\n if (err) reject(err);\n else resolve();\n });\n });\n};\n\nconst queryPragma = (\n database: sqlite3.Database,\n pragma: string,\n): Promise<string> =>\n new Promise((resolve, reject) => {\n database.get(\n `PRAGMA ${pragma};`,\n (err: Error | null, row: { [key: string]: string } | null) => {\n if (err) reject(err);\n else resolve(row?.[pragma] ?? '');\n },\n );\n });\n\nconst applyPragmas = (\n database: sqlite3.Database,\n pragmas: Array<{ pragma: string; value: string | number }>,\n) =>\n pragmas.reduce(\n (promise, { pragma, value }) =>\n promise.then(() => applyPragma(database, pragma, value)),\n Promise.resolve(),\n );\n\nexport const sqlite3Client = (\n options: SQLite3ClientOptions & {\n serializer: JSONSerializer;\n },\n): SQLiteClient => {\n let db: sqlite3.Database;\n\n let isClosed = false;\n\n const { serializer } = options;\n\n const connectionString =\n options.fileName ?? options.connectionString ?? InMemorySQLiteDatabase;\n\n const finalPragmas = mergePragmaOptions(\n String(connectionString),\n options.pragmaOptions,\n );\n\n const connectionPragmas = buildConnectionPragmaStatements(finalPragmas);\n\n const connect: () => Promise<void> = () =>\n db\n ? Promise.resolve()\n : new Promise((resolve, reject) => {\n try {\n db = new sqlite3.Database(\n connectionString,\n sqlite3.OPEN_URI | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE,\n (err) => {\n if (err) {\n reject(err);\n return;\n }\n\n const busyTimeout =\n finalPragmas.busy_timeout ??\n DEFAULT_SQLITE_PRAGMA_OPTIONS.busy_timeout!;\n\n db.configure('busyTimeout', busyTimeout);\n\n applyPragmas(\n db,\n connectionPragmas.filter((p) => p.pragma !== 'busy_timeout'),\n )\n .then(async () => {\n if (options.skipDatabasePragmas) return;\n\n const databasePragmas =\n buildDatabasePragmaStatements(finalPragmas);\n for (const { pragma, value } of databasePragmas) {\n const current = await queryPragma(db, pragma);\n if (\n current.toUpperCase() !== String(value).toUpperCase()\n ) {\n await applyPragma(db, pragma, value);\n }\n }\n })\n .then(() => resolve())\n .catch(reject);\n },\n );\n\n // Apply connection-level pragmas first (busy_timeout is first)\n } catch (error) {\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n\n const executeQuery = <T>(\n sql: string,\n params?: SQLiteParameters[],\n ): Promise<T[]> =>\n new Promise((resolve, reject) => {\n try {\n db.all(sql, params ?? [], (err: Error | null, result: T[]) => {\n if (err) {\n reject(err);\n return;\n }\n\n resolve(result);\n });\n } catch (error) {\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n\n const executeCommand = <Result extends QueryResultRow = QueryResultRow>(\n sql: string,\n params?: SQLiteParameters[],\n options?: SQLiteCommandOptions,\n ): Promise<QueryResult<Result>> =>\n new Promise((resolve, reject) => {\n try {\n if (options?.ignoreChangesCount === true) {\n db.run(\n sql,\n params ?? [],\n function (err: Error | null, rows: Result[]) {\n if (err) {\n reject(err);\n return;\n }\n resolve({\n rowCount: 0,\n rows: rows ?? [],\n });\n },\n );\n return;\n }\n\n if (hasReturningClause(sql)) {\n db.all(sql, params ?? [], (err, rows: Result[]) => {\n if (err) return reject(err);\n resolve({ rowCount: rows.length, rows });\n });\n return;\n }\n\n // OD: 2026-01-21\n // This is needed as SQLite does not return changes count properly\n // We need to query it separately with SELECT changes()\n // This may be fixed eventually in sqlite3 library as Node.js team did here:\n // https://github.com/nodejs/node/issues/57344\n // But for now, we do it manually, as a workaround\n // We also serialize it to avoid race conditions\n db.serialize(() => {\n let hasFailed = false;\n let resultRows: Result[] = [];\n\n db.all(sql, params ?? [], (err, rows: Result[]) => {\n if (err) {\n hasFailed = true;\n return reject(err);\n }\n resultRows = rows;\n });\n\n db.get(\n 'SELECT changes() as changes',\n (err, row: { changes: number } | null) => {\n // If the first query failed, we exit immediately.\n // The promise is already rejected; we don't want to touch it.\n if (hasFailed) return;\n\n if (err) return reject(err);\n\n resolve({\n rowCount: row?.changes ?? 0,\n rows: resultRows,\n });\n },\n );\n });\n } catch (error) {\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n\n return {\n connect,\n close: async (): Promise<void> => {\n if (isClosed) {\n return;\n }\n isClosed = true;\n if (db) {\n try {\n await new Promise<void>((resolve, reject) => {\n db.close((err: Error | null) => {\n if (err) {\n reject(err);\n return;\n }\n resolve();\n });\n });\n } catch (error) {\n throw mapSqliteError(error);\n }\n }\n },\n query: async <Result extends QueryResultRow = QueryResultRow>(\n sql: SQL,\n _options?: SQLQueryOptions,\n ): Promise<QueryResult<Result>> => {\n try {\n const { query, params } = sqliteFormatter.format(sql, {\n serializer,\n });\n const result = await executeQuery<Result>(\n query,\n params as SQLiteParameters[],\n );\n return { rowCount: result.length, rows: result };\n } catch (error) {\n throw mapSqliteError(error);\n }\n },\n batchQuery: async <Result extends QueryResultRow = QueryResultRow>(\n sqls: SQL[],\n _options?: SQLQueryOptions,\n ): Promise<QueryResult<Result>[]> => {\n try {\n const results: QueryResult<Result>[] = [];\n for (const sql of sqls) {\n const { query, params } = sqliteFormatter.format(sql, {\n serializer,\n });\n const result = await executeQuery<Result>(\n query,\n params as SQLiteParameters[],\n );\n results.push({ rowCount: result.length, rows: result });\n }\n return results;\n } catch (error) {\n throw mapSqliteError(error);\n }\n },\n command: async <Result extends QueryResultRow = QueryResultRow>(\n sql: SQL,\n options?: SQLiteCommandOptions,\n ): Promise<QueryResult<Result>> => {\n try {\n const { query, params } = sqliteFormatter.format(sql, {\n serializer,\n });\n\n return await executeCommand<Result>(\n query,\n params as SQLiteParameters[],\n options,\n );\n } catch (error) {\n throw mapSqliteError(error);\n }\n },\n batchCommand: async <Result extends QueryResultRow = QueryResultRow>(\n sqls: SQL[],\n options?: BatchSQLiteCommandOptions,\n ): Promise<QueryResult<Result>[]> => {\n try {\n const results: QueryResult<Result>[] = [];\n\n for (let i = 0; i < sqls.length; i++) {\n const { query, params } = sqliteFormatter.format(sqls[i]!, {\n serializer,\n });\n const result = await executeCommand<Result>(\n query,\n params as SQLiteParameters[],\n options,\n );\n results.push(result);\n\n if (options?.assertChanges && (result.rowCount ?? 0) === 0) {\n throw new BatchCommandNoChangesError(i);\n }\n }\n return results;\n } catch (error) {\n throw mapSqliteError(error);\n }\n },\n };\n};\n\nexport const checkConnection = async (\n fileName: string,\n serializer: JSONSerializer,\n): Promise<ConnectionCheckResult> => {\n const client = sqlite3Client({\n fileName,\n serializer,\n });\n\n try {\n await client.query(SQL`SELECT 1`);\n return { successful: true };\n } catch (error) {\n const code =\n error instanceof Error &&\n 'code' in error &&\n typeof error.code === 'string'\n ? error.code\n : undefined;\n\n return {\n successful: false,\n errorType:\n code === 'SQLITE_CANTOPEN'\n ? 'ConnectionRefused'\n : code === 'SQLITE_AUTH'\n ? 'Authentication'\n : 'Unknown',\n code,\n error,\n };\n } finally {\n await client.close();\n }\n};\n\nexport const sqlite3Connection = (\n options: SQLite3ConnectionOptions & { serializer: JSONSerializer },\n) =>\n sqliteConnection<SQLite3Connection, SQLite3ConnectionOptions>({\n type: 'Client',\n driverType: SQLite3DriverType,\n sqliteClientFactory: (connectionOptions) => {\n if ('client' in connectionOptions && connectionOptions.client) {\n return connectionOptions.client;\n }\n return sqlite3Client({\n ...connectionOptions,\n serializer: options.serializer,\n });\n },\n connectionOptions: options,\n serializer: options.serializer,\n });\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport {\n createSingletonConnectionPool,\n type ConnectionPool,\n} from '../../../../core';\nimport { TaskProcessor } from '../../../../core/taskProcessing';\nimport type { AnySQLiteConnection } from '../../core';\n\nexport type SQLite3SingletonPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection,\n> = {\n driverType: SQLiteConnectionType['driverType'];\n getConnection: () => SQLiteConnectionType | Promise<SQLiteConnectionType>;\n closeConnection?: (connection: SQLiteConnectionType) => void | Promise<void>;\n maxQueueSize?: number;\n};\n\n// Creates a singleton-connection pool whose callers serialise through a\n// single-slot TaskProcessor. An AsyncLocalStorage flag lets re-entrant calls\n// (made from inside an active task on this pool) bypass the queue instead of\n// deadlocking — that's the path emmett relies on when a workflow handler\n// internally calls back through the same pool (e.g. messageStore.appendToStream).\nexport const sqlite3SingletonPool = <\n SQLiteConnectionType extends AnySQLiteConnection,\n>(\n options: SQLite3SingletonPoolOptions<SQLiteConnectionType>,\n): ConnectionPool<SQLiteConnectionType> => {\n const inner = createSingletonConnectionPool<SQLiteConnectionType>({\n driverType: options.driverType,\n getConnection: options.getConnection,\n ...(options.closeConnection\n ? { closeConnection: options.closeConnection }\n : {}),\n });\n\n const taskProcessor = new TaskProcessor({\n maxActiveTasks: 1,\n maxQueueSize: options.maxQueueSize ?? 1000,\n });\n const insideWriterTask = new AsyncLocalStorage<true>();\n\n const enqueue = <Result>(op: () => Promise<Result>): Promise<Result> => {\n if (insideWriterTask.getStore() === true) {\n return op();\n }\n return taskProcessor.enqueue(({ ack }) =>\n insideWriterTask.run(true, async () => {\n try {\n return await op();\n } finally {\n ack();\n }\n }),\n );\n };\n\n return {\n driverType: inner.driverType,\n connection: inner.connection.bind(inner),\n transaction: inner.transaction.bind(inner),\n withConnection: (handle, connectionOptions) =>\n enqueue(() => inner.withConnection(handle, connectionOptions)),\n withTransaction: (handle, transactionOptions) =>\n enqueue(() => inner.withTransaction(handle, transactionOptions)),\n execute: {\n query: (sql, queryOptions) =>\n enqueue(() => inner.execute.query(sql, queryOptions)),\n batchQuery: (sqls, queryOptions) =>\n enqueue(() => inner.execute.batchQuery(sqls, queryOptions)),\n command: (sql, commandOptions) =>\n enqueue(() => inner.execute.command(sql, commandOptions)),\n batchCommand: (sqls, commandOptions) =>\n enqueue(() => inner.execute.batchCommand(sqls, commandOptions)),\n },\n close: async () => {\n await taskProcessor.stop();\n await inner.close();\n },\n };\n};\n","import { cpus } from 'os';\nimport { createBoundedConnectionPool } from '../../../../core';\nimport { guardInitializedOnce } from '../../../../core/taskProcessing';\nimport type {\n AnySQLiteConnection,\n SQLiteConnectionFactory,\n SQLiteConnectionOptions,\n SQLitePool,\n} from '../../core';\nimport { mapSqliteError } from '../../core/errors';\nimport { sqlite3SingletonPool } from './singletonPool';\n\nexport type SQLiteDualPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions,\n> = {\n driverType: SQLiteConnectionType['driverType'];\n dual?: true;\n singleton?: false;\n pooled?: true;\n connection?: never;\n readerPoolSize?: number;\n sqliteConnectionFactory: SQLiteConnectionFactory<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n connectionOptions?: ConnectionOptions;\n};\n\nexport const sqliteDualConnectionPool = <\n SQLiteConnectionType extends AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions,\n>(\n options: SQLiteDualPoolOptions<SQLiteConnectionType, ConnectionOptions>,\n): SQLitePool<SQLiteConnectionType> => {\n const { sqliteConnectionFactory, connectionOptions } = options;\n const readerPoolSize = options.readerPoolSize ?? Math.max(4, cpus().length);\n\n let databaseInitPromise: Promise<void> | null = null;\n\n const guardSingleConnection = guardInitializedOnce(async () => {\n if (databaseInitPromise !== null) {\n return databaseInitPromise;\n }\n\n const initConnection = sqliteConnectionFactory({\n ...connectionOptions,\n skipDatabasePragmas: false,\n readonly: false,\n } as ConnectionOptions);\n\n const initPromise = initConnection.open();\n databaseInitPromise = initPromise;\n\n try {\n await initPromise;\n await initConnection.close();\n } catch (error) {\n databaseInitPromise = null;\n await initConnection.close();\n throw mapSqliteError(error);\n }\n });\n\n const ensureDatabaseInitialized = async (): Promise<void> => {\n if (databaseInitPromise !== null) {\n return databaseInitPromise;\n }\n\n return guardSingleConnection.ensureInitialized();\n };\n\n const wrappedConnectionFactory = async (\n readonly: boolean,\n connectionOptions: ConnectionOptions | undefined,\n ): Promise<SQLiteConnectionType> => {\n await ensureDatabaseInitialized();\n\n const connection = sqliteConnectionFactory({\n ...connectionOptions,\n skipDatabasePragmas: true,\n readonly,\n } as ConnectionOptions);\n\n await connection.open();\n\n return connection;\n };\n\n const writerPool = sqlite3SingletonPool<SQLiteConnectionType>({\n driverType: options.driverType,\n getConnection: () => wrappedConnectionFactory(false, connectionOptions),\n });\n\n const readerPool = createBoundedConnectionPool({\n driverType: options.driverType,\n getConnection: () => wrappedConnectionFactory(true, connectionOptions),\n maxConnections: readerPoolSize,\n });\n\n return {\n driverType: options.driverType,\n connection: (connectionOptions) =>\n connectionOptions?.readonly\n ? readerPool.connection(connectionOptions)\n : writerPool.connection(connectionOptions),\n execute: {\n query: (...args) => readerPool.execute.query(...args),\n batchQuery: (...args) => readerPool.execute.batchQuery(...args),\n command: (...args) => writerPool.execute.command(...args),\n batchCommand: (...args) => writerPool.execute.batchCommand(...args),\n },\n withConnection: (handle, connectionOptions) =>\n connectionOptions?.readonly\n ? readerPool.withConnection(handle, connectionOptions)\n : writerPool.withConnection(handle, connectionOptions),\n transaction: writerPool.transaction,\n withTransaction: writerPool.withTransaction,\n close: async () => {\n await guardSingleConnection.stop();\n await Promise.all([writerPool.close(), readerPool.close()]);\n },\n };\n};\n","export * from './connections';\nimport {\n canHandleDriverWithConnectionString,\n dumboDatabaseDriverRegistry,\n JSONSerializer,\n type DumboConnectionOptions,\n type DumboDatabaseDriver,\n} from '../../../core';\nimport {\n DefaultSQLiteMigratorOptions,\n isInMemoryDatabase,\n SQLiteConnectionString,\n sqliteFormatter,\n sqliteMetadata,\n sqlitePool,\n toSqlitePoolOptions,\n type SQLitePool,\n type SQLitePoolOptions,\n} from '../core';\nimport {\n sqlite3Connection,\n SQLite3DriverType,\n type SQLite3Connection,\n type SQLite3ConnectionOptions,\n} from './connections';\nimport { sqliteDualConnectionPool } from './pool/dualPool';\nimport { sqlite3SingletonPool } from './pool/singletonPool';\n\nexport type SQLite3DumboOptions = Omit<\n SQLitePoolOptions<SQLite3Connection, SQLite3ConnectionOptions>,\n 'driverType'\n> &\n SQLite3ConnectionOptions & { serializer?: JSONSerializer };\n\nexport type SQLite3PoolOptions = SQLite3DumboOptions;\n\nexport type Sqlite3Pool = SQLitePool<SQLite3Connection>;\n\nexport const sqlite3Pool = (\n options: SQLite3DumboOptions,\n): SQLitePool<SQLite3Connection> => {\n // Ambient: caller-managed connection. No acquisition, no serialisation.\n if ('connection' in options && options.connection) {\n return sqlitePool(\n toSqlitePoolOptions({\n ...options,\n driverType: SQLite3DriverType,\n }),\n );\n }\n\n const sqliteConnectionFactory = (opts: SQLite3ConnectionOptions) =>\n sqlite3Connection({\n ...opts,\n serializer: options.serializer ?? JSONSerializer,\n });\n\n // Singleton-shaped: in-memory DBs, an explicit client, or `singleton: true`.\n // One connection shared across callers — wrap it so concurrent callers\n // serialise through a single-slot TaskProcessor with ALS-based reentrancy.\n const isSingleton =\n isInMemoryDatabase(options) ||\n ('client' in options && Boolean(options.client)) ||\n options.singleton === true;\n\n if (isSingleton) {\n return sqlite3SingletonPool<SQLite3Connection>({\n driverType: SQLite3DriverType,\n getConnection: () => sqliteConnectionFactory(options),\n });\n }\n\n // Default: file-backed dual pool. Its writer side is serialised inside\n // sqliteDualConnectionPool via the same primitive.\n const readerPoolSize = (options as { readerPoolSize?: number })\n .readerPoolSize;\n return sqliteDualConnectionPool({\n driverType: SQLite3DriverType,\n sqliteConnectionFactory,\n connectionOptions: options,\n ...(readerPoolSize !== undefined ? { readerPoolSize } : {}),\n });\n};\n\nconst tryParseConnectionString = (connectionString: string) => {\n try {\n return SQLiteConnectionString(connectionString);\n } catch {\n return null;\n }\n};\n\nexport const sqlite3DumboDriver = {\n driverType: SQLite3DriverType,\n createPool: (options) => sqlite3Pool(options as SQLite3DumboOptions),\n sqlFormatter: sqliteFormatter,\n defaultMigratorOptions: DefaultSQLiteMigratorOptions,\n canHandle: canHandleDriverWithConnectionString(\n SQLite3DriverType,\n tryParseConnectionString,\n ),\n databaseMetadata: sqliteMetadata,\n} satisfies DumboDatabaseDriver<\n SQLite3Connection,\n SQLite3DumboOptions,\n Sqlite3Pool\n>;\n\nexport const useSqlite3DumboDriver = () => {\n dumboDatabaseDriverRegistry.register(SQLite3DriverType, sqlite3DumboDriver);\n};\n\nexport type SQLite3DumboConnectionOptions = DumboConnectionOptions<\n typeof sqlite3DumboDriver\n> & { connectionString: string | SQLiteConnectionString };\n\nuseSqlite3DumboDriver();\n\nexport * from './connections';\nexport * from './formatter';\nexport * from './transactions';\n"],"mappings":";;;;;;;;AAMA,MAAa,sBACX,kBACA,gBACwB;CACxB,MAAM,0BACJ,iCAAiC,iBAAiB;AAEpD,QAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACJ;;AAGH,MAAa,mCACX,YACsD;CAEtD;EAAE,QAAQ;EAAgB,OAAO,QAAQ;EAAe;CACxD;EAAE,QAAQ;EAAe,OAAO,QAAQ;EAAc;CACtD;EAAE,QAAQ;EAAc,OAAO,QAAQ;EAAa;CACpD;EAAE,QAAQ;EAAgB,OAAO,QAAQ,eAAe,OAAO;EAAO;CACtE;EAAE,QAAQ;EAAc,OAAO,QAAQ;EAAa;CACpD,GAAI,QAAQ,cAAc,SACtB,CAAC;EAAE,QAAQ;EAAa,OAAO,QAAQ;EAAW,CAAC,GACnD,EAAE;CACP;AAED,MAAa,iCACX,YACsD,CACtD;CAAE,QAAQ;CAAgB,OAAO,QAAQ;CAAe,CACzD;;;;ACDD,MAAa,oBAAuC;AAWpD,MAAM,sBAAsB,QAAyB,iBAAiB,KAAK,IAAI;AAmB/E,MAAM,eACJ,UACA,QACA,UACG;AACH,QAAO,IAAI,SAAe,SAAS,WAAW;AAC5C,WAAS,IAAI,UAAU,OAAO,KAAK,MAAM,KAAK,QAAQ;AACpD,OA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,KAJE,mBAAmB,QAAQ,IAC1B,YAAY,WAAW,QAAQ,QAAQ,OAAO,IAC/C,QAAQ,cAAc,KAGtB,QAAO,qBAAwC;EAC7C,YAAY;EACZ,qBAAqB,wBAAwB,QAAQ;EACtD,CAAC;CAKJ,MAAM,iBAAkB,QACrB;AACH,QAAO,yBAAyB;EAC9B,YAAY;EACZ;EACA,mBAAmB;EACnB,GAAI,mBAAmB,SAAY,EAAE,gBAAgB,GAAG,EAAE;EAC3D,CAAC;;AAGJ,MAAM,4BAA4B,qBAA6B;AAC7D,KAAI;AACF,SAAO,uBAAuB,iBAAiB;SACzC;AACN,SAAO;;;AAIX,MAAa,qBAAqB;CAChC,YAAY;CACZ,aAAa,YAAY,YAAY,QAA+B;CACpE,cAAc;CACd,wBAAwB;CACxB,WAAW,oCACT,mBACA,yBACD;CACD,kBAAkB;CACnB;AAMD,MAAa,8BAA8B;AACzC,6BAA4B,SAAS,mBAAmB,mBAAmB;;AAO7E,uBAAuB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ln as exists, xt as SQL } from "./core-BG__WVn6.js";
|
|
2
2
|
|
|
3
3
|
//#region src/storage/sqlite/core/schema/schema.ts
|
|
4
4
|
const defaultSQLiteDatabase = ":memory:";
|
|
@@ -26,4 +26,4 @@ dumboDatabaseMetadataRegistry.register("SQLite", sqliteMetadata);
|
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
28
|
export { defaultSQLiteDatabase as n, tableExists as r, sqliteMetadata as t };
|
|
29
|
-
//# sourceMappingURL=sqliteMetadata-
|
|
29
|
+
//# sourceMappingURL=sqliteMetadata-7qBjsMBN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqliteMetadata-
|
|
1
|
+
{"version":3,"file":"sqliteMetadata-7qBjsMBN.js","names":[],"sources":["../src/storage/sqlite/core/schema/schema.ts","../src/storage/sqlite/core/schema/sqliteMetadata.ts"],"sourcesContent":["import { exists, SQL, type SQLExecutor } from '../../../../core';\nexport * from './schema';\n\nexport const defaultSQLiteDatabase = ':memory:';\n\nconst tableExistsSQL = (tableName: string): SQL =>\n SQL`\n SELECT EXISTS (\n SELECT 1\n FROM sqlite_master\n WHERE type = 'table' AND name = ${tableName}\n ) AS \"exists\"\n `;\n\nexport const tableExists = async (\n execute: SQLExecutor,\n tableName: string,\n): Promise<boolean> => exists(execute.query(tableExistsSQL(tableName)));\n","import type { DatabaseMetadata } from '../../../../core';\nimport { tableExists } from './schema';\n\nexport const sqliteMetadata: DatabaseMetadata<false, false, false> = {\n databaseType: 'SQLite',\n capabilities: {\n supportsSchemas: false,\n supportsFunctions: false,\n supportsMultipleDatabases: false,\n },\n tableExists,\n};\n\ndumboDatabaseMetadataRegistry.register('SQLite', sqliteMetadata);\n"],"mappings":";;;AAGA,MAAa,wBAAwB;AAErC,MAAM,kBAAkB,cACtB,GAAG;;;;sCAIiC,UAAU;;;AAIhD,MAAa,cAAc,OACzB,SACA,cACqB,OAAO,QAAQ,MAAM,eAAe,UAAU,CAAC,CAAC;;;;ACdvE,MAAa,iBAAwD;CACnE,cAAc;CACd,cAAc;EACZ,iBAAiB;EACjB,mBAAmB;EACnB,2BAA2B;EAC5B;CACD;CACD;AAED,8BAA8B,SAAS,UAAU,eAAe"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_core = require('./core-
|
|
1
|
+
const require_core = require('./core-D-smW7cm.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/storage/sqlite/core/schema/schema.ts
|
|
4
4
|
const defaultSQLiteDatabase = ":memory:";
|
|
@@ -43,4 +43,4 @@ Object.defineProperty(exports, 'tableExists', {
|
|
|
43
43
|
return tableExists;
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
//# sourceMappingURL=sqliteMetadata-
|
|
46
|
+
//# sourceMappingURL=sqliteMetadata-PJTRPIZ1.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqliteMetadata-
|
|
1
|
+
{"version":3,"file":"sqliteMetadata-PJTRPIZ1.cjs","names":["exists"],"sources":["../src/storage/sqlite/core/schema/schema.ts","../src/storage/sqlite/core/schema/sqliteMetadata.ts"],"sourcesContent":["import { exists, SQL, type SQLExecutor } from '../../../../core';\nexport * from './schema';\n\nexport const defaultSQLiteDatabase = ':memory:';\n\nconst tableExistsSQL = (tableName: string): SQL =>\n SQL`\n SELECT EXISTS (\n SELECT 1\n FROM sqlite_master\n WHERE type = 'table' AND name = ${tableName}\n ) AS \"exists\"\n `;\n\nexport const tableExists = async (\n execute: SQLExecutor,\n tableName: string,\n): Promise<boolean> => exists(execute.query(tableExistsSQL(tableName)));\n","import type { DatabaseMetadata } from '../../../../core';\nimport { tableExists } from './schema';\n\nexport const sqliteMetadata: DatabaseMetadata<false, false, false> = {\n databaseType: 'SQLite',\n capabilities: {\n supportsSchemas: false,\n supportsFunctions: false,\n supportsMultipleDatabases: false,\n },\n tableExists,\n};\n\ndumboDatabaseMetadataRegistry.register('SQLite', sqliteMetadata);\n"],"mappings":";;;AAGA,MAAa,wBAAwB;AAErC,MAAM,kBAAkB,cACtB,gBAAG;;;;sCAIiC,UAAU;;;AAIhD,MAAa,cAAc,OACzB,SACA,cACqBA,oBAAO,QAAQ,MAAM,eAAe,UAAU,CAAC,CAAC;;;;ACdvE,MAAa,iBAAwD;CACnE,cAAc;CACd,cAAc;EACZ,iBAAiB;EACjB,mBAAmB;EACnB,2BAA2B;EAC5B;CACD;CACD;AAED,8BAA8B,SAAS,UAAU,eAAe"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core-BeyC5tHn.js","names":[],"sources":["../src/storage/sqlite/core/errors/errorMapper.ts","../src/storage/sqlite/core/sql/processors/columProcessors.ts","../src/storage/sqlite/core/sql/formatter/index.ts","../src/storage/sqlite/core/execute/execute.ts","../src/storage/sqlite/core/transactions/index.ts","../src/storage/sqlite/core/connections/connectionString.ts","../src/storage/sqlite/core/connections/index.ts","../src/storage/sqlite/core/pool/dualPool.ts","../src/storage/sqlite/core/pool/pool.ts","../src/storage/sqlite/core/schema/migrations.ts","../src/storage/sqlite/core/index.ts"],"sourcesContent":["import {\n CheckViolationError,\n ConnectionError,\n DataError,\n DeadlockError,\n DumboError,\n ForeignKeyViolationError,\n InsufficientResourcesError,\n IntegrityConstraintViolationError,\n InvalidOperationError,\n LockNotAvailableError,\n NotNullViolationError,\n SerializationError,\n SystemError,\n UniqueConstraintError,\n} from '../../../../core/errors';\n\n/**\n * Extracts the SQLite error code string from a `sqlite3` driver error.\n *\n * The `sqlite3` (node-sqlite3) driver sets `error.code` to a string like\n * `'SQLITE_CONSTRAINT'` and `error.errno` to the numeric result code.\n * See: https://github.com/TryGhost/node-sqlite3\n */\nconst getSqliteErrorCode = (error: unknown): string | undefined => {\n if (\n error instanceof Error &&\n 'code' in error &&\n typeof (error as Record<string, unknown>).code === 'string'\n ) {\n return (error as Record<string, unknown>).code as string;\n }\n return undefined;\n};\n\nconst getErrorMessage = (error: unknown): string | undefined =>\n error instanceof Error ? error.message : undefined;\n\nconst asError = (error: unknown): Error | undefined =>\n error instanceof Error ? error : undefined;\n\n/**\n * Maps a constraint error to a specific DumboError subtype by inspecting the\n * error message. The `sqlite3` driver only exposes the primary result code\n * `SQLITE_CONSTRAINT` — the constraint subtype (UNIQUE, FOREIGN KEY, etc.)\n * is embedded in the message string by SQLite, e.g.:\n * \"SQLITE_CONSTRAINT: UNIQUE constraint failed: users.email\"\n *\n * Reference: https://www.sqlite.org/rescode.html (extended result codes 275–3091)\n */\nconst mapConstraintError = (\n message: string | undefined,\n innerError: Error | undefined,\n): DumboError => {\n const upperMessage = message?.toUpperCase() ?? '';\n\n // SQLITE_CONSTRAINT_UNIQUE (2067) / SQLITE_CONSTRAINT_PRIMARYKEY (1555)\n if (upperMessage.includes('UNIQUE') || upperMessage.includes('PRIMARY KEY'))\n return new UniqueConstraintError(message, innerError);\n\n // SQLITE_CONSTRAINT_FOREIGNKEY (787)\n if (upperMessage.includes('FOREIGN KEY'))\n return new ForeignKeyViolationError(message, innerError);\n\n // SQLITE_CONSTRAINT_NOTNULL (1299)\n if (upperMessage.includes('NOT NULL'))\n return new NotNullViolationError(message, innerError);\n\n // SQLITE_CONSTRAINT_CHECK (275)\n if (upperMessage.includes('CHECK'))\n return new CheckViolationError(message, innerError);\n\n // SQLITE_CONSTRAINT_ROWID (2579), SQLITE_CONSTRAINT_TRIGGER (1811),\n // SQLITE_CONSTRAINT_COMMITHOOK (531), SQLITE_CONSTRAINT_PINNED (2835),\n // SQLITE_CONSTRAINT_DATATYPE (3091), etc.\n return new IntegrityConstraintViolationError(message, innerError);\n};\n\n/**\n * Maps a SQLite error (from the `sqlite3` / node-sqlite3 driver) to a typed\n * DumboError based on the SQLite result code.\n *\n * Result code reference: https://www.sqlite.org/rescode.html\n *\n * Falls back to a generic DumboError (500) if the error is not a recognized SQLite error.\n */\nexport const mapSqliteError = (error: unknown): DumboError => {\n if (DumboError.isInstanceOf<DumboError>(error)) return error;\n\n const code = getSqliteErrorCode(error);\n if (!code)\n return new DumboError({\n errorCode: 500,\n message: getErrorMessage(error),\n innerError: asError(error),\n });\n\n const message = getErrorMessage(error);\n const innerError = asError(error);\n\n switch (code) {\n // ── Constraint violations (19) ──\n // node-sqlite3 only exposes the primary code; subtype is in the message.\n case 'SQLITE_CONSTRAINT':\n return mapConstraintError(message, innerError);\n\n // ── Busy / lock contention ──\n // SQLITE_BUSY (5): conflict with a separate database connection\n case 'SQLITE_BUSY':\n return new LockNotAvailableError(message, innerError);\n\n // SQLITE_LOCKED (6): conflict within the same connection or shared cache\n case 'SQLITE_LOCKED':\n return new DeadlockError(message, innerError);\n\n // SQLITE_PROTOCOL (15): WAL locking race condition\n case 'SQLITE_PROTOCOL':\n return new LockNotAvailableError(message, innerError);\n\n // ── Connection / open errors ──\n // SQLITE_CANTOPEN (14): unable to open database file\n case 'SQLITE_CANTOPEN':\n return new ConnectionError(message, innerError);\n\n // SQLITE_NOTADB (26): file is not a database\n case 'SQLITE_NOTADB':\n return new ConnectionError(message, innerError);\n\n // ── Resource exhaustion ──\n // SQLITE_NOMEM (7): out of memory\n case 'SQLITE_NOMEM':\n return new InsufficientResourcesError(message, innerError);\n\n // SQLITE_FULL (13): disk full\n case 'SQLITE_FULL':\n return new InsufficientResourcesError(message, innerError);\n\n // ── System / I/O errors ──\n // SQLITE_IOERR (10): operating system I/O error\n case 'SQLITE_IOERR':\n return new SystemError(message, innerError);\n\n // SQLITE_CORRUPT (11): database file is corrupted\n case 'SQLITE_CORRUPT':\n return new SystemError(message, innerError);\n\n // SQLITE_INTERNAL (2): internal SQLite malfunction\n case 'SQLITE_INTERNAL':\n return new SystemError(message, innerError);\n\n // SQLITE_NOLFS (22): large file support unavailable\n case 'SQLITE_NOLFS':\n return new SystemError(message, innerError);\n\n // ── Data errors ──\n // SQLITE_TOOBIG (18): string or BLOB too large\n case 'SQLITE_TOOBIG':\n return new DataError(message, innerError);\n\n // SQLITE_MISMATCH (20): datatype mismatch\n case 'SQLITE_MISMATCH':\n return new DataError(message, innerError);\n\n // SQLITE_RANGE (25): bind parameter index out of range\n case 'SQLITE_RANGE':\n return new DataError(message, innerError);\n\n // ── Invalid operations ──\n // SQLITE_ERROR (1): generic SQL error (syntax errors, missing tables, etc.)\n case 'SQLITE_ERROR':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_READONLY (8): attempt to write to a read-only database\n case 'SQLITE_READONLY':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_MISUSE (21): API misuse\n case 'SQLITE_MISUSE':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_AUTH (23): authorization denied\n case 'SQLITE_AUTH':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_PERM (3): access permission denied\n case 'SQLITE_PERM':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_SCHEMA (17): schema changed, statement needs re-preparation\n case 'SQLITE_SCHEMA':\n return new InvalidOperationError(message, innerError);\n\n // ── Transaction / abort ──\n // SQLITE_ABORT (4): operation aborted (e.g. by rollback)\n case 'SQLITE_ABORT':\n return new SerializationError(message, innerError);\n\n // SQLITE_INTERRUPT (9): operation interrupted\n case 'SQLITE_INTERRUPT':\n return new SerializationError(message, innerError);\n }\n\n return new DumboError({\n errorCode: 500,\n message,\n innerError,\n });\n};\n","import {\n mapDefaultSQLColumnProcessors,\n type DefaultSQLColumnProcessors,\n type DefaultSQLColumnToken,\n type SQLProcessorContext,\n} from '../../../../../core';\n\nconst mapColumnType = (\n token: DefaultSQLColumnToken,\n { builder }: SQLProcessorContext,\n): void => {\n let columnSQL: string;\n const { sqlTokenType } = token;\n switch (sqlTokenType) {\n case 'SQL_COLUMN_AUTO_INCREMENT':\n columnSQL = `INTEGER ${token.primaryKey ? 'PRIMARY KEY' : ''} AUTOINCREMENT`;\n break;\n case 'SQL_COLUMN_BIGINT':\n columnSQL = 'INTEGER';\n break;\n case 'SQL_COLUMN_SERIAL':\n columnSQL = 'INTEGER';\n break;\n case 'SQL_COLUMN_INTEGER':\n columnSQL = 'INTEGER';\n break;\n case 'SQL_COLUMN_JSONB':\n columnSQL = 'BLOB';\n break;\n case 'SQL_COLUMN_BIGSERIAL':\n columnSQL = 'INTEGER';\n break;\n case 'SQL_COLUMN_TIMESTAMP':\n columnSQL = 'DATETIME';\n break;\n case 'SQL_COLUMN_TIMESTAMPTZ':\n columnSQL = 'DATETIME';\n break;\n case 'SQL_COLUMN_VARCHAR':\n columnSQL = `VARCHAR ${Number.isNaN(token.length) ? '' : `(${token.length})`}`;\n break;\n default: {\n const exhaustiveCheck: never = sqlTokenType;\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Unknown column type: ${exhaustiveCheck}`);\n }\n }\n builder.addSQL(columnSQL);\n};\n\nexport const sqliteColumnProcessors: DefaultSQLColumnProcessors =\n mapDefaultSQLColumnProcessors(mapColumnType);\n","import {\n defaultProcessorsRegistry,\n registerFormatter,\n SQLFormatter,\n SQLProcessorsRegistry,\n} from '../../../../../core/sql';\nimport { sqliteColumnProcessors } from '../processors';\n\nconst sqliteSQLProcessorsRegistry = SQLProcessorsRegistry({\n from: defaultProcessorsRegistry,\n}).register(sqliteColumnProcessors);\n\nconst sqliteFormatter: SQLFormatter = SQLFormatter({\n processorsRegistry: sqliteSQLProcessorsRegistry,\n});\n\nregisterFormatter('SQLite', sqliteFormatter);\n\nexport { sqliteFormatter };\n","import type { SQLiteDriverType } from '..';\nimport type { JSONSerializer, SQLFormatter, SQL } from '../../../../core';\nimport {\n mapSQLQueryResult,\n tracer,\n type BatchSQLCommandOptions,\n type DbSQLExecutor,\n type QueryResult,\n type QueryResultRow,\n type SQLCommandOptions,\n type SQLQueryOptions,\n} from '../../../../core';\nimport type { DumboError } from '../../../../core/errors';\nimport type { SQLiteClient } from '../connections';\nimport { mapSqliteError } from '../errors/errorMapper';\nimport { sqliteFormatter } from '../sql/formatter';\n\nexport type SQLiteErrorMapper = (error: unknown) => DumboError;\n\nexport const sqliteExecute = async <Result = void>(\n database: SQLiteClient,\n handle: (client: SQLiteClient) => Promise<Result>,\n) => {\n try {\n return await handle(database);\n } finally {\n await database.close();\n }\n};\n\nexport type SQLiteSQLExecutor<\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n> = DbSQLExecutor<DriverType, SQLiteClient>;\n\nexport const sqliteSQLExecutor = <\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n>(\n driverType: DriverType,\n serializer: JSONSerializer,\n formatter?: SQLFormatter,\n errorMapper?: SQLiteErrorMapper,\n): SQLiteSQLExecutor<DriverType> => ({\n driverType,\n query: async <Result extends QueryResultRow = QueryResultRow>(\n client: SQLiteClient,\n sql: SQL,\n options?: SQLQueryOptions,\n ): Promise<QueryResult<Result>> => {\n tracer.info('db:sql:query', {\n query: (formatter ?? sqliteFormatter).format(sql, { serializer }).query,\n params: (formatter ?? sqliteFormatter).format(sql, { serializer }).params,\n debugSQL: (formatter ?? sqliteFormatter).describe(sql, { serializer }),\n });\n\n try {\n let result = await client.query<Result>(sql, options);\n\n if (options?.mapping) {\n result = {\n ...result,\n rows: result.rows.map((row) =>\n mapSQLQueryResult(row, options.mapping!),\n ),\n };\n }\n\n return result;\n } catch (error) {\n tracer.error('db:sql:query:execute:error', { error });\n throw (errorMapper ?? mapSqliteError)(error);\n }\n },\n batchQuery: async <Result extends QueryResultRow = QueryResultRow>(\n client: SQLiteClient,\n sqls: SQL[],\n options?: SQLQueryOptions,\n ): Promise<QueryResult<Result>[]> => {\n try {\n const results = await client.batchQuery<Result>(sqls, options);\n\n if (options?.mapping) {\n return results.map((result) => ({\n ...result,\n rows: result.rows.map((row) =>\n mapSQLQueryResult(row, options.mapping!),\n ),\n }));\n }\n\n return results;\n } catch (error) {\n tracer.error('db:sql:batch_query:execute:error', { error });\n throw (errorMapper ?? mapSqliteError)(error);\n }\n },\n command: async <Result extends QueryResultRow = QueryResultRow>(\n client: SQLiteClient,\n sql: SQL,\n options?: SQLCommandOptions,\n ): Promise<QueryResult<Result>> => {\n tracer.info('db:sql:command', {\n query: (formatter ?? sqliteFormatter).format(sql, { serializer }).query,\n params: (formatter ?? sqliteFormatter).format(sql, { serializer }).params,\n debugSQL: (formatter ?? sqliteFormatter).describe(sql, { serializer }),\n });\n\n try {\n return await client.command<Result>(sql, options);\n } catch (error) {\n tracer.error('db:sql:command:execute:error', { error });\n throw (errorMapper ?? mapSqliteError)(error);\n }\n },\n batchCommand: async <Result extends QueryResultRow = QueryResultRow>(\n client: SQLiteClient,\n sqls: SQL[],\n options?: BatchSQLCommandOptions,\n ): Promise<QueryResult<Result>[]> => {\n try {\n return await client.batchCommand<Result>(sqls, options);\n } catch (error) {\n tracer.error('db:sql:batch_command:execute:error', { error });\n throw (errorMapper ?? mapSqliteError)(error);\n }\n },\n formatter: formatter ?? sqliteFormatter,\n});\n","import type {\n InferTransactionFromConnection,\n JSONSerializer,\n} from '../../../../core';\nimport {\n SQL,\n sqlExecutor,\n type DatabaseTransaction,\n type DatabaseTransactionOptions,\n type InferDbClientFromConnection,\n} from '../../../../core';\nimport { sqliteSQLExecutor } from '../../core/execute';\nimport {\n transactionNestingCounter,\n type AnySQLiteConnection,\n type SQLiteClientOrPoolClient,\n} from '../connections';\n\nexport type SQLiteTransaction<\n ConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n TransactionOptions extends SQLiteTransactionOptions =\n SQLiteTransactionOptions,\n> = DatabaseTransaction<ConnectionType, TransactionOptions>;\n\nexport type SQLiteTransactionMode = 'DEFERRED' | 'IMMEDIATE' | 'EXCLUSIVE';\n\nexport type SQLiteTransactionOptions = DatabaseTransactionOptions & {\n mode?: SQLiteTransactionMode;\n useSavepoints?: boolean;\n};\n\nexport const sqliteTransaction =\n <ConnectionType extends AnySQLiteConnection = AnySQLiteConnection>(\n driverType: ConnectionType['driverType'],\n connection: () => ConnectionType,\n allowNestedTransactions: boolean,\n serializer: JSONSerializer,\n defaultTransactionMode?: 'IMMEDIATE' | 'DEFERRED' | 'EXCLUSIVE',\n ) =>\n (\n getClient: Promise<InferDbClientFromConnection<ConnectionType>>,\n options?: {\n close: (\n client: InferDbClientFromConnection<ConnectionType>,\n error?: unknown,\n ) => Promise<void>;\n } & SQLiteTransactionOptions,\n ): InferTransactionFromConnection<ConnectionType> => {\n const transactionCounter = transactionNestingCounter();\n allowNestedTransactions =\n options?.allowNestedTransactions ?? allowNestedTransactions;\n\n const transaction: DatabaseTransaction<ConnectionType> = {\n connection: connection(),\n driverType,\n begin: async function () {\n const client = (await getClient) as SQLiteClientOrPoolClient;\n\n if (allowNestedTransactions) {\n if (transactionCounter.level >= 1) {\n transactionCounter.increment();\n if (options?.useSavepoints) {\n await client.command(\n SQL`SAVEPOINT transaction${SQL.plain(transactionCounter.level.toString())}`,\n );\n }\n return;\n }\n\n transactionCounter.increment();\n }\n\n const mode = options?.mode ?? defaultTransactionMode ?? 'IMMEDIATE';\n await client.command(SQL`BEGIN ${SQL.plain(mode)} TRANSACTION`);\n },\n commit: async function () {\n const client = (await getClient) as SQLiteClientOrPoolClient;\n\n try {\n if (allowNestedTransactions) {\n if (transactionCounter.level > 1) {\n if (options?.useSavepoints) {\n await client.command(\n SQL`RELEASE transaction${SQL.plain(transactionCounter.level.toString())}`,\n );\n }\n transactionCounter.decrement();\n\n return;\n }\n\n transactionCounter.reset();\n }\n await client.command(SQL`COMMIT`);\n } finally {\n if (options?.close)\n await options?.close(\n client as InferDbClientFromConnection<ConnectionType>,\n );\n }\n },\n rollback: async function (error?: unknown) {\n const client = (await getClient) as SQLiteClientOrPoolClient;\n try {\n if (allowNestedTransactions) {\n if (transactionCounter.level > 1) {\n transactionCounter.decrement();\n return;\n }\n }\n\n await client.command(SQL`ROLLBACK`);\n } finally {\n if (options?.close)\n await options?.close(\n client as InferDbClientFromConnection<ConnectionType>,\n error,\n );\n }\n },\n execute: sqlExecutor(sqliteSQLExecutor(driverType, serializer), {\n connect: () => getClient,\n }),\n _transactionOptions: options ?? {},\n };\n\n return transaction as InferTransactionFromConnection<ConnectionType>;\n };\n","import type { DatabaseConnectionString } from '../../../all';\n\nexport type SQLitePragmaOptions = {\n journal_mode?: 'DELETE' | 'TRUNCATE' | 'PERSIST' | 'MEMORY' | 'WAL' | 'OFF';\n synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA';\n cache_size?: number;\n foreign_keys?: boolean;\n temp_store?: 'DEFAULT' | 'FILE' | 'MEMORY';\n busy_timeout?: number;\n mmap_size?: number;\n};\n\nexport type SQLiteConnectionString = DatabaseConnectionString<\n 'SQLite',\n `file:${string}` | `:memory:` | `/${string}` | `./${string}`\n>;\n\nexport const SQLiteConnectionString = (\n connectionString: string,\n): SQLiteConnectionString => {\n if (\n !connectionString.startsWith('file:') &&\n connectionString !== ':memory:' &&\n !connectionString.startsWith('/') &&\n !connectionString.startsWith('./')\n ) {\n throw new Error(\n `Invalid SQLite connection string: ${connectionString}. It should start with \"file:\", \":memory:\", \"/\", or \"./\".`,\n );\n }\n return connectionString as SQLiteConnectionString;\n};\n\nexport const parsePragmasFromConnectionString = (\n connectionString: string | SQLiteConnectionString,\n): Partial<SQLitePragmaOptions> => {\n const str = String(connectionString);\n\n if (!str.startsWith('file:')) {\n return {};\n }\n\n const url = new URL(str);\n const params = url.searchParams;\n const pragmas: Partial<SQLitePragmaOptions> = {};\n\n const journalMode = params.get('journal_mode');\n if (journalMode !== null) {\n pragmas.journal_mode = journalMode as\n | 'DELETE'\n | 'TRUNCATE'\n | 'PERSIST'\n | 'MEMORY'\n | 'WAL'\n | 'OFF';\n }\n\n const synchronous = params.get('synchronous');\n if (synchronous !== null) {\n pragmas.synchronous = synchronous as 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA';\n }\n\n const cacheSize = params.get('cache_size');\n if (cacheSize !== null) {\n pragmas.cache_size = parseInt(cacheSize, 10);\n }\n\n const foreignKeys = params.get('foreign_keys');\n if (foreignKeys !== null) {\n const val = foreignKeys.toLowerCase();\n pragmas.foreign_keys = val === 'true' || val === 'on' || val === '1';\n }\n\n const tempStore = params.get('temp_store');\n if (tempStore !== null) {\n pragmas.temp_store = tempStore.toUpperCase() as\n | 'DEFAULT'\n | 'FILE'\n | 'MEMORY';\n }\n\n const busyTimeout = params.get('busy_timeout');\n if (busyTimeout !== null) {\n pragmas.busy_timeout = parseInt(busyTimeout, 10);\n }\n\n const mmapSize = params.get('mmap_size');\n if (mmapSize !== null) {\n pragmas.mmap_size = parseInt(mmapSize, 10);\n }\n\n return pragmas;\n};\n","import type { SQLiteDriverType } from '..';\nimport type { JSONSerializer } from '../../../../core';\nimport {\n createAmbientConnection,\n createConnection,\n type AnyConnection,\n type BatchSQLCommandOptions,\n type Connection,\n type ConnectionOptions,\n type DatabaseTransaction,\n type InferDbClientFromConnection,\n type InferDriverTypeFromConnection,\n type InitTransaction,\n type SQLCommandOptions,\n type SQLExecutor,\n} from '../../../../core';\nimport { mapSqliteError } from '../errors';\nimport { sqliteSQLExecutor, type SQLiteErrorMapper } from '../execute';\nimport { sqliteTransaction, type SQLiteTransactionMode } from '../transactions';\nimport {\n SQLiteConnectionString,\n type SQLitePragmaOptions,\n} from './connectionString';\n\nexport type SQLiteCommandOptions = SQLCommandOptions & {\n ignoreChangesCount?: boolean;\n};\n\nexport type BatchSQLiteCommandOptions = SQLiteCommandOptions &\n BatchSQLCommandOptions;\n\nexport type SQLiteParameters =\n | object\n | string\n | bigint\n | number\n | boolean\n | null;\n\nexport type SQLiteClient = {\n connect: () => Promise<void>;\n close: () => Promise<void>;\n} & SQLExecutor;\n\nexport type SQLitePoolClient = {\n release: () => void;\n} & SQLExecutor;\n\nexport type SQLiteClientFactory<\n SQLiteClientType extends SQLiteClient = SQLiteClient,\n ClientOptions = SQLiteClientOptions,\n> = (options: ClientOptions) => SQLiteClientType;\n\nexport type SQLiteClientOrPoolClient = SQLitePoolClient | SQLiteClient;\n\nexport interface SQLiteError extends Error {\n errno: number;\n}\n\nexport const isSQLiteError = (error: unknown): error is SQLiteError => {\n if (error instanceof Error && 'code' in error) {\n return true;\n }\n\n return false;\n};\n\nexport type SQLiteClientConnection<\n Self extends AnyConnection = AnyConnection,\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n SQLiteClientType extends SQLiteClient = SQLiteClient,\n TransactionType extends DatabaseTransaction<Self> = DatabaseTransaction<Self>,\n> = Connection<Self, DriverType, SQLiteClientType, TransactionType>;\n\nexport type SQLitePoolClientConnection<\n Self extends AnyConnection = AnyConnection,\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n SQLitePoolClientType extends SQLitePoolClient = SQLitePoolClient,\n TransactionType extends DatabaseTransaction<Self> = DatabaseTransaction<Self>,\n> = Connection<Self, DriverType, SQLitePoolClientType, TransactionType>;\n\nexport type SQLiteConnection<\n Self extends AnyConnection = AnyConnection,\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n SQLiteClientType extends SQLiteClientOrPoolClient =\n | SQLiteClient\n | SQLitePoolClient,\n TransactionType extends DatabaseTransaction<Self> = DatabaseTransaction<Self>,\n> =\n | (SQLiteClientType extends SQLiteClient\n ? SQLiteClientConnection<\n Self,\n DriverType,\n SQLiteClientType,\n TransactionType\n >\n : never)\n | (SQLiteClientType extends SQLitePoolClient\n ? SQLitePoolClientConnection<\n Self,\n DriverType,\n SQLiteClientType,\n TransactionType\n >\n : never);\n\nexport type AnySQLiteClientConnection =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n SQLiteClientConnection<any, any>;\n\nexport type AnySQLitePoolClientConnection =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n SQLitePoolClientConnection<any, any, any, any>;\n\nexport type AnySQLiteConnection =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n SQLiteConnection<any, any, any, any>;\n\nexport type SQLiteConnectionOptions<\n ConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = ConnectionOptions<ConnectionType> & SQLiteClientOptions;\n\nexport type SQLiteClientConnectionDefinitionOptions<\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n ConnectionOptions = SQLiteConnectionOptions,\n> = {\n driverType: InferDriverTypeFromConnection<SQLiteConnectionType>;\n type: 'Client';\n sqliteClientFactory: SQLiteClientFactory<\n InferDbClientFromConnection<SQLiteConnectionType>,\n ConnectionOptions\n >;\n connectionOptions: SQLiteConnectionOptions<SQLiteConnectionType>;\n serializer: JSONSerializer;\n};\n\nexport type SQLitePoolConnectionDefinitionOptions<\n SQLiteConnectionType extends AnySQLitePoolClientConnection =\n AnySQLitePoolClientConnection,\n ConnectionOptions = SQLiteConnectionOptions,\n> = {\n driverType: InferDriverTypeFromConnection<SQLiteConnectionType>;\n type: 'PoolClient';\n sqliteClientFactory: SQLiteClientFactory<\n InferDbClientFromConnection<SQLiteConnectionType>,\n ConnectionOptions\n >;\n connectionOptions: SQLiteConnectionOptions<SQLiteConnectionType>;\n serializer: JSONSerializer;\n};\n\nexport type SQLiteConnectionDefinitionOptions<\n SQLiteConnectionType extends AnySQLitePoolClientConnection =\n AnySQLitePoolClientConnection,\n ClientOptions = SQLiteClientOptions,\n> =\n | SQLiteClientConnectionDefinitionOptions<SQLiteConnectionType, ClientOptions>\n | SQLitePoolConnectionDefinitionOptions<SQLiteConnectionType, ClientOptions>;\n\nexport type SQLiteConnectionFactory<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n> = (options: ConnectionOptions) => SQLiteConnectionType;\n\nexport type TransactionNestingCounter = {\n increment: () => void;\n decrement: () => void;\n reset: () => void;\n level: number;\n};\n\nexport const transactionNestingCounter = (): TransactionNestingCounter => {\n let transactionLevel = 0;\n\n return {\n reset: () => {\n transactionLevel = 0;\n },\n increment: () => {\n transactionLevel++;\n },\n decrement: () => {\n transactionLevel--;\n\n if (transactionLevel < 0) {\n throw new Error('Transaction level is out of bounds');\n }\n },\n get level() {\n return transactionLevel;\n },\n };\n};\n\nexport type SqliteAmbientClientConnectionOptions<\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n> = {\n driverType: SQLiteConnectionType['driverType'];\n client: InferDbClientFromConnection<SQLiteConnectionType>;\n initTransaction?: InitTransaction<SQLiteConnectionType>;\n allowNestedTransactions?: boolean;\n defaultTransactionMode?: SQLiteTransactionMode;\n serializer: JSONSerializer;\n errorMapper?: SQLiteErrorMapper;\n};\n\nexport const sqliteAmbientClientConnection = <\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n>(\n options: SqliteAmbientClientConnectionOptions<SQLiteConnectionType>,\n) => {\n const {\n client,\n driverType,\n initTransaction,\n allowNestedTransactions,\n defaultTransactionMode,\n serializer,\n errorMapper,\n } = options;\n\n return createAmbientConnection<SQLiteConnectionType>({\n driverType,\n client,\n initTransaction:\n initTransaction ??\n ((connection) =>\n sqliteTransaction(\n driverType,\n connection,\n allowNestedTransactions ?? false,\n serializer,\n defaultTransactionMode,\n )),\n executor: ({ serializer }) =>\n sqliteSQLExecutor(driverType, serializer, undefined, errorMapper),\n serializer,\n });\n};\n\nexport const sqliteClientConnection = <\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n ClientOptions = SQLiteClientOptions,\n>(\n options: SQLiteClientConnectionDefinitionOptions<\n SQLiteConnectionType,\n ClientOptions\n >,\n): SQLiteConnectionType => {\n const { connectionOptions, sqliteClientFactory, serializer } = options;\n\n let client: InferDbClientFromConnection<SQLiteConnectionType> | null = null;\n\n const connect = async (): Promise<\n InferDbClientFromConnection<SQLiteConnectionType>\n > => {\n if (client) return Promise.resolve(client);\n\n client = sqliteClientFactory(connectionOptions as ClientOptions);\n\n if (client && 'connect' in client && typeof client.connect === 'function') {\n try {\n await client.connect();\n } catch (error) {\n throw mapSqliteError(error);\n }\n }\n\n return client;\n };\n\n return createConnection({\n driverType: options.driverType,\n connect,\n close: async () => {\n if (client && 'close' in client && typeof client.close === 'function')\n await client.close();\n else if (\n client &&\n 'release' in client &&\n typeof client.release === 'function'\n )\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n client.release();\n },\n initTransaction: (connection) =>\n sqliteTransaction(\n options.driverType,\n connection,\n connectionOptions.transactionOptions?.allowNestedTransactions ?? false,\n serializer,\n connectionOptions.defaultTransactionMode,\n ),\n executor: ({ serializer }) =>\n sqliteSQLExecutor(options.driverType, serializer),\n serializer,\n });\n};\n\nexport const sqlitePoolClientConnection = <\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n ClientOptions = SQLiteClientOptions,\n>(\n options: SQLitePoolConnectionDefinitionOptions<\n SQLiteConnectionType,\n ClientOptions\n >,\n): SQLiteConnectionType => {\n const { connectionOptions, sqliteClientFactory, serializer } = options;\n\n let client: InferDbClientFromConnection<SQLiteConnectionType> | null = null;\n\n const connect = async (): Promise<\n InferDbClientFromConnection<SQLiteConnectionType>\n > => {\n if (client) return Promise.resolve(client);\n\n client = sqliteClientFactory(connectionOptions as ClientOptions);\n\n try {\n await client.connect();\n } catch (error) {\n throw mapSqliteError(error);\n }\n\n return client;\n };\n\n return createConnection({\n driverType: options.driverType,\n connect,\n close: () =>\n client !== null\n ? Promise.resolve((client as unknown as SQLitePoolClient).release())\n : Promise.resolve(),\n initTransaction: (connection) =>\n sqliteTransaction(\n options.driverType,\n connection,\n connectionOptions.transactionOptions?.allowNestedTransactions ?? false,\n serializer,\n connectionOptions.defaultTransactionMode,\n ),\n executor: ({ serializer }) =>\n sqliteSQLExecutor(options.driverType, serializer),\n serializer,\n });\n};\n\nexport function sqliteConnection<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ClientOptions = SQLiteClientOptions,\n>(\n options: SQLiteConnectionDefinitionOptions<\n SQLiteConnectionType,\n ClientOptions\n >,\n): SQLiteConnectionType {\n return options.type === 'Client'\n ? sqliteClientConnection(options)\n : sqlitePoolClientConnection(options);\n}\n\nexport type InMemorySQLiteDatabase = ':memory:';\nexport const InMemorySQLiteDatabase = SQLiteConnectionString(':memory:');\n\nexport type { SQLitePragmaOptions } from './connectionString';\n\nexport const DEFAULT_SQLITE_PRAGMA_OPTIONS: SQLitePragmaOptions = {\n journal_mode: 'WAL',\n synchronous: 'NORMAL',\n cache_size: -1000000,\n foreign_keys: true,\n temp_store: 'MEMORY',\n busy_timeout: 5000,\n mmap_size: 268435456,\n};\n\nexport type SQLiteClientOptions = {\n pragmaOptions?: Partial<SQLitePragmaOptions>;\n defaultTransactionMode?: SQLiteTransactionMode;\n skipDatabasePragmas?: boolean;\n readonly?: boolean;\n};\n\nexport * from './connectionString';\n","import { cpus } from 'os';\nimport {\n createBoundedConnectionPool,\n createSingletonConnectionPool,\n} from '../../../../core';\nimport { guardInitializedOnce } from '../../../../core/taskProcessing';\nimport type {\n AnySQLiteConnection,\n SQLiteConnectionFactory,\n SQLiteConnectionOptions,\n} from '../connections';\nimport { mapSqliteError } from '../errors';\nimport type { SQLitePool } from './pool';\n\nexport type SQLiteDualPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions,\n> = {\n driverType: SQLiteConnectionType['driverType'];\n dual?: true;\n singleton?: false;\n pooled?: true;\n connection?: never;\n readerPoolSize?: number;\n sqliteConnectionFactory: SQLiteConnectionFactory<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n connectionOptions?: ConnectionOptions;\n};\n\nexport const sqliteDualConnectionPool = <\n SQLiteConnectionType extends AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions,\n>(\n options: SQLiteDualPoolOptions<SQLiteConnectionType, ConnectionOptions>,\n): SQLitePool<SQLiteConnectionType> => {\n const { sqliteConnectionFactory, connectionOptions } = options;\n const readerPoolSize = options.readerPoolSize ?? Math.max(4, cpus().length);\n\n let databaseInitPromise: Promise<void> | null = null;\n\n const guardSingleConnection = guardInitializedOnce(async () => {\n if (databaseInitPromise !== null) {\n return databaseInitPromise;\n }\n\n const initConnection = sqliteConnectionFactory({\n ...connectionOptions,\n skipDatabasePragmas: false,\n readonly: false,\n } as ConnectionOptions);\n\n const initPromise = initConnection.open();\n databaseInitPromise = initPromise;\n\n try {\n await initPromise;\n await initConnection.close();\n } catch (error) {\n databaseInitPromise = null;\n await initConnection.close();\n throw mapSqliteError(error);\n }\n });\n\n const ensureDatabaseInitialized = async (): Promise<void> => {\n if (databaseInitPromise !== null) {\n return databaseInitPromise;\n }\n\n return guardSingleConnection.ensureInitialized();\n };\n\n const wrappedConnectionFactory = async (\n readonly: boolean,\n connectionOptions: ConnectionOptions | undefined,\n ): Promise<SQLiteConnectionType> => {\n await ensureDatabaseInitialized();\n\n const connection = sqliteConnectionFactory({\n ...connectionOptions,\n skipDatabasePragmas: true,\n readonly,\n } as ConnectionOptions);\n\n await connection.open();\n\n return connection;\n };\n\n const writerPool = createSingletonConnectionPool({\n driverType: options.driverType,\n getConnection: () => wrappedConnectionFactory(false, connectionOptions),\n });\n\n const readerPool = createBoundedConnectionPool({\n driverType: options.driverType,\n getConnection: () => wrappedConnectionFactory(true, connectionOptions),\n maxConnections: readerPoolSize,\n });\n\n return {\n driverType: options.driverType,\n connection: (connectionOptions) =>\n connectionOptions?.readonly\n ? readerPool.connection(connectionOptions)\n : writerPool.connection(connectionOptions),\n execute: {\n query: (...args) => readerPool.execute.query(...args),\n batchQuery: (...args) => readerPool.execute.batchQuery(...args),\n command: (...args) => writerPool.execute.command(...args),\n batchCommand: (...args) => writerPool.execute.batchCommand(...args),\n },\n withConnection: (handle, connectionOptions) =>\n connectionOptions?.readonly\n ? readerPool.withConnection(handle, connectionOptions)\n : writerPool.withConnection(handle, connectionOptions),\n transaction: writerPool.transaction,\n withTransaction: writerPool.withTransaction,\n close: async () => {\n await guardSingleConnection.stop();\n await Promise.all([writerPool.close(), readerPool.close()]);\n },\n };\n};\n","import type { SQLiteConnectionString } from '../connections/connectionString';\nimport {\n InMemorySQLiteDatabase,\n type AnySQLiteConnection,\n type SQLiteConnectionFactory,\n type SQLiteConnectionOptions,\n} from '../connections';\nimport type { JSONSerializer } from '../../../../core';\nimport {\n createAlwaysNewConnectionPool,\n createAmbientConnectionPool,\n createSingletonConnectionPool,\n type ConnectionPool,\n} from '../../../../core';\nimport {\n sqliteDualConnectionPool,\n type SQLiteDualPoolOptions,\n} from './dualPool';\n\nexport type SQLiteFileNameOrConnectionString =\n | {\n fileName: string | SQLiteConnectionString;\n connectionString?: never;\n }\n | {\n connectionString: string | SQLiteConnectionString;\n fileName?: never;\n };\n\nexport const isInMemoryDatabase = (\n options: Record<string, unknown>,\n): boolean => {\n if ('fileName' in options) {\n return options.fileName === InMemorySQLiteDatabase;\n }\n if ('connectionString' in options) {\n return options.connectionString === InMemorySQLiteDatabase;\n }\n return false;\n};\n\nexport type SQLiteAmbientConnectionPool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = ConnectionPool<SQLiteConnectionType>;\n\ntype SQLiteAmbientConnectionPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = {\n singleton?: true;\n pooled?: false;\n sqliteConnectionFactory?: never;\n connection: SQLiteConnectionType;\n connectionOptions?: never;\n};\n\nexport const sqliteAmbientConnectionPool = <\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n>(\n options: {\n driverType: SQLiteConnectionType['driverType'];\n } & SQLiteAmbientConnectionPoolOptions<SQLiteConnectionType['driverType']>,\n): SQLiteAmbientConnectionPool<SQLiteConnectionType['driverType']> => {\n const { connection, driverType } = options;\n\n return createAmbientConnectionPool<SQLiteConnectionType>({\n driverType,\n connection: connection,\n });\n};\n\ntype SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n> = {\n singleton: true;\n pooled?: true;\n sqliteConnectionFactory: SQLiteConnectionFactory<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n connection?: never;\n connectionOptions: ConnectionOptions;\n};\n\nexport type SQLiteSingletonConnectionPool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = ConnectionPool<SQLiteConnectionType>;\n\nexport const sqliteSingletonConnectionPool = <\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions & Record<string, unknown> =\n SQLiteConnectionOptions & Record<string, unknown>,\n>(\n options: {\n driverType: SQLiteConnectionType['driverType'];\n } & SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >,\n): SQLiteSingletonConnectionPool<SQLiteConnectionType> => {\n const { driverType, sqliteConnectionFactory, connectionOptions } = options;\n\n return createSingletonConnectionPool<SQLiteConnectionType>({\n driverType,\n getConnection: () => sqliteConnectionFactory(connectionOptions),\n });\n};\n\ntype SQLiteAlwaysNewPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n> = {\n singleton?: false;\n pooled?: true;\n sqliteConnectionFactory: SQLiteConnectionFactory<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n connection?: never;\n connectionOptions: ConnectionOptions;\n};\n\nexport type SQLiteAlwaysNewConnectionPool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = ConnectionPool<SQLiteConnectionType>;\n\nexport const sqliteAlwaysNewConnectionPool = <\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions & Record<string, unknown> =\n SQLiteConnectionOptions & Record<string, unknown>,\n>(\n options: {\n driverType: SQLiteConnectionType['driverType'];\n } & SQLiteAlwaysNewPoolOptions<SQLiteConnectionType, ConnectionOptions>,\n): SQLiteAlwaysNewConnectionPool<SQLiteConnectionType> => {\n const { driverType, sqliteConnectionFactory, connectionOptions } = options;\n\n return createAlwaysNewConnectionPool<SQLiteConnectionType>({\n driverType,\n getConnection: () => sqliteConnectionFactory(connectionOptions),\n });\n};\n\nexport type SQLitePoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n> = (\n | SQLiteAlwaysNewPoolOptions<SQLiteConnectionType, ConnectionOptions>\n | SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >\n | SQLiteAmbientConnectionPoolOptions<SQLiteConnectionType>\n | SQLiteDualPoolOptions<SQLiteConnectionType, ConnectionOptions>\n) & {\n driverType: SQLiteConnectionType['driverType'];\n serializer?: JSONSerializer;\n};\n\nexport type SQLitePool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> =\n | SQLiteAmbientConnectionPool<SQLiteConnectionType>\n | SQLiteSingletonConnectionPool<SQLiteConnectionType>\n | SQLiteAlwaysNewConnectionPool<SQLiteConnectionType>;\n\nexport type SQLitePoolFactoryOptions<\n SQLiteConnectionType extends AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions,\n> = Omit<\n SQLitePoolOptions<SQLiteConnectionType, ConnectionOptions>,\n 'singleton'\n> & {\n singleton?: boolean;\n};\n\nexport const toSqlitePoolOptions = <\n SQLiteConnectionType extends AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions,\n>(\n options: SQLitePoolFactoryOptions<SQLiteConnectionType, ConnectionOptions>,\n): SQLitePoolOptions<SQLiteConnectionType, ConnectionOptions> => {\n const { singleton, ...rest } = options;\n const isInMemory = isInMemoryDatabase(options);\n\n if ('client' in options && options.client) {\n return { ...rest, singleton: true } as SQLitePoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n }\n\n if (isInMemory) {\n return { ...rest, singleton: true } as SQLitePoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n }\n\n if (singleton === true) {\n return { ...rest, singleton: true } as SQLitePoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n }\n\n return { ...rest, dual: true } as SQLitePoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n};\n\nexport function sqlitePool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n>(\n options: SQLitePoolOptions<SQLiteConnectionType, ConnectionOptions>,\n): SQLitePool<SQLiteConnectionType> {\n const { driverType } = options;\n\n if (\n (\n options as SQLiteAmbientConnectionPoolOptions<SQLiteConnectionType> & {\n driverType: SQLiteConnectionType['driverType'];\n }\n ).connection\n )\n return createAmbientConnectionPool<SQLiteConnectionType>({\n driverType,\n connection: (\n options as SQLiteAmbientConnectionPoolOptions<SQLiteConnectionType> & {\n driverType: SQLiteConnectionType['driverType'];\n }\n ).connection,\n });\n\n if ('dual' in options && options.dual) {\n return sqliteDualConnectionPool(\n options as SQLiteDualPoolOptions<SQLiteConnectionType, ConnectionOptions>,\n );\n }\n\n if (\n options.singleton === true &&\n (\n options as SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n > & { driverType: SQLiteConnectionType['driverType'] }\n ).sqliteConnectionFactory\n ) {\n return createSingletonConnectionPool({\n driverType,\n getConnection: () =>\n (\n options as SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n > & { driverType: SQLiteConnectionType['driverType'] }\n ).sqliteConnectionFactory(\n (\n options as SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n > & { driverType: SQLiteConnectionType['driverType'] }\n ).connectionOptions,\n ),\n });\n }\n\n return createAlwaysNewConnectionPool({\n driverType,\n getConnection: () =>\n (\n options as SQLiteAlwaysNewPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n > & { driverType: SQLiteConnectionType['driverType'] }\n ).sqliteConnectionFactory(\n (\n options as SQLiteAlwaysNewPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n > & { driverType: SQLiteConnectionType['driverType'] }\n ).connectionOptions,\n ),\n });\n}\n","import {\n registerDefaultMigratorOptions,\n type MigratorOptions,\n} from '../../../../core';\n\nexport const DefaultSQLiteMigratorOptions: MigratorOptions = {};\n\nregisterDefaultMigratorOptions('SQLite', DefaultSQLiteMigratorOptions);\n","import type { DatabaseDriverType } from '../../..';\n\nexport * from './connections';\nexport * from './errors';\nexport * from './execute';\nexport * from './pool';\nexport * from './schema';\nexport * from './sql';\nexport * from './transactions';\n\nexport type SQLiteDatabaseName = 'SQLite';\nexport const SQLiteDatabaseName = 'SQLite';\n\nexport type SQLiteDriverType<DriverName extends string = string> =\n DatabaseDriverType<SQLiteDatabaseName, DriverName>;\n\nexport type SQLiteDatabaseType = 'SQLite';\n"],"mappings":";;;;;;;;;;;;AAwBA,MAAM,sBAAsB,UAAuC;AACjE,KACE,iBAAiB,SACjB,UAAU,SACV,OAAQ,MAAkC,SAAS,SAEnD,QAAQ,MAAkC;;AAK9C,MAAM,mBAAmB,UACvB,iBAAiB,QAAQ,MAAM,UAAU;AAE3C,MAAM,W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