@event-driven-io/dumbo 0.13.0-beta.35 → 0.13.0-beta.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cloudflare.cjs +375 -434
- package/dist/cloudflare.cjs.map +1 -1
- package/dist/cloudflare.d.cts +36 -29
- package/dist/cloudflare.d.ts +36 -29
- package/dist/cloudflare.js +339 -434
- package/dist/cloudflare.js.map +1 -1
- package/dist/core-BG__WVn6.js +2262 -0
- package/dist/core-BG__WVn6.js.map +1 -0
- package/dist/core-BchvTX3G.js +379 -0
- package/dist/core-BchvTX3G.js.map +1 -0
- package/dist/core-CWZb0zOY.cjs +588 -0
- package/dist/core-CWZb0zOY.cjs.map +1 -0
- package/dist/core-D-smW7cm.cjs +3243 -0
- package/dist/core-D-smW7cm.cjs.map +1 -0
- package/dist/core-DXCRR5A9.cjs +450 -0
- package/dist/core-DXCRR5A9.cjs.map +1 -0
- package/dist/core-DlV8ua1P.js +451 -0
- package/dist/core-DlV8ua1P.js.map +1 -0
- package/dist/{connectionString-Dch_MIRU.d.cts → index-BDSQvDH2.d.cts} +1010 -922
- package/dist/index-BdWFmDhJ.d.cts +68 -0
- package/dist/index-BgFHGsuP.d.ts +186 -0
- package/dist/index-DaP2fTEX.d.ts +67 -0
- package/dist/index-N2ly5shv.d.cts +186 -0
- package/dist/index-S_wp0Eaf.d.cts +67 -0
- package/dist/index-cxtbLiju.d.ts +68 -0
- package/dist/{connectionString-Dch_MIRU.d.ts → index-zkszkJqP.d.ts} +1010 -922
- package/dist/index.cjs +212 -359
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -132
- package/dist/index.d.ts +3 -132
- package/dist/index.js +52 -361
- package/dist/index.js.map +1 -1
- package/dist/pg.cjs +366 -431
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +83 -72
- package/dist/pg.d.ts +83 -72
- package/dist/pg.js +320 -431
- package/dist/pg.js.map +1 -1
- package/dist/postgreSQLMetadata-BTz6vdwE.js +65 -0
- package/dist/postgreSQLMetadata-BTz6vdwE.js.map +1 -0
- package/dist/postgreSQLMetadata-WGXySO7a.cjs +118 -0
- package/dist/postgreSQLMetadata-WGXySO7a.cjs.map +1 -0
- package/dist/postgresql.cjs +25 -50
- package/dist/postgresql.d.cts +3 -61
- package/dist/postgresql.d.ts +3 -61
- package/dist/postgresql.js +4 -50
- package/dist/sqlite.cjs +30 -60
- package/dist/sqlite.d.cts +3 -190
- package/dist/sqlite.d.ts +3 -190
- package/dist/sqlite.js +4 -60
- package/dist/sqlite3.cjs +432 -380
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +79 -77
- package/dist/sqlite3.d.ts +79 -77
- package/dist/sqlite3.js +396 -378
- package/dist/sqlite3.js.map +1 -1
- package/dist/sqliteMetadata-7qBjsMBN.js +29 -0
- package/dist/sqliteMetadata-7qBjsMBN.js.map +1 -0
- package/dist/sqliteMetadata-PJTRPIZ1.cjs +46 -0
- package/dist/sqliteMetadata-PJTRPIZ1.cjs.map +1 -0
- package/package.json +12 -12
- package/dist/chunk-33P5766L.js +0 -83
- package/dist/chunk-33P5766L.js.map +0 -1
- package/dist/chunk-4MMMEDQ7.cjs +0 -2944
- package/dist/chunk-4MMMEDQ7.cjs.map +0 -1
- package/dist/chunk-6HAHSSPW.js +0 -701
- package/dist/chunk-6HAHSSPW.js.map +0 -1
- package/dist/chunk-GNH5XC6D.cjs +0 -481
- package/dist/chunk-GNH5XC6D.cjs.map +0 -1
- package/dist/chunk-H2JBS7HM.js +0 -2944
- package/dist/chunk-H2JBS7HM.js.map +0 -1
- package/dist/chunk-JIZGCEPE.cjs +0 -701
- package/dist/chunk-JIZGCEPE.cjs.map +0 -1
- package/dist/chunk-NJI6PJFZ.cjs +0 -83
- package/dist/chunk-NJI6PJFZ.cjs.map +0 -1
- package/dist/chunk-RQ3KKMTP.cjs +0 -34
- package/dist/chunk-RQ3KKMTP.cjs.map +0 -1
- package/dist/chunk-UK7MXVS2.js +0 -34
- package/dist/chunk-UK7MXVS2.js.map +0 -1
- package/dist/chunk-Y5TD53QE.js +0 -481
- package/dist/chunk-Y5TD53QE.js.map +0 -1
- package/dist/columnProcessors-Be2uMYjS.d.cts +0 -8
- package/dist/columnProcessors-D0ivj_SU.d.ts +0 -8
- package/dist/postgresql.cjs.map +0 -1
- package/dist/postgresql.js.map +0 -1
- package/dist/sqlite.cjs.map +0 -1
- package/dist/sqlite.js.map +0 -1
package/dist/sqlite3.js
CHANGED
|
@@ -1,394 +1,412 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
InMemorySQLiteDatabase,
|
|
5
|
-
SQLiteConnectionString,
|
|
6
|
-
SQLiteDatabaseName,
|
|
7
|
-
isInMemoryDatabase,
|
|
8
|
-
isSQLiteError,
|
|
9
|
-
mapSqliteError,
|
|
10
|
-
parsePragmasFromConnectionString,
|
|
11
|
-
sqliteAlwaysNewConnectionPool,
|
|
12
|
-
sqliteAmbientClientConnection,
|
|
13
|
-
sqliteAmbientConnectionPool,
|
|
14
|
-
sqliteClientConnection,
|
|
15
|
-
sqliteConnection,
|
|
16
|
-
sqliteExecute,
|
|
17
|
-
sqliteFormatter,
|
|
18
|
-
sqlitePool,
|
|
19
|
-
sqlitePoolClientConnection,
|
|
20
|
-
sqliteSQLExecutor,
|
|
21
|
-
sqliteSingletonConnectionPool,
|
|
22
|
-
sqliteTransaction,
|
|
23
|
-
toSqlitePoolOptions,
|
|
24
|
-
transactionNestingCounter
|
|
25
|
-
} from "./chunk-6HAHSSPW.js";
|
|
26
|
-
import {
|
|
27
|
-
defaultSQLiteDatabase,
|
|
28
|
-
sqliteMetadata,
|
|
29
|
-
tableExists
|
|
30
|
-
} from "./chunk-UK7MXVS2.js";
|
|
31
|
-
import {
|
|
32
|
-
BatchCommandNoChangesError,
|
|
33
|
-
JSONSerializer,
|
|
34
|
-
SQL,
|
|
35
|
-
canHandleDriverWithConnectionString,
|
|
36
|
-
dumboDatabaseDriverRegistry
|
|
37
|
-
} from "./chunk-H2JBS7HM.js";
|
|
38
|
-
|
|
39
|
-
// 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-BG__WVn6.js";
|
|
2
|
+
import { n as defaultSQLiteDatabase, r as tableExists, t as sqliteMetadata } from "./sqliteMetadata-7qBjsMBN.js";
|
|
3
|
+
import { C as mapSqliteError, S as sqliteFormatter, _ as SQLiteConnectionString, a as sqliteAmbientConnectionPool, b as sqliteExecute, c as toSqlitePoolOptions, d as isSQLiteError, f as sqliteAmbientClientConnection, g as transactionNestingCounter, h as sqlitePoolClientConnection, i as sqliteAlwaysNewConnectionPool, l as DEFAULT_SQLITE_PRAGMA_OPTIONS, m as sqliteConnection, n as DefaultSQLiteMigratorOptions, o as sqlitePool, p as sqliteClientConnection, r as isInMemoryDatabase, s as sqliteSingletonConnectionPool, t as SQLiteDatabaseName, u as InMemorySQLiteDatabase, v as parsePragmasFromConnectionString, x as sqliteSQLExecutor, y as sqliteTransaction } from "./core-DlV8ua1P.js";
|
|
40
4
|
import sqlite3 from "sqlite3";
|
|
5
|
+
import { cpus } from "os";
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
41
7
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
};
|
|
50
16
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}] : []
|
|
62
42
|
];
|
|
43
|
+
const buildDatabasePragmaStatements = (pragmas) => [{
|
|
44
|
+
pragma: "journal_mode",
|
|
45
|
+
value: pragmas.journal_mode
|
|
46
|
+
}];
|
|
63
47
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
+
});
|
|
74
59
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
else resolve(row?.[pragma] ?? "");
|
|
81
|
-
}
|
|
82
|
-
);
|
|
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
|
+
});
|
|
83
65
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
results.push({ rowCount: result.length, rows: result });
|
|
243
|
-
}
|
|
244
|
-
return results;
|
|
245
|
-
} catch (error) {
|
|
246
|
-
throw mapSqliteError(error);
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
command: async (sql, options2) => {
|
|
250
|
-
try {
|
|
251
|
-
const { query, params } = sqliteFormatter.format(sql, {
|
|
252
|
-
serializer
|
|
253
|
-
});
|
|
254
|
-
return await executeCommand(
|
|
255
|
-
query,
|
|
256
|
-
params,
|
|
257
|
-
options2
|
|
258
|
-
);
|
|
259
|
-
} catch (error) {
|
|
260
|
-
throw mapSqliteError(error);
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
batchCommand: async (sqls, options2) => {
|
|
264
|
-
try {
|
|
265
|
-
const results = [];
|
|
266
|
-
for (let i = 0; i < sqls.length; i++) {
|
|
267
|
-
const { query, params } = sqliteFormatter.format(sqls[i], {
|
|
268
|
-
serializer
|
|
269
|
-
});
|
|
270
|
-
const result = await executeCommand(
|
|
271
|
-
query,
|
|
272
|
-
params,
|
|
273
|
-
options2
|
|
274
|
-
);
|
|
275
|
-
results.push(result);
|
|
276
|
-
if (options2?.assertChanges && (result.rowCount ?? 0) === 0) {
|
|
277
|
-
throw new BatchCommandNoChangesError(i);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return results;
|
|
281
|
-
} catch (error) {
|
|
282
|
-
throw mapSqliteError(error);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
};
|
|
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
|
+
};
|
|
286
224
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
+
}
|
|
306
244
|
};
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
connectionOptions: options,
|
|
320
|
-
serializer: options.serializer
|
|
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
|
|
321
257
|
});
|
|
322
258
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
)
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
+
};
|
|
343
299
|
};
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
+
};
|
|
354
365
|
};
|
|
355
|
-
|
|
356
|
-
|
|
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
|
+
});
|
|
357
389
|
};
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
SQLiteConnectionString,
|
|
365
|
-
SQLiteDatabaseName,
|
|
366
|
-
checkConnection,
|
|
367
|
-
defaultSQLiteDatabase,
|
|
368
|
-
isInMemoryDatabase,
|
|
369
|
-
isSQLiteError,
|
|
370
|
-
mapSqliteError,
|
|
371
|
-
parsePragmasFromConnectionString,
|
|
372
|
-
sqlite3Client,
|
|
373
|
-
sqlite3Connection,
|
|
374
|
-
sqlite3DumboDriver,
|
|
375
|
-
sqlite3Pool,
|
|
376
|
-
sqliteAlwaysNewConnectionPool,
|
|
377
|
-
sqliteAmbientClientConnection,
|
|
378
|
-
sqliteAmbientConnectionPool,
|
|
379
|
-
sqliteClientConnection,
|
|
380
|
-
sqliteConnection,
|
|
381
|
-
sqliteExecute,
|
|
382
|
-
sqliteFormatter,
|
|
383
|
-
sqliteMetadata,
|
|
384
|
-
sqlitePool,
|
|
385
|
-
sqlitePoolClientConnection,
|
|
386
|
-
sqliteSQLExecutor,
|
|
387
|
-
sqliteSingletonConnectionPool,
|
|
388
|
-
sqliteTransaction,
|
|
389
|
-
tableExists,
|
|
390
|
-
toSqlitePoolOptions,
|
|
391
|
-
transactionNestingCounter,
|
|
392
|
-
useSqlite3DumboDriver
|
|
390
|
+
const tryParseConnectionString = (connectionString) => {
|
|
391
|
+
try {
|
|
392
|
+
return SQLiteConnectionString(connectionString);
|
|
393
|
+
} catch {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
393
396
|
};
|
|
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
|
|
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 };
|
|
394
412
|
//# sourceMappingURL=sqlite3.js.map
|