@event-driven-io/dumbo 0.13.0-beta.4 → 0.13.0-beta.41

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.
Files changed (83) hide show
  1. package/dist/cloudflare.cjs +397 -0
  2. package/dist/cloudflare.cjs.map +1 -0
  3. package/dist/cloudflare.d.cts +99 -0
  4. package/dist/cloudflare.d.ts +99 -0
  5. package/dist/cloudflare.js +361 -0
  6. package/dist/cloudflare.js.map +1 -0
  7. package/dist/core-BMeDuqBQ.js +2265 -0
  8. package/dist/core-BMeDuqBQ.js.map +1 -0
  9. package/dist/core-BPNgo5b6.js +379 -0
  10. package/dist/core-BPNgo5b6.js.map +1 -0
  11. package/dist/core-CIVu4cNp.cjs +588 -0
  12. package/dist/core-CIVu4cNp.cjs.map +1 -0
  13. package/dist/core-D5W_5J8k.cjs +3246 -0
  14. package/dist/core-D5W_5J8k.cjs.map +1 -0
  15. package/dist/core-DqUjje4u.cjs +450 -0
  16. package/dist/core-DqUjje4u.cjs.map +1 -0
  17. package/dist/core-gu5fi784.js +451 -0
  18. package/dist/core-gu5fi784.js.map +1 -0
  19. package/dist/{index-C2z_XBn6.d.ts → index-B-q2er0S.d.cts} +122 -75
  20. package/dist/{index-C0h0c380.d.cts → index-B5qbt5nP.d.ts} +122 -75
  21. package/dist/index-BJJAkyuJ.d.ts +68 -0
  22. package/dist/index-CRbkvVjT.d.ts +1587 -0
  23. package/dist/index-Cmdlb0KP.d.cts +1587 -0
  24. package/dist/index-D7qxqMf9.d.cts +67 -0
  25. package/dist/index-DtRCGhFP.d.cts +68 -0
  26. package/dist/index-m5LDyNNF.d.ts +67 -0
  27. package/dist/index.cjs +219 -270
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +3 -127
  30. package/dist/index.d.ts +3 -127
  31. package/dist/index.js +56 -269
  32. package/dist/index.js.map +1 -1
  33. package/dist/pg.cjs +373 -659
  34. package/dist/pg.cjs.map +1 -1
  35. package/dist/pg.d.cts +140 -153
  36. package/dist/pg.d.ts +140 -153
  37. package/dist/pg.js +326 -658
  38. package/dist/pg.js.map +1 -1
  39. package/dist/postgreSQLMetadata-Khf1e9CT.js +65 -0
  40. package/dist/postgreSQLMetadata-Khf1e9CT.js.map +1 -0
  41. package/dist/postgreSQLMetadata-Ri_p5u6i.cjs +118 -0
  42. package/dist/postgreSQLMetadata-Ri_p5u6i.cjs.map +1 -0
  43. package/dist/postgresql.cjs +25 -0
  44. package/dist/postgresql.d.cts +3 -0
  45. package/dist/postgresql.d.ts +3 -0
  46. package/dist/postgresql.js +4 -0
  47. package/dist/sqlite.cjs +30 -0
  48. package/dist/sqlite.d.cts +3 -0
  49. package/dist/sqlite.d.ts +3 -0
  50. package/dist/sqlite.js +4 -0
  51. package/dist/sqlite3.cjs +437 -273
  52. package/dist/sqlite3.cjs.map +1 -1
  53. package/dist/sqlite3.d.cts +92 -70
  54. package/dist/sqlite3.d.ts +92 -70
  55. package/dist/sqlite3.js +402 -272
  56. package/dist/sqlite3.js.map +1 -1
  57. package/dist/sqliteMetadata-CpmoZxqb.cjs +46 -0
  58. package/dist/sqliteMetadata-CpmoZxqb.cjs.map +1 -0
  59. package/dist/sqliteMetadata-viYmVwA5.js +29 -0
  60. package/dist/sqliteMetadata-viYmVwA5.js.map +1 -0
  61. package/package.json +60 -37
  62. package/dist/chunk-32AL3EAS.cjs +0 -47
  63. package/dist/chunk-32AL3EAS.cjs.map +0 -1
  64. package/dist/chunk-6IHCIJ7S.js +0 -47
  65. package/dist/chunk-6IHCIJ7S.js.map +0 -1
  66. package/dist/chunk-IYEHOE4S.cjs +0 -405
  67. package/dist/chunk-IYEHOE4S.cjs.map +0 -1
  68. package/dist/chunk-N7RWT46K.js +0 -2011
  69. package/dist/chunk-N7RWT46K.js.map +0 -1
  70. package/dist/chunk-OJ34O3Q2.cjs +0 -2011
  71. package/dist/chunk-OJ34O3Q2.cjs.map +0 -1
  72. package/dist/chunk-XVV3OOQX.js +0 -405
  73. package/dist/chunk-XVV3OOQX.js.map +0 -1
  74. package/dist/columnProcessors-BX-sH7ah.d.cts +0 -8
  75. package/dist/columnProcessors-DMPpTPqM.d.ts +0 -8
  76. package/dist/connectionString-B1wm0TFc.d.cts +0 -1271
  77. package/dist/connectionString-B1wm0TFc.d.ts +0 -1271
  78. package/dist/d1.cjs +0 -277
  79. package/dist/d1.cjs.map +0 -1
  80. package/dist/d1.d.cts +0 -72
  81. package/dist/d1.d.ts +0 -72
  82. package/dist/d1.js +0 -277
  83. package/dist/d1.js.map +0 -1
package/dist/sqlite3.js CHANGED
@@ -1,282 +1,412 @@
1
- import {
2
- DefaultSQLiteMigratorOptions,
3
- InMemorySQLiteDatabase,
4
- SQLiteConnectionString,
5
- SQLiteDatabaseName,
6
- defaultPostgreSqlDatabase,
7
- isInMemoryDatabase,
8
- isSQLiteError,
9
- sqliteAlwaysNewConnectionPool,
10
- sqliteAmbientClientConnection,
11
- sqliteAmbientConnectionPool,
12
- sqliteClientConnection,
13
- sqliteConnection,
14
- sqliteExecute,
15
- sqliteFormatter,
16
- sqlitePool,
17
- sqlitePoolClientConnection,
18
- sqliteSQLExecutor,
19
- sqliteSingletonConnectionPool,
20
- sqliteTransaction,
21
- tableExists,
22
- tableExistsSQL,
23
- toSqlitePoolOptions,
24
- transactionNestingCounter
25
- } from "./chunk-XVV3OOQX.js";
26
- import "./chunk-6IHCIJ7S.js";
27
- import {
28
- SQL,
29
- canHandleDriverWithConnectionString,
30
- dumboDatabaseDriverRegistry
31
- } from "./chunk-N7RWT46K.js";
32
-
33
- // src/storage/sqlite/sqlite3/connections/connection.ts
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-BMeDuqBQ.js";
2
+ import { n as defaultSQLiteDatabase, r as tableExists, t as sqliteMetadata } from "./sqliteMetadata-viYmVwA5.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-gu5fi784.js";
34
4
  import sqlite3 from "sqlite3";
35
- var SQLite3DriverType = "SQLite:sqlite3";
36
- var sqlite3Client = (options) => {
37
- let db;
38
- let isClosed = false;
39
- const connect = () => db ? Promise.resolve() : new Promise((resolve, reject) => {
40
- try {
41
- db = new sqlite3.Database(
42
- options.fileName ?? options.connectionString ?? InMemorySQLiteDatabase,
43
- sqlite3.OPEN_URI | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE,
44
- (err) => {
45
- if (err) {
46
- reject(err);
47
- return;
48
- }
49
- }
50
- );
51
- db.run("PRAGMA journal_mode = WAL;", (err) => {
52
- if (err) {
53
- reject(err);
54
- return;
55
- }
56
- resolve();
57
- });
58
- } catch (error) {
59
- reject(error);
60
- }
61
- });
62
- const executeQuery = (sql, params) => new Promise((resolve, reject) => {
63
- try {
64
- db.all(sql, params ?? [], (err, result) => {
65
- if (err) {
66
- reject(err);
67
- return;
68
- }
69
- resolve(result);
70
- });
71
- } catch (error) {
72
- reject(error);
73
- }
74
- });
75
- const executeCommand = (sql, params, options2) => new Promise((resolve, reject) => {
76
- try {
77
- if (options2?.ignoreChangesCount === true) {
78
- db.run(
79
- sql,
80
- params ?? [],
81
- function(err, rows) {
82
- if (err) {
83
- reject(err);
84
- return;
85
- }
86
- resolve({
87
- rowCount: 0,
88
- rows: rows ?? []
89
- });
90
- }
91
- );
92
- }
93
- db.serialize(() => {
94
- db.all(sql, params ?? [], (err, rows) => {
95
- if (err) {
96
- reject(err);
97
- return;
98
- }
99
- db.get(
100
- "SELECT changes() as changes",
101
- (changesErr, row) => {
102
- if (changesErr) {
103
- reject(changesErr);
104
- return;
105
- }
106
- resolve({
107
- rowCount: row?.changes ?? 0,
108
- rows: rows ?? []
109
- });
110
- }
111
- );
112
- });
113
- });
114
- } catch (error) {
115
- reject(error);
116
- }
117
- });
118
- return {
119
- connect,
120
- close: () => {
121
- if (isClosed) {
122
- return Promise.resolve();
123
- }
124
- isClosed = true;
125
- if (db)
126
- return new Promise((resolve, reject) => {
127
- db.close((err) => {
128
- if (err) {
129
- reject(err);
130
- return;
131
- }
132
- resolve();
133
- });
134
- });
135
- return Promise.resolve();
136
- },
137
- query: async (sql, _options) => {
138
- const { query, params } = sqliteFormatter.format(sql);
139
- const result = await executeQuery(
140
- query,
141
- params
142
- );
143
- return { rowCount: result.length, rows: result };
144
- },
145
- batchQuery: async (sqls, _options) => {
146
- const results = [];
147
- for (const sql of sqls) {
148
- const { query, params } = sqliteFormatter.format(sql);
149
- const result = await executeQuery(
150
- query,
151
- params
152
- );
153
- results.push({ rowCount: result.length, rows: result });
154
- }
155
- return results;
156
- },
157
- command: async (sql, options2) => {
158
- const { query, params } = sqliteFormatter.format(sql);
159
- return executeCommand(
160
- query,
161
- params,
162
- options2
163
- );
164
- },
165
- batchCommand: async (sqls, options2) => {
166
- const results = [];
167
- for (const sql of sqls) {
168
- const { query, params } = sqliteFormatter.format(sql);
169
- const result = await executeCommand(
170
- query,
171
- params,
172
- options2
173
- );
174
- results.push(result);
175
- }
176
- return results;
177
- }
178
- };
5
+ import { cpus } from "os";
6
+ import { AsyncLocalStorage } from "node:async_hooks";
7
+
8
+ //#region src/storage/sqlite/core/connections/pragmas.ts
9
+ const mergePragmaOptions = (connectionString, userOptions) => {
10
+ const connectionStringPragmas = parsePragmasFromConnectionString(connectionString);
11
+ return {
12
+ ...DEFAULT_SQLITE_PRAGMA_OPTIONS,
13
+ ...connectionStringPragmas,
14
+ ...userOptions
15
+ };
16
+ };
17
+ const buildConnectionPragmaStatements = (pragmas) => [
18
+ {
19
+ pragma: "busy_timeout",
20
+ value: pragmas.busy_timeout
21
+ },
22
+ {
23
+ pragma: "synchronous",
24
+ value: pragmas.synchronous
25
+ },
26
+ {
27
+ pragma: "cache_size",
28
+ value: pragmas.cache_size
29
+ },
30
+ {
31
+ pragma: "foreign_keys",
32
+ value: pragmas.foreign_keys ? "ON" : "OFF"
33
+ },
34
+ {
35
+ pragma: "temp_store",
36
+ value: pragmas.temp_store
37
+ },
38
+ ...pragmas.mmap_size !== void 0 ? [{
39
+ pragma: "mmap_size",
40
+ value: pragmas.mmap_size
41
+ }] : []
42
+ ];
43
+ const buildDatabasePragmaStatements = (pragmas) => [{
44
+ pragma: "journal_mode",
45
+ value: pragmas.journal_mode
46
+ }];
47
+
48
+ //#endregion
49
+ //#region src/storage/sqlite/sqlite3/connections/connection.ts
50
+ const SQLite3DriverType = "SQLite:sqlite3";
51
+ const hasReturningClause = (sql) => /\bRETURNING\b/i.test(sql);
52
+ const applyPragma = (database, pragma, value) => {
53
+ return new Promise((resolve, reject) => {
54
+ database.run(`PRAGMA ${pragma} = ${value};`, (err) => {
55
+ if (err) reject(err);
56
+ else resolve();
57
+ });
58
+ });
59
+ };
60
+ const queryPragma = (database, pragma) => new Promise((resolve, reject) => {
61
+ database.get(`PRAGMA ${pragma};`, (err, row) => {
62
+ if (err) reject(err);
63
+ else resolve(row?.[pragma] ?? "");
64
+ });
65
+ });
66
+ const applyPragmas = (database, pragmas) => pragmas.reduce((promise, { pragma, value }) => promise.then(() => applyPragma(database, pragma, value)), Promise.resolve());
67
+ const sqlite3Client = (options) => {
68
+ let db;
69
+ let isClosed = false;
70
+ const { serializer } = options;
71
+ const connectionString = options.fileName ?? options.connectionString ?? InMemorySQLiteDatabase;
72
+ const finalPragmas = mergePragmaOptions(String(connectionString), options.pragmaOptions);
73
+ const connectionPragmas = buildConnectionPragmaStatements(finalPragmas);
74
+ const connect = () => db ? Promise.resolve() : new Promise((resolve, reject) => {
75
+ try {
76
+ db = new sqlite3.Database(connectionString, sqlite3.OPEN_URI | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
77
+ if (err) {
78
+ reject(err);
79
+ return;
80
+ }
81
+ const busyTimeout = finalPragmas.busy_timeout ?? DEFAULT_SQLITE_PRAGMA_OPTIONS.busy_timeout;
82
+ db.configure("busyTimeout", busyTimeout);
83
+ applyPragmas(db, connectionPragmas.filter((p) => p.pragma !== "busy_timeout")).then(async () => {
84
+ if (options.skipDatabasePragmas) return;
85
+ const databasePragmas = buildDatabasePragmaStatements(finalPragmas);
86
+ for (const { pragma, value } of databasePragmas) if ((await queryPragma(db, pragma)).toUpperCase() !== String(value).toUpperCase()) await applyPragma(db, pragma, value);
87
+ }).then(() => resolve()).catch(reject);
88
+ });
89
+ } catch (error) {
90
+ reject(error instanceof Error ? error : new Error(String(error)));
91
+ }
92
+ });
93
+ const executeQuery = (sql, params) => new Promise((resolve, reject) => {
94
+ try {
95
+ db.all(sql, params ?? [], (err, result) => {
96
+ if (err) {
97
+ reject(err);
98
+ return;
99
+ }
100
+ resolve(result);
101
+ });
102
+ } catch (error) {
103
+ reject(error instanceof Error ? error : new Error(String(error)));
104
+ }
105
+ });
106
+ const executeCommand = (sql, params, options) => new Promise((resolve, reject) => {
107
+ try {
108
+ if (options?.ignoreChangesCount === true) {
109
+ db.run(sql, params ?? [], function(err, rows) {
110
+ if (err) {
111
+ reject(err);
112
+ return;
113
+ }
114
+ resolve({
115
+ rowCount: 0,
116
+ rows: rows ?? []
117
+ });
118
+ });
119
+ return;
120
+ }
121
+ if (hasReturningClause(sql)) {
122
+ db.all(sql, params ?? [], (err, rows) => {
123
+ if (err) return reject(err);
124
+ resolve({
125
+ rowCount: rows.length,
126
+ rows
127
+ });
128
+ });
129
+ return;
130
+ }
131
+ db.serialize(() => {
132
+ let hasFailed = false;
133
+ let resultRows = [];
134
+ db.all(sql, params ?? [], (err, rows) => {
135
+ if (err) {
136
+ hasFailed = true;
137
+ return reject(err);
138
+ }
139
+ resultRows = rows;
140
+ });
141
+ db.get("SELECT changes() as changes", (err, row) => {
142
+ if (hasFailed) return;
143
+ if (err) return reject(err);
144
+ resolve({
145
+ rowCount: row?.changes ?? 0,
146
+ rows: resultRows
147
+ });
148
+ });
149
+ });
150
+ } catch (error) {
151
+ reject(error instanceof Error ? error : new Error(String(error)));
152
+ }
153
+ });
154
+ return {
155
+ connect,
156
+ close: async () => {
157
+ if (isClosed) return;
158
+ isClosed = true;
159
+ if (db) try {
160
+ await new Promise((resolve, reject) => {
161
+ db.close((err) => {
162
+ if (err) {
163
+ reject(err);
164
+ return;
165
+ }
166
+ resolve();
167
+ });
168
+ });
169
+ } catch (error) {
170
+ throw mapSqliteError(error);
171
+ }
172
+ },
173
+ query: async (sql, _options) => {
174
+ try {
175
+ const { query, params } = sqliteFormatter.format(sql, { serializer });
176
+ const result = await executeQuery(query, params);
177
+ return {
178
+ rowCount: result.length,
179
+ rows: result
180
+ };
181
+ } catch (error) {
182
+ throw mapSqliteError(error);
183
+ }
184
+ },
185
+ batchQuery: async (sqls, _options) => {
186
+ try {
187
+ const results = [];
188
+ for (const sql of sqls) {
189
+ const { query, params } = sqliteFormatter.format(sql, { serializer });
190
+ const result = await executeQuery(query, params);
191
+ results.push({
192
+ rowCount: result.length,
193
+ rows: result
194
+ });
195
+ }
196
+ return results;
197
+ } catch (error) {
198
+ throw mapSqliteError(error);
199
+ }
200
+ },
201
+ command: async (sql, options) => {
202
+ try {
203
+ const { query, params } = sqliteFormatter.format(sql, { serializer });
204
+ return await executeCommand(query, params, options);
205
+ } catch (error) {
206
+ throw mapSqliteError(error);
207
+ }
208
+ },
209
+ batchCommand: async (sqls, options) => {
210
+ try {
211
+ const results = [];
212
+ for (let i = 0; i < sqls.length; i++) {
213
+ const { query, params } = sqliteFormatter.format(sqls[i], { serializer });
214
+ const result = await executeCommand(query, params, options);
215
+ results.push(result);
216
+ if (options?.assertChanges && (result.rowCount ?? 0) === 0) throw new BatchCommandNoChangesError(i);
217
+ }
218
+ return results;
219
+ } catch (error) {
220
+ throw mapSqliteError(error);
221
+ }
222
+ }
223
+ };
179
224
  };
180
- var checkConnection = async (fileName) => {
181
- const client = sqlite3Client({
182
- fileName
183
- });
184
- try {
185
- await client.query(SQL`SELECT 1`);
186
- return { successful: true };
187
- } catch (error) {
188
- const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
189
- return {
190
- successful: false,
191
- errorType: code === "SQLITE_CANTOPEN" ? "ConnectionRefused" : code === "SQLITE_AUTH" ? "Authentication" : "Unknown",
192
- code,
193
- error
194
- };
195
- } finally {
196
- await client.close();
197
- }
225
+ const checkConnection = async (fileName, serializer) => {
226
+ const client = sqlite3Client({
227
+ fileName,
228
+ serializer
229
+ });
230
+ try {
231
+ await client.query(SQL`SELECT 1`);
232
+ return { successful: true };
233
+ } catch (error) {
234
+ const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
235
+ return {
236
+ successful: false,
237
+ errorType: code === "SQLITE_CANTOPEN" ? "ConnectionRefused" : code === "SQLITE_AUTH" ? "Authentication" : "Unknown",
238
+ code,
239
+ error
240
+ };
241
+ } finally {
242
+ await client.close();
243
+ }
198
244
  };
199
- var sqlite3Connection = (options) => sqliteConnection({
200
- type: "Client",
201
- driverType: SQLite3DriverType,
202
- sqliteClientFactory: (connectionOptions) => {
203
- if ("client" in connectionOptions && connectionOptions.client) {
204
- return connectionOptions.client;
205
- }
206
- return sqlite3Client(connectionOptions);
207
- },
208
- connectionOptions: options
245
+ const sqlite3Connection = (options) => sqliteConnection({
246
+ type: "Client",
247
+ driverType: SQLite3DriverType,
248
+ sqliteClientFactory: (connectionOptions) => {
249
+ if ("client" in connectionOptions && connectionOptions.client) return connectionOptions.client;
250
+ return sqlite3Client({
251
+ ...connectionOptions,
252
+ serializer: options.serializer
253
+ });
254
+ },
255
+ connectionOptions: options,
256
+ serializer: options.serializer
209
257
  });
210
258
 
211
- // src/storage/sqlite/sqlite3/index.ts
212
- var sqlite3Pool = (options) => sqlitePool(
213
- toSqlitePoolOptions({
214
- ...options,
215
- driverType: SQLite3DriverType,
216
- ..."connection" in options ? {} : {
217
- connectionOptions: options,
218
- sqliteConnectionFactory: (opts) => sqlite3Connection(opts)
219
- }
220
- })
221
- );
222
- var tryParseConnectionString = (connectionString) => {
223
- try {
224
- return SQLiteConnectionString(connectionString);
225
- } catch {
226
- return null;
227
- }
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
+ };
228
299
  };
229
- var sqlite3DatabaseDriver = {
230
- driverType: SQLite3DriverType,
231
- createPool: (options) => sqlite3Pool(options),
232
- sqlFormatter: sqliteFormatter,
233
- defaultMigratorOptions: DefaultSQLiteMigratorOptions,
234
- getDatabaseNameOrDefault: () => InMemorySQLiteDatabase,
235
- canHandle: canHandleDriverWithConnectionString(
236
- SQLite3DriverType,
237
- tryParseConnectionString
238
- )
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
+
367
+ //#endregion
368
+ //#region src/storage/sqlite/sqlite3/index.ts
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,
386
+ connectionOptions: options,
387
+ ...readerPoolSize !== void 0 ? { readerPoolSize } : {}
388
+ });
239
389
  };
240
- var useSqlite3DatabaseDriver = () => {
241
- dumboDatabaseDriverRegistry.register(
242
- SQLite3DriverType,
243
- sqlite3DatabaseDriver
244
- );
390
+ const tryParseConnectionString = (connectionString) => {
391
+ try {
392
+ return SQLiteConnectionString(connectionString);
393
+ } catch {
394
+ return null;
395
+ }
245
396
  };
246
- useSqlite3DatabaseDriver();
247
- export {
248
- DefaultSQLiteMigratorOptions,
249
- InMemorySQLiteDatabase,
250
- SQLite3DriverType,
251
- SQLiteConnectionString,
252
- SQLiteDatabaseName,
253
- checkConnection,
254
- sqlite3Pool as connectionPool,
255
- sqlite3DatabaseDriver as databaseDriver,
256
- defaultPostgreSqlDatabase,
257
- isInMemoryDatabase,
258
- isSQLiteError,
259
- sqlite3Client,
260
- sqlite3Connection,
261
- sqlite3DatabaseDriver,
262
- sqlite3Pool,
263
- sqliteAlwaysNewConnectionPool,
264
- sqliteAmbientClientConnection,
265
- sqliteAmbientConnectionPool,
266
- sqlite3Client as sqliteClient,
267
- sqliteClientConnection,
268
- sqliteConnection,
269
- sqliteExecute,
270
- sqliteFormatter,
271
- sqlitePool,
272
- sqlitePoolClientConnection,
273
- sqliteSQLExecutor,
274
- sqliteSingletonConnectionPool,
275
- sqliteTransaction,
276
- tableExists,
277
- tableExistsSQL,
278
- toSqlitePoolOptions,
279
- transactionNestingCounter,
280
- useSqlite3DatabaseDriver
397
+ const sqlite3DumboDriver = {
398
+ driverType: SQLite3DriverType,
399
+ createPool: (options) => sqlite3Pool(options),
400
+ sqlFormatter: sqliteFormatter,
401
+ defaultMigratorOptions: DefaultSQLiteMigratorOptions,
402
+ canHandle: canHandleDriverWithConnectionString(SQLite3DriverType, tryParseConnectionString),
403
+ databaseMetadata: sqliteMetadata
281
404
  };
405
+ const useSqlite3DumboDriver = () => {
406
+ dumboDatabaseDriverRegistry.register(SQLite3DriverType, sqlite3DumboDriver);
407
+ };
408
+ useSqlite3DumboDriver();
409
+
410
+ //#endregion
411
+ export { DEFAULT_SQLITE_PRAGMA_OPTIONS, DefaultSQLiteMigratorOptions, InMemorySQLiteDatabase, SQLite3DriverType, SQLiteConnectionString, SQLiteDatabaseName, checkConnection, defaultSQLiteDatabase, isInMemoryDatabase, isSQLiteError, mapSqliteError, parsePragmasFromConnectionString, sqlite3Client, sqlite3Connection, sqlite3DumboDriver, sqlite3Pool, sqliteAlwaysNewConnectionPool, sqliteAmbientClientConnection, sqliteAmbientConnectionPool, sqliteClientConnection, sqliteConnection, sqliteExecute, sqliteFormatter, sqliteMetadata, sqlitePool, sqlitePoolClientConnection, sqliteSQLExecutor, sqliteSingletonConnectionPool, sqliteTransaction, tableExists, toSqlitePoolOptions, transactionNestingCounter, useSqlite3DumboDriver };
282
412
  //# sourceMappingURL=sqlite3.js.map