@event-driven-io/dumbo 0.13.0-beta.28 → 0.13.0-beta.29
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/{chunk-XE3EOVHX.js → chunk-3MGKBBPW.js} +2 -2
- package/dist/{chunk-MDO3F654.cjs → chunk-4EG7BVCJ.cjs} +109 -80
- package/dist/chunk-4EG7BVCJ.cjs.map +1 -0
- package/dist/{chunk-LL7C5HYA.cjs → chunk-6HWAX6QS.cjs} +6 -6
- package/dist/{chunk-LL7C5HYA.cjs.map → chunk-6HWAX6QS.cjs.map} +1 -1
- package/dist/{chunk-WZY7IOOU.js → chunk-BPELC2IY.js} +2 -2
- package/dist/{chunk-MHY7CYDN.js → chunk-DOUKZ6ZP.js} +2 -1
- package/dist/{chunk-UV4VHOZQ.js → chunk-FYOB5WLJ.js} +2 -2
- package/dist/{chunk-56DF2K5J.cjs → chunk-OQAVLNY2.cjs} +43 -43
- package/dist/{chunk-56DF2K5J.cjs.map → chunk-OQAVLNY2.cjs.map} +1 -1
- package/dist/{chunk-VIME2LPV.cjs → chunk-TCILLBMA.cjs} +3 -2
- package/dist/chunk-TCILLBMA.cjs.map +1 -0
- package/dist/{chunk-IWGQR5FU.js → chunk-WTSDCE6M.js} +48 -19
- package/dist/chunk-WTSDCE6M.js.map +1 -0
- package/dist/{chunk-WBQGX4V6.cjs → chunk-YBKIOJBO.cjs} +4 -4
- package/dist/{chunk-WBQGX4V6.cjs.map → chunk-YBKIOJBO.cjs.map} +1 -1
- package/dist/cloudflare.cjs +60 -60
- package/dist/cloudflare.js +3 -3
- package/dist/index.cjs +5 -5
- package/dist/index.js +3 -3
- package/dist/pg.cjs +37 -37
- package/dist/pg.js +3 -3
- package/dist/postgresql.cjs +4 -4
- package/dist/postgresql.js +3 -3
- package/dist/sqlite.cjs +4 -4
- package/dist/sqlite.js +3 -3
- package/dist/sqlite3.cjs +24 -24
- package/dist/sqlite3.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-IWGQR5FU.js.map +0 -1
- package/dist/chunk-MDO3F654.cjs.map +0 -1
- package/dist/chunk-VIME2LPV.cjs.map +0 -1
- /package/dist/{chunk-XE3EOVHX.js.map → chunk-3MGKBBPW.js.map} +0 -0
- /package/dist/{chunk-WZY7IOOU.js.map → chunk-BPELC2IY.js.map} +0 -0
- /package/dist/{chunk-MHY7CYDN.js.map → chunk-DOUKZ6ZP.js.map} +0 -0
- /package/dist/{chunk-UV4VHOZQ.js.map → chunk-FYOB5WLJ.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SQL,
|
|
3
3
|
exists
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-DOUKZ6ZP.js";
|
|
5
5
|
|
|
6
6
|
// src/storage/postgresql/core/connections/connectionString.ts
|
|
7
7
|
var defaultPostgreSQLConnectionString = "postgresql://postgres@localhost:5432/postgres";
|
|
@@ -80,4 +80,4 @@ export {
|
|
|
80
80
|
functionExists,
|
|
81
81
|
postgreSQLMetadata
|
|
82
82
|
};
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-3MGKBBPW.js.map
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
var _chunkTCILLBMAcjs = require('./chunk-TCILLBMA.cjs');
|
|
33
34
|
|
|
34
35
|
// src/storage/sqlite/core/errors/errorMapper.ts
|
|
35
36
|
var getSqliteErrorCode = (error) => {
|
|
@@ -43,20 +44,20 @@ var asError = (error) => error instanceof Error ? error : void 0;
|
|
|
43
44
|
var mapConstraintError = (message, innerError) => {
|
|
44
45
|
const upperMessage = _nullishCoalesce(_optionalChain([message, 'optionalAccess', _ => _.toUpperCase, 'call', _2 => _2()]), () => ( ""));
|
|
45
46
|
if (upperMessage.includes("UNIQUE") || upperMessage.includes("PRIMARY KEY"))
|
|
46
|
-
return new (0,
|
|
47
|
+
return new (0, _chunkTCILLBMAcjs.UniqueConstraintError)(message, innerError);
|
|
47
48
|
if (upperMessage.includes("FOREIGN KEY"))
|
|
48
|
-
return new (0,
|
|
49
|
+
return new (0, _chunkTCILLBMAcjs.ForeignKeyViolationError)(message, innerError);
|
|
49
50
|
if (upperMessage.includes("NOT NULL"))
|
|
50
|
-
return new (0,
|
|
51
|
+
return new (0, _chunkTCILLBMAcjs.NotNullViolationError)(message, innerError);
|
|
51
52
|
if (upperMessage.includes("CHECK"))
|
|
52
|
-
return new (0,
|
|
53
|
-
return new (0,
|
|
53
|
+
return new (0, _chunkTCILLBMAcjs.CheckViolationError)(message, innerError);
|
|
54
|
+
return new (0, _chunkTCILLBMAcjs.IntegrityConstraintViolationError)(message, innerError);
|
|
54
55
|
};
|
|
55
56
|
var mapSqliteError = (error) => {
|
|
56
|
-
if (
|
|
57
|
+
if (_chunkTCILLBMAcjs.DumboError.isInstanceOf(error)) return error;
|
|
57
58
|
const code = getSqliteErrorCode(error);
|
|
58
59
|
if (!code)
|
|
59
|
-
return new (0,
|
|
60
|
+
return new (0, _chunkTCILLBMAcjs.DumboError)({
|
|
60
61
|
errorCode: 500,
|
|
61
62
|
message: getErrorMessage(error),
|
|
62
63
|
innerError: asError(error)
|
|
@@ -71,78 +72,78 @@ var mapSqliteError = (error) => {
|
|
|
71
72
|
// ── Busy / lock contention ──
|
|
72
73
|
// SQLITE_BUSY (5): conflict with a separate database connection
|
|
73
74
|
case "SQLITE_BUSY":
|
|
74
|
-
return new (0,
|
|
75
|
+
return new (0, _chunkTCILLBMAcjs.LockNotAvailableError)(message, innerError);
|
|
75
76
|
// SQLITE_LOCKED (6): conflict within the same connection or shared cache
|
|
76
77
|
case "SQLITE_LOCKED":
|
|
77
|
-
return new (0,
|
|
78
|
+
return new (0, _chunkTCILLBMAcjs.DeadlockError)(message, innerError);
|
|
78
79
|
// SQLITE_PROTOCOL (15): WAL locking race condition
|
|
79
80
|
case "SQLITE_PROTOCOL":
|
|
80
|
-
return new (0,
|
|
81
|
+
return new (0, _chunkTCILLBMAcjs.LockNotAvailableError)(message, innerError);
|
|
81
82
|
// ── Connection / open errors ──
|
|
82
83
|
// SQLITE_CANTOPEN (14): unable to open database file
|
|
83
84
|
case "SQLITE_CANTOPEN":
|
|
84
|
-
return new (0,
|
|
85
|
+
return new (0, _chunkTCILLBMAcjs.ConnectionError)(message, innerError);
|
|
85
86
|
// SQLITE_NOTADB (26): file is not a database
|
|
86
87
|
case "SQLITE_NOTADB":
|
|
87
|
-
return new (0,
|
|
88
|
+
return new (0, _chunkTCILLBMAcjs.ConnectionError)(message, innerError);
|
|
88
89
|
// ── Resource exhaustion ──
|
|
89
90
|
// SQLITE_NOMEM (7): out of memory
|
|
90
91
|
case "SQLITE_NOMEM":
|
|
91
|
-
return new (0,
|
|
92
|
+
return new (0, _chunkTCILLBMAcjs.InsufficientResourcesError)(message, innerError);
|
|
92
93
|
// SQLITE_FULL (13): disk full
|
|
93
94
|
case "SQLITE_FULL":
|
|
94
|
-
return new (0,
|
|
95
|
+
return new (0, _chunkTCILLBMAcjs.InsufficientResourcesError)(message, innerError);
|
|
95
96
|
// ── System / I/O errors ──
|
|
96
97
|
// SQLITE_IOERR (10): operating system I/O error
|
|
97
98
|
case "SQLITE_IOERR":
|
|
98
|
-
return new (0,
|
|
99
|
+
return new (0, _chunkTCILLBMAcjs.SystemError)(message, innerError);
|
|
99
100
|
// SQLITE_CORRUPT (11): database file is corrupted
|
|
100
101
|
case "SQLITE_CORRUPT":
|
|
101
|
-
return new (0,
|
|
102
|
+
return new (0, _chunkTCILLBMAcjs.SystemError)(message, innerError);
|
|
102
103
|
// SQLITE_INTERNAL (2): internal SQLite malfunction
|
|
103
104
|
case "SQLITE_INTERNAL":
|
|
104
|
-
return new (0,
|
|
105
|
+
return new (0, _chunkTCILLBMAcjs.SystemError)(message, innerError);
|
|
105
106
|
// SQLITE_NOLFS (22): large file support unavailable
|
|
106
107
|
case "SQLITE_NOLFS":
|
|
107
|
-
return new (0,
|
|
108
|
+
return new (0, _chunkTCILLBMAcjs.SystemError)(message, innerError);
|
|
108
109
|
// ── Data errors ──
|
|
109
110
|
// SQLITE_TOOBIG (18): string or BLOB too large
|
|
110
111
|
case "SQLITE_TOOBIG":
|
|
111
|
-
return new (0,
|
|
112
|
+
return new (0, _chunkTCILLBMAcjs.DataError)(message, innerError);
|
|
112
113
|
// SQLITE_MISMATCH (20): datatype mismatch
|
|
113
114
|
case "SQLITE_MISMATCH":
|
|
114
|
-
return new (0,
|
|
115
|
+
return new (0, _chunkTCILLBMAcjs.DataError)(message, innerError);
|
|
115
116
|
// SQLITE_RANGE (25): bind parameter index out of range
|
|
116
117
|
case "SQLITE_RANGE":
|
|
117
|
-
return new (0,
|
|
118
|
+
return new (0, _chunkTCILLBMAcjs.DataError)(message, innerError);
|
|
118
119
|
// ── Invalid operations ──
|
|
119
120
|
// SQLITE_ERROR (1): generic SQL error (syntax errors, missing tables, etc.)
|
|
120
121
|
case "SQLITE_ERROR":
|
|
121
|
-
return new (0,
|
|
122
|
+
return new (0, _chunkTCILLBMAcjs.InvalidOperationError)(message, innerError);
|
|
122
123
|
// SQLITE_READONLY (8): attempt to write to a read-only database
|
|
123
124
|
case "SQLITE_READONLY":
|
|
124
|
-
return new (0,
|
|
125
|
+
return new (0, _chunkTCILLBMAcjs.InvalidOperationError)(message, innerError);
|
|
125
126
|
// SQLITE_MISUSE (21): API misuse
|
|
126
127
|
case "SQLITE_MISUSE":
|
|
127
|
-
return new (0,
|
|
128
|
+
return new (0, _chunkTCILLBMAcjs.InvalidOperationError)(message, innerError);
|
|
128
129
|
// SQLITE_AUTH (23): authorization denied
|
|
129
130
|
case "SQLITE_AUTH":
|
|
130
|
-
return new (0,
|
|
131
|
+
return new (0, _chunkTCILLBMAcjs.InvalidOperationError)(message, innerError);
|
|
131
132
|
// SQLITE_PERM (3): access permission denied
|
|
132
133
|
case "SQLITE_PERM":
|
|
133
|
-
return new (0,
|
|
134
|
+
return new (0, _chunkTCILLBMAcjs.InvalidOperationError)(message, innerError);
|
|
134
135
|
// SQLITE_SCHEMA (17): schema changed, statement needs re-preparation
|
|
135
136
|
case "SQLITE_SCHEMA":
|
|
136
|
-
return new (0,
|
|
137
|
+
return new (0, _chunkTCILLBMAcjs.InvalidOperationError)(message, innerError);
|
|
137
138
|
// ── Transaction / abort ──
|
|
138
139
|
// SQLITE_ABORT (4): operation aborted (e.g. by rollback)
|
|
139
140
|
case "SQLITE_ABORT":
|
|
140
|
-
return new (0,
|
|
141
|
+
return new (0, _chunkTCILLBMAcjs.SerializationError)(message, innerError);
|
|
141
142
|
// SQLITE_INTERRUPT (9): operation interrupted
|
|
142
143
|
case "SQLITE_INTERRUPT":
|
|
143
|
-
return new (0,
|
|
144
|
+
return new (0, _chunkTCILLBMAcjs.SerializationError)(message, innerError);
|
|
144
145
|
}
|
|
145
|
-
return new (0,
|
|
146
|
+
return new (0, _chunkTCILLBMAcjs.DumboError)({
|
|
146
147
|
errorCode: 500,
|
|
147
148
|
message,
|
|
148
149
|
innerError
|
|
@@ -188,16 +189,16 @@ var mapColumnType = (token, { builder }) => {
|
|
|
188
189
|
}
|
|
189
190
|
builder.addSQL(columnSQL);
|
|
190
191
|
};
|
|
191
|
-
var sqliteColumnProcessors =
|
|
192
|
+
var sqliteColumnProcessors = _chunkTCILLBMAcjs.mapDefaultSQLColumnProcessors.call(void 0, mapColumnType);
|
|
192
193
|
|
|
193
194
|
// src/storage/sqlite/core/sql/formatter/index.ts
|
|
194
|
-
var sqliteSQLProcessorsRegistry =
|
|
195
|
-
from:
|
|
195
|
+
var sqliteSQLProcessorsRegistry = _chunkTCILLBMAcjs.SQLProcessorsRegistry.call(void 0, {
|
|
196
|
+
from: _chunkTCILLBMAcjs.defaultProcessorsRegistry
|
|
196
197
|
}).register(sqliteColumnProcessors);
|
|
197
|
-
var sqliteFormatter =
|
|
198
|
+
var sqliteFormatter = _chunkTCILLBMAcjs.SQLFormatter.call(void 0, {
|
|
198
199
|
processorsRegistry: sqliteSQLProcessorsRegistry
|
|
199
200
|
});
|
|
200
|
-
|
|
201
|
+
_chunkTCILLBMAcjs.registerFormatter.call(void 0, "SQLite", sqliteFormatter);
|
|
201
202
|
|
|
202
203
|
// src/storage/sqlite/core/execute/execute.ts
|
|
203
204
|
var sqliteExecute = async (database, handle) => {
|
|
@@ -210,7 +211,7 @@ var sqliteExecute = async (database, handle) => {
|
|
|
210
211
|
var sqliteSQLExecutor = (driverType, serializer, formatter, errorMapper) => ({
|
|
211
212
|
driverType,
|
|
212
213
|
query: async (client, sql, options) => {
|
|
213
|
-
|
|
214
|
+
_chunkTCILLBMAcjs.tracer.info("db:sql:query", {
|
|
214
215
|
query: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).format(sql, { serializer }).query,
|
|
215
216
|
params: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).format(sql, { serializer }).params,
|
|
216
217
|
debugSQL: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).describe(sql, { serializer })
|
|
@@ -221,13 +222,13 @@ var sqliteSQLExecutor = (driverType, serializer, formatter, errorMapper) => ({
|
|
|
221
222
|
result = {
|
|
222
223
|
...result,
|
|
223
224
|
rows: result.rows.map(
|
|
224
|
-
(row) =>
|
|
225
|
+
(row) => _chunkTCILLBMAcjs.mapSQLQueryResult.call(void 0, row, options.mapping)
|
|
225
226
|
)
|
|
226
227
|
};
|
|
227
228
|
}
|
|
228
229
|
return result;
|
|
229
230
|
} catch (error) {
|
|
230
|
-
|
|
231
|
+
_chunkTCILLBMAcjs.tracer.error("db:sql:query:execute:error", { error });
|
|
231
232
|
throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
|
|
232
233
|
}
|
|
233
234
|
},
|
|
@@ -238,18 +239,18 @@ var sqliteSQLExecutor = (driverType, serializer, formatter, errorMapper) => ({
|
|
|
238
239
|
return results.map((result) => ({
|
|
239
240
|
...result,
|
|
240
241
|
rows: result.rows.map(
|
|
241
|
-
(row) =>
|
|
242
|
+
(row) => _chunkTCILLBMAcjs.mapSQLQueryResult.call(void 0, row, options.mapping)
|
|
242
243
|
)
|
|
243
244
|
}));
|
|
244
245
|
}
|
|
245
246
|
return results;
|
|
246
247
|
} catch (error) {
|
|
247
|
-
|
|
248
|
+
_chunkTCILLBMAcjs.tracer.error("db:sql:batch_query:execute:error", { error });
|
|
248
249
|
throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
|
|
249
250
|
}
|
|
250
251
|
},
|
|
251
252
|
command: async (client, sql, options) => {
|
|
252
|
-
|
|
253
|
+
_chunkTCILLBMAcjs.tracer.info("db:sql:command", {
|
|
253
254
|
query: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).format(sql, { serializer }).query,
|
|
254
255
|
params: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).format(sql, { serializer }).params,
|
|
255
256
|
debugSQL: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).describe(sql, { serializer })
|
|
@@ -257,7 +258,7 @@ var sqliteSQLExecutor = (driverType, serializer, formatter, errorMapper) => ({
|
|
|
257
258
|
try {
|
|
258
259
|
return await client.command(sql, options);
|
|
259
260
|
} catch (error) {
|
|
260
|
-
|
|
261
|
+
_chunkTCILLBMAcjs.tracer.error("db:sql:command:execute:error", { error });
|
|
261
262
|
throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
|
|
262
263
|
}
|
|
263
264
|
},
|
|
@@ -265,7 +266,7 @@ var sqliteSQLExecutor = (driverType, serializer, formatter, errorMapper) => ({
|
|
|
265
266
|
try {
|
|
266
267
|
return await client.batchCommand(sqls, options);
|
|
267
268
|
} catch (error) {
|
|
268
|
-
|
|
269
|
+
_chunkTCILLBMAcjs.tracer.error("db:sql:batch_command:execute:error", { error });
|
|
269
270
|
throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
|
|
270
271
|
}
|
|
271
272
|
},
|
|
@@ -278,34 +279,59 @@ var sqliteDualConnectionPool = (options) => {
|
|
|
278
279
|
const { sqliteConnectionFactory, connectionOptions } = options;
|
|
279
280
|
const readerPoolSize = _nullishCoalesce(options.readerPoolSize, () => ( Math.max(4, _os.cpus.call(void 0, ).length)));
|
|
280
281
|
let databaseInitPromise = null;
|
|
281
|
-
const
|
|
282
|
+
const initTaskProcessor = new (0, _chunkTCILLBMAcjs.TaskProcessor)({
|
|
283
|
+
maxActiveTasks: 1,
|
|
284
|
+
maxQueueSize: 1e3
|
|
285
|
+
});
|
|
286
|
+
const ensureDatabaseInitialized = async (connectionOptions2, retryCount = 0) => {
|
|
287
|
+
if (databaseInitPromise !== null) {
|
|
288
|
+
return databaseInitPromise;
|
|
289
|
+
}
|
|
290
|
+
return initTaskProcessor.enqueue(
|
|
291
|
+
async ({ ack }) => {
|
|
292
|
+
if (databaseInitPromise !== null) {
|
|
293
|
+
ack();
|
|
294
|
+
return databaseInitPromise;
|
|
295
|
+
}
|
|
296
|
+
const initConnection = sqliteConnectionFactory({
|
|
297
|
+
...connectionOptions2,
|
|
298
|
+
skipDatabasePragmas: false,
|
|
299
|
+
readonly: false
|
|
300
|
+
});
|
|
301
|
+
const initPromise = initConnection.open();
|
|
302
|
+
databaseInitPromise = initPromise;
|
|
303
|
+
try {
|
|
304
|
+
await initPromise;
|
|
305
|
+
await initConnection.close();
|
|
306
|
+
ack();
|
|
307
|
+
} catch (error) {
|
|
308
|
+
databaseInitPromise = null;
|
|
309
|
+
await initConnection.close();
|
|
310
|
+
ack();
|
|
311
|
+
if (retryCount < 3) {
|
|
312
|
+
return ensureDatabaseInitialized(connectionOptions2, retryCount + 1);
|
|
313
|
+
}
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
{ taskGroupId: "db-init" }
|
|
318
|
+
);
|
|
319
|
+
};
|
|
320
|
+
const wrappedConnectionFactory = async (readonly, connectionOptions2) => {
|
|
321
|
+
await ensureDatabaseInitialized(connectionOptions2);
|
|
282
322
|
const connection = sqliteConnectionFactory({
|
|
283
323
|
...connectionOptions2,
|
|
284
|
-
skipDatabasePragmas:
|
|
324
|
+
skipDatabasePragmas: true,
|
|
285
325
|
readonly
|
|
286
326
|
});
|
|
287
|
-
|
|
288
|
-
try {
|
|
289
|
-
await databaseInitPromise;
|
|
290
|
-
} catch (error) {
|
|
291
|
-
databaseInitPromise = null;
|
|
292
|
-
await connection.close();
|
|
293
|
-
if (retryCount < 3) {
|
|
294
|
-
return wrappedConnectionFactory(
|
|
295
|
-
readonly,
|
|
296
|
-
connectionOptions2,
|
|
297
|
-
retryCount + 1
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
throw error;
|
|
301
|
-
}
|
|
327
|
+
await connection.open();
|
|
302
328
|
return connection;
|
|
303
329
|
};
|
|
304
|
-
const writerPool =
|
|
330
|
+
const writerPool = _chunkTCILLBMAcjs.createSingletonConnectionPool.call(void 0, {
|
|
305
331
|
driverType: options.driverType,
|
|
306
332
|
getConnection: () => wrappedConnectionFactory(false, connectionOptions)
|
|
307
333
|
});
|
|
308
|
-
const readerPool =
|
|
334
|
+
const readerPool = _chunkTCILLBMAcjs.createBoundedConnectionPool.call(void 0, {
|
|
309
335
|
driverType: options.driverType,
|
|
310
336
|
getConnection: () => wrappedConnectionFactory(true, connectionOptions),
|
|
311
337
|
maxConnections: readerPoolSize
|
|
@@ -339,21 +365,21 @@ var isInMemoryDatabase = (options) => {
|
|
|
339
365
|
};
|
|
340
366
|
var sqliteAmbientConnectionPool = (options) => {
|
|
341
367
|
const { connection, driverType } = options;
|
|
342
|
-
return
|
|
368
|
+
return _chunkTCILLBMAcjs.createAmbientConnectionPool.call(void 0, {
|
|
343
369
|
driverType,
|
|
344
370
|
connection
|
|
345
371
|
});
|
|
346
372
|
};
|
|
347
373
|
var sqliteSingletonConnectionPool = (options) => {
|
|
348
374
|
const { driverType, sqliteConnectionFactory, connectionOptions } = options;
|
|
349
|
-
return
|
|
375
|
+
return _chunkTCILLBMAcjs.createSingletonConnectionPool.call(void 0, {
|
|
350
376
|
driverType,
|
|
351
377
|
getConnection: () => sqliteConnectionFactory(connectionOptions)
|
|
352
378
|
});
|
|
353
379
|
};
|
|
354
380
|
var sqliteAlwaysNewConnectionPool = (options) => {
|
|
355
381
|
const { driverType, sqliteConnectionFactory, connectionOptions } = options;
|
|
356
|
-
return
|
|
382
|
+
return _chunkTCILLBMAcjs.createAlwaysNewConnectionPool.call(void 0, {
|
|
357
383
|
driverType,
|
|
358
384
|
getConnection: () => sqliteConnectionFactory(connectionOptions)
|
|
359
385
|
});
|
|
@@ -361,6 +387,9 @@ var sqliteAlwaysNewConnectionPool = (options) => {
|
|
|
361
387
|
var toSqlitePoolOptions = (options) => {
|
|
362
388
|
const { singleton, ...rest } = options;
|
|
363
389
|
const isInMemory = isInMemoryDatabase(options);
|
|
390
|
+
if ("client" in options && options.client) {
|
|
391
|
+
return { ...rest, singleton: true };
|
|
392
|
+
}
|
|
364
393
|
if (isInMemory) {
|
|
365
394
|
return { ...rest, singleton: true };
|
|
366
395
|
}
|
|
@@ -372,7 +401,7 @@ var toSqlitePoolOptions = (options) => {
|
|
|
372
401
|
function sqlitePool(options) {
|
|
373
402
|
const { driverType } = options;
|
|
374
403
|
if (options.connection)
|
|
375
|
-
return
|
|
404
|
+
return _chunkTCILLBMAcjs.createAmbientConnectionPool.call(void 0, {
|
|
376
405
|
driverType,
|
|
377
406
|
connection: options.connection
|
|
378
407
|
});
|
|
@@ -382,14 +411,14 @@ function sqlitePool(options) {
|
|
|
382
411
|
);
|
|
383
412
|
}
|
|
384
413
|
if (options.singleton === true && options.sqliteConnectionFactory) {
|
|
385
|
-
return
|
|
414
|
+
return _chunkTCILLBMAcjs.createSingletonConnectionPool.call(void 0, {
|
|
386
415
|
driverType,
|
|
387
416
|
getConnection: () => options.sqliteConnectionFactory(
|
|
388
417
|
options.connectionOptions
|
|
389
418
|
)
|
|
390
419
|
});
|
|
391
420
|
}
|
|
392
|
-
return
|
|
421
|
+
return _chunkTCILLBMAcjs.createAlwaysNewConnectionPool.call(void 0, {
|
|
393
422
|
driverType,
|
|
394
423
|
getConnection: () => options.sqliteConnectionFactory(
|
|
395
424
|
options.connectionOptions
|
|
@@ -399,7 +428,7 @@ function sqlitePool(options) {
|
|
|
399
428
|
|
|
400
429
|
// src/storage/sqlite/core/schema/migrations.ts
|
|
401
430
|
var DefaultSQLiteMigratorOptions = {};
|
|
402
|
-
|
|
431
|
+
_chunkTCILLBMAcjs.registerDefaultMigratorOptions.call(void 0, "SQLite", DefaultSQLiteMigratorOptions);
|
|
403
432
|
|
|
404
433
|
// src/storage/sqlite/core/index.ts
|
|
405
434
|
var SQLiteDatabaseName = "SQLite";
|
|
@@ -486,7 +515,7 @@ var sqliteAmbientClientConnection = (options) => {
|
|
|
486
515
|
serializer,
|
|
487
516
|
errorMapper
|
|
488
517
|
} = options;
|
|
489
|
-
return
|
|
518
|
+
return _chunkTCILLBMAcjs.createAmbientConnection.call(void 0, {
|
|
490
519
|
driverType,
|
|
491
520
|
client,
|
|
492
521
|
initTransaction: _nullishCoalesce(initTransaction, () => ( ((connection) => sqliteTransaction(
|
|
@@ -515,7 +544,7 @@ var sqliteClientConnection = (options) => {
|
|
|
515
544
|
}
|
|
516
545
|
return client;
|
|
517
546
|
};
|
|
518
|
-
return
|
|
547
|
+
return _chunkTCILLBMAcjs.createConnection.call(void 0, {
|
|
519
548
|
driverType: options.driverType,
|
|
520
549
|
connect,
|
|
521
550
|
close: async () => {
|
|
@@ -548,7 +577,7 @@ var sqlitePoolClientConnection = (options) => {
|
|
|
548
577
|
}
|
|
549
578
|
return client;
|
|
550
579
|
};
|
|
551
|
-
return
|
|
580
|
+
return _chunkTCILLBMAcjs.createConnection.call(void 0, {
|
|
552
581
|
driverType: options.driverType,
|
|
553
582
|
connect,
|
|
554
583
|
close: () => client !== null ? Promise.resolve(client.release()) : Promise.resolve(),
|
|
@@ -590,7 +619,7 @@ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serial
|
|
|
590
619
|
transactionCounter.increment();
|
|
591
620
|
if (_optionalChain([options, 'optionalAccess', _12 => _12.useSavepoints])) {
|
|
592
621
|
await client.query(
|
|
593
|
-
|
|
622
|
+
_chunkTCILLBMAcjs.SQL`SAVEPOINT transaction${_chunkTCILLBMAcjs.SQL.plain(transactionCounter.level.toString())}`
|
|
594
623
|
);
|
|
595
624
|
}
|
|
596
625
|
return;
|
|
@@ -598,7 +627,7 @@ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serial
|
|
|
598
627
|
transactionCounter.increment();
|
|
599
628
|
}
|
|
600
629
|
const mode = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _13 => _13.mode]), () => ( defaultTransactionMode)), () => ( "IMMEDIATE"));
|
|
601
|
-
await client.query(
|
|
630
|
+
await client.query(_chunkTCILLBMAcjs.SQL`BEGIN ${_chunkTCILLBMAcjs.SQL.plain(mode)} TRANSACTION`);
|
|
602
631
|
},
|
|
603
632
|
commit: async function() {
|
|
604
633
|
const client = await getClient;
|
|
@@ -607,7 +636,7 @@ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serial
|
|
|
607
636
|
if (transactionCounter.level > 1) {
|
|
608
637
|
if (_optionalChain([options, 'optionalAccess', _14 => _14.useSavepoints])) {
|
|
609
638
|
await client.query(
|
|
610
|
-
|
|
639
|
+
_chunkTCILLBMAcjs.SQL`RELEASE transaction${_chunkTCILLBMAcjs.SQL.plain(transactionCounter.level.toString())}`
|
|
611
640
|
);
|
|
612
641
|
}
|
|
613
642
|
transactionCounter.decrement();
|
|
@@ -615,7 +644,7 @@ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serial
|
|
|
615
644
|
}
|
|
616
645
|
transactionCounter.reset();
|
|
617
646
|
}
|
|
618
|
-
await client.query(
|
|
647
|
+
await client.query(_chunkTCILLBMAcjs.SQL`COMMIT`);
|
|
619
648
|
} finally {
|
|
620
649
|
if (_optionalChain([options, 'optionalAccess', _15 => _15.close]))
|
|
621
650
|
await _optionalChain([options, 'optionalAccess', _16 => _16.close, 'call', _17 => _17(
|
|
@@ -632,7 +661,7 @@ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serial
|
|
|
632
661
|
return;
|
|
633
662
|
}
|
|
634
663
|
}
|
|
635
|
-
await client.query(
|
|
664
|
+
await client.query(_chunkTCILLBMAcjs.SQL`ROLLBACK`);
|
|
636
665
|
} finally {
|
|
637
666
|
if (_optionalChain([options, 'optionalAccess', _18 => _18.close]))
|
|
638
667
|
await _optionalChain([options, 'optionalAccess', _19 => _19.close, 'call', _20 => _20(
|
|
@@ -641,7 +670,7 @@ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serial
|
|
|
641
670
|
)]);
|
|
642
671
|
}
|
|
643
672
|
},
|
|
644
|
-
execute:
|
|
673
|
+
execute: _chunkTCILLBMAcjs.sqlExecutor.call(void 0, sqliteSQLExecutor(driverType, serializer), {
|
|
645
674
|
connect: () => getClient
|
|
646
675
|
}),
|
|
647
676
|
_transactionOptions: _nullishCoalesce(options, () => ( {}))
|
|
@@ -674,4 +703,4 @@ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serial
|
|
|
674
703
|
|
|
675
704
|
|
|
676
705
|
exports.mapSqliteError = mapSqliteError; exports.sqliteFormatter = sqliteFormatter; exports.sqliteExecute = sqliteExecute; exports.sqliteSQLExecutor = sqliteSQLExecutor; exports.sqliteTransaction = sqliteTransaction; exports.SQLiteConnectionString = SQLiteConnectionString; exports.parsePragmasFromConnectionString = parsePragmasFromConnectionString; exports.isSQLiteError = isSQLiteError; exports.transactionNestingCounter = transactionNestingCounter; exports.sqliteAmbientClientConnection = sqliteAmbientClientConnection; exports.sqliteClientConnection = sqliteClientConnection; exports.sqlitePoolClientConnection = sqlitePoolClientConnection; exports.sqliteConnection = sqliteConnection; exports.InMemorySQLiteDatabase = InMemorySQLiteDatabase; exports.DEFAULT_SQLITE_PRAGMA_OPTIONS = DEFAULT_SQLITE_PRAGMA_OPTIONS; exports.isInMemoryDatabase = isInMemoryDatabase; exports.sqliteAmbientConnectionPool = sqliteAmbientConnectionPool; exports.sqliteSingletonConnectionPool = sqliteSingletonConnectionPool; exports.sqliteAlwaysNewConnectionPool = sqliteAlwaysNewConnectionPool; exports.toSqlitePoolOptions = toSqlitePoolOptions; exports.sqlitePool = sqlitePool; exports.DefaultSQLiteMigratorOptions = DefaultSQLiteMigratorOptions; exports.SQLiteDatabaseName = SQLiteDatabaseName;
|
|
677
|
-
//# sourceMappingURL=chunk-
|
|
706
|
+
//# sourceMappingURL=chunk-4EG7BVCJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/Pongo/Pongo/src/packages/dumbo/dist/chunk-4EG7BVCJ.cjs","../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/pool/dualPool.ts","../src/storage/sqlite/core/pool/pool.ts","../src/storage/sqlite/core/schema/migrations.ts","../src/storage/sqlite/core/index.ts","../src/storage/sqlite/core/connections/connectionString.ts","../src/storage/sqlite/core/connections/index.ts","../src/storage/sqlite/core/transactions/index.ts"],"names":["connectionOptions","serializer"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACVA,IAAM,mBAAA,EAAqB,CAAC,KAAA,EAAA,GAAuC;AACjE,EAAA,GAAA,CACE,MAAA,WAAiB,MAAA,GACjB,OAAA,GAAU,MAAA,GACV,OAAQ,KAAA,CAAkC,KAAA,IAAS,QAAA,EACnD;AACA,IAAA,OAAQ,KAAA,CAAkC,IAAA;AAAA,EAC5C;AACA,EAAA,OAAO,KAAA,CAAA;AACT,CAAA;AAEA,IAAM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D,IAAA;AAC0B,IAAA;AACF,MAAA;AAElB,MAAA;AAC2B,QAAA;AACO,UAAA;AACJ,YAAA;AACb,cAAA;AACiD,gBAAA;AAC9D,cAAA;AACF,YAAA;AAC6B,YAAA;AAE7B,YAAA;AACF,UAAA;AAEyB,UAAA;AAC3B,QAAA;AAC8B,QAAA;AAC9B,MAAA;AACa,QAAA;AACI,UAAA;AACb,YAAA;AACF,UAAA;AACJ,MAAA;AACF,IAAA;AAC2C,IAAA;AACnB,MAAA;AAClB,MAAA;AAC2B,QAAA;AACO,UAAA;AACH,YAAA;AAC7B,YAAA;AACF,UAAA;AACF,QAAA;AAEgC,QAAA;AAChC,MAAA;AACa,QAAA;AACI,UAAA;AACb,YAAA;AACA,YAAA;AACF,UAAA;AACJ,MAAA;AACF,IAAA;AACgE,IAAA;AAC/C,MAAA;AAChB,IAAA;AACgC,IAAA;AACnC,EAAA;AAGO,EAAA;AACT;AXuiBiF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/Pongo/Pongo/src/packages/dumbo/dist/chunk-4EG7BVCJ.cjs","sourcesContent":[null,"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 { cpus } from 'os';\nimport {\n createBoundedConnectionPool,\n createSingletonConnectionPool,\n} from '../../../../core';\nimport { TaskProcessor } from '../../../../core/taskProcessing';\nimport type {\n AnySQLiteConnection,\n SQLiteConnectionFactory,\n SQLiteConnectionOptions,\n} from '../connections';\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 initTaskProcessor = new TaskProcessor({\n maxActiveTasks: 1,\n maxQueueSize: 1000,\n });\n\n const ensureDatabaseInitialized = async (\n connectionOptions: ConnectionOptions | undefined,\n retryCount = 0,\n ): Promise<void> => {\n if (databaseInitPromise !== null) {\n return databaseInitPromise;\n }\n\n return initTaskProcessor.enqueue(\n async ({ ack }) => {\n if (databaseInitPromise !== null) {\n ack();\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 ack();\n } catch (error) {\n databaseInitPromise = null;\n await initConnection.close();\n ack();\n if (retryCount < 3) {\n return ensureDatabaseInitialized(connectionOptions, retryCount + 1);\n }\n throw error;\n }\n },\n { taskGroupId: 'db-init' },\n );\n };\n\n const wrappedConnectionFactory = async (\n readonly: boolean,\n connectionOptions: ConnectionOptions | undefined,\n ): Promise<SQLiteConnectionType> => {\n await ensureDatabaseInitialized(connectionOptions);\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: () =>\n Promise.all([writerPool.close(), readerPool.close()]).then(() => {}),\n };\n};\n","import type { SQLiteConnectionString } from '..';\nimport {\n InMemorySQLiteDatabase,\n type AnySQLiteConnection,\n type SQLiteConnectionFactory,\n type SQLiteConnectionOptions,\n} from '..';\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 }) as unknown as SQLiteAmbientConnectionPool<\n SQLiteConnectionType['driverType']\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 }) as unknown as SQLiteSingletonConnectionPool<SQLiteConnectionType>;\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 }) as unknown as SQLiteAlwaysNewConnectionPool<SQLiteConnectionType>;\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","import type { DatabaseConnectionString } from '../../../all';\nimport type { SQLitePragmaOptions } from './index';\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 return pragmas;\n};\n","import {\n mapSqliteError,\n SQLiteConnectionString,\n sqliteSQLExecutor,\n type SQLiteDriverType,\n type SQLiteErrorMapper,\n} 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 { sqliteTransaction, type SQLiteTransactionMode } from '../transactions';\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 = {\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};\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};\n\nexport type SQLiteClientOptions = {\n pragmaOptions?: Partial<SQLitePragmaOptions>;\n defaultTransactionMode?: SQLiteTransactionMode;\n skipDatabasePragmas?: boolean;\n readonly?: boolean;\n};\n\nexport * from './connectionString';\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.query(\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.query(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.query(\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.query(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.query(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 // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transaction as InferTransactionFromConnection<ConnectionType>;\n };\n"]}
|