azure-mock 2.20.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +201 -201
  2. package/dist/better-sqlite3-CtLaF97z-DWR9uC3b.js +129 -0
  3. package/dist/chunk-2X2C5D2I-dJHtPFe9-DxsO-1YF.js +4026 -0
  4. package/dist/d1-pK2J-_yx-BoQTXsTa.js +185 -0
  5. package/dist/dialect-pBb6Cg_F-xgpUtfmk.js +570 -0
  6. package/dist/dist-C481edUb-CHbOkeXH.js +10131 -0
  7. package/dist/dist-DUzzleZr-DxHmeYjp.js +2 -0
  8. package/dist/index.d.ts +21 -21
  9. package/dist/index.js +20396 -18921
  10. package/dist/libsql-Nq-S0r5x-d2dAzhgO.js +240 -0
  11. package/dist/logger-TIsK7375-CLNNa25D.js +652 -0
  12. package/dist/migrator-B9kYwLqO-4g9JX3_v.js +8 -0
  13. package/dist/migrator-BfTfJctM-DrNlb1BS.js +8 -0
  14. package/dist/migrator-BjoW0_3j-CD-XdZ5a.js +8 -0
  15. package/dist/migrator-CWWlo_Jk-C4Hw4PPN.js +8 -0
  16. package/dist/migrator-CpiXRkls-COYfhljd.js +24 -0
  17. package/dist/migrator-CtqJkLVI-D1lU6ZV0.js +8 -0
  18. package/dist/migrator-CxcBjmET-Dcd21VIf.js +8 -0
  19. package/dist/migrator-Cyhbhxo_-Bh7sF0R3.js +21 -0
  20. package/dist/migrator-DG1mWUoR-DVfkqn_v.js +31 -0
  21. package/dist/migrator-DrWmHwY2-YjAfotd7.js +8 -0
  22. package/dist/migrator-WAPonQxA-CRvJJhKG.js +8 -0
  23. package/dist/migrator-Zdh8WMMx-gsmNXspd.js +8 -0
  24. package/dist/migrator-xRJ6NOTS-SsAuB-Gi.js +24 -0
  25. package/dist/migrator-xbWwvFYF-BjyVdQS8.js +8 -0
  26. package/dist/mysql2-DkoPEsRu-BMwVSCmY.js +251 -0
  27. package/dist/neon-serverless-BEVFA7yv-DGSPAG1z.js +205 -0
  28. package/dist/node-postgres-DQA7bEhW-CkM_cVLD.js +216 -0
  29. package/dist/nodefs-Bc8b83o_-DetP9qUa.js +24 -0
  30. package/dist/opfs-ahp-DbstDvx--CHskKtzG.js +365 -0
  31. package/dist/pg-ylxXyvKj-Hm8vcZoi.js +279 -0
  32. package/dist/pglite-CPs4w-D9-DHOg0D8W.js +179 -0
  33. package/dist/pglite-DMWgTUE6-BOIRUWUT.js +2 -0
  34. package/dist/planetscale-serverless-DUMheN-f-Dyc_W6V_.js +172 -0
  35. package/dist/query-builder-CLJAKedv-DTZiP7B6.js +1715 -0
  36. package/dist/query-builder-CT3_liD0-hhg5kRTk.js +1347 -0
  37. package/dist/session-BOEirggu-DTmpyU_x.js +2485 -0
  38. package/dist/session-CAUQtT0A-BoVK2x7A.js +745 -0
  39. package/dist/session-Cjeygn2Z-BO0mi6pq.js +989 -0
  40. package/dist/singlestore-Cdlo23hW-BuFJ4Zqb.js +1647 -0
  41. package/dist/sql-CNZp2yLp-Bwugq384.js +611 -0
  42. package/dist/sqlite-proxy-BgUfVEbZ-CsSkc-_K.js +190 -0
  43. package/dist/src-LcyXhCXE-C_vKJiLK.js +1920 -0
  44. package/dist/vercel-postgres-BYmFKsTS-CpV2usun.js +203 -0
  45. package/package.json +7 -8
@@ -0,0 +1,989 @@
1
+ import { C as sql, b as is, d as Table, g as entityKind, h as WithSubquery, m as ViewBaseConfig, n as Columns, r as Param, s as SQL, u as Subquery } from "./sql-CNZp2yLp-Bwugq384.js";
2
+ import { D as haveSameKeys, E as hashQuery, F as orderSelectedFields, N as mapUpdateSet, T as getTableLikeName, f as SelectionProxyHandler, i as DrizzleQueryError, j as mapRelationalRow, o as NoopCache, p as TransactionRollbackError, r as DrizzleError, u as QueryPromise } from "./logger-TIsK7375-CLNNa25D.js";
3
+ import { a as SQLiteTable, o as SQLiteViewBase, r as SQLiteSelectBuilder, s as extractUsedTable, t as QueryBuilder } from "./query-builder-CT3_liD0-hhg5kRTk.js";
4
+ //#region ../db/dist/session-Cjeygn2Z.js
5
+ var SQLiteDeleteBase = class extends QueryPromise {
6
+ constructor(table, session, dialect, withList) {
7
+ super();
8
+ this.table = table;
9
+ this.session = session;
10
+ this.dialect = dialect;
11
+ this.config = {
12
+ table,
13
+ withList
14
+ };
15
+ }
16
+ static [entityKind] = "SQLiteDelete";
17
+ /** @internal */
18
+ config;
19
+ /**
20
+ * Adds a `where` clause to the query.
21
+ *
22
+ * Calling this method will delete only those rows that fulfill a specified condition.
23
+ *
24
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
25
+ *
26
+ * @param where the `where` clause.
27
+ *
28
+ * @example
29
+ * You can use conditional operators and `sql function` to filter the rows to be deleted.
30
+ *
31
+ * ```ts
32
+ * // Delete all cars with green color
33
+ * db.delete(cars).where(eq(cars.color, 'green'));
34
+ * // or
35
+ * db.delete(cars).where(sql`${cars.color} = 'green'`)
36
+ * ```
37
+ *
38
+ * You can logically combine conditional operators with `and()` and `or()` operators:
39
+ *
40
+ * ```ts
41
+ * // Delete all BMW cars with a green color
42
+ * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
43
+ *
44
+ * // Delete all cars with the green or blue color
45
+ * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
46
+ * ```
47
+ */
48
+ where(where) {
49
+ this.config.where = where;
50
+ return this;
51
+ }
52
+ orderBy(...columns) {
53
+ if (typeof columns[0] === "function") {
54
+ const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
55
+ sqlAliasedBehavior: "alias",
56
+ sqlBehavior: "sql"
57
+ })));
58
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
59
+ this.config.orderBy = orderByArray;
60
+ } else {
61
+ const orderByArray = columns;
62
+ this.config.orderBy = orderByArray;
63
+ }
64
+ return this;
65
+ }
66
+ limit(limit) {
67
+ this.config.limit = limit;
68
+ return this;
69
+ }
70
+ returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
71
+ this.config.returning = orderSelectedFields(fields);
72
+ return this;
73
+ }
74
+ /** @internal */
75
+ getSQL() {
76
+ return this.dialect.buildDeleteQuery(this.config);
77
+ }
78
+ toSQL() {
79
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
80
+ return rest;
81
+ }
82
+ /** @internal */
83
+ _prepare(isOneTimeQuery = true) {
84
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](this.dialect.sqlToQuery(this.getSQL()), this.config.returning, this.config.returning ? "all" : "run", true, void 0, {
85
+ type: "delete",
86
+ tables: extractUsedTable(this.config.table)
87
+ });
88
+ }
89
+ prepare() {
90
+ return this._prepare(false);
91
+ }
92
+ run = (placeholderValues) => {
93
+ return this._prepare().run(placeholderValues);
94
+ };
95
+ all = (placeholderValues) => {
96
+ return this._prepare().all(placeholderValues);
97
+ };
98
+ get = (placeholderValues) => {
99
+ return this._prepare().get(placeholderValues);
100
+ };
101
+ values = (placeholderValues) => {
102
+ return this._prepare().values(placeholderValues);
103
+ };
104
+ async execute(placeholderValues) {
105
+ return this._prepare().execute(placeholderValues);
106
+ }
107
+ $dynamic() {
108
+ return this;
109
+ }
110
+ };
111
+ var SQLiteInsertBuilder = class {
112
+ constructor(table, session, dialect, withList) {
113
+ this.table = table;
114
+ this.session = session;
115
+ this.dialect = dialect;
116
+ this.withList = withList;
117
+ }
118
+ static [entityKind] = "SQLiteInsertBuilder";
119
+ values(values) {
120
+ values = Array.isArray(values) ? values : [values];
121
+ if (values.length === 0) throw new Error("values() must be called with at least one value");
122
+ const mappedValues = values.map((entry) => {
123
+ const result = {};
124
+ const cols = this.table[Table.Symbol.Columns];
125
+ for (const colKey of Object.keys(entry)) {
126
+ const colValue = entry[colKey];
127
+ result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
128
+ }
129
+ return result;
130
+ });
131
+ return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
132
+ }
133
+ select(selectQuery) {
134
+ const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
135
+ if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) throw new Error("Insert select error: selected fields are not the same or are in a different order compared to the table definition");
136
+ return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
137
+ }
138
+ };
139
+ var SQLiteInsertBase = class extends QueryPromise {
140
+ constructor(table, values, session, dialect, withList, select) {
141
+ super();
142
+ this.session = session;
143
+ this.dialect = dialect;
144
+ this.config = {
145
+ table,
146
+ values,
147
+ withList,
148
+ select
149
+ };
150
+ }
151
+ static [entityKind] = "SQLiteInsert";
152
+ /** @internal */
153
+ config;
154
+ returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
155
+ this.config.returning = orderSelectedFields(fields);
156
+ return this;
157
+ }
158
+ /**
159
+ * Adds an `on conflict do nothing` clause to the query.
160
+ *
161
+ * Calling this method simply avoids inserting a row as its alternative action.
162
+ *
163
+ * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
164
+ *
165
+ * @param config The `target` and `where` clauses.
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * // Insert one row and cancel the insert if there's a conflict
170
+ * await db.insert(cars)
171
+ * .values({ id: 1, brand: 'BMW' })
172
+ * .onConflictDoNothing();
173
+ *
174
+ * // Explicitly specify conflict target
175
+ * await db.insert(cars)
176
+ * .values({ id: 1, brand: 'BMW' })
177
+ * .onConflictDoNothing({ target: cars.id });
178
+ * ```
179
+ */
180
+ onConflictDoNothing(config = {}) {
181
+ if (!this.config.onConflict) this.config.onConflict = [];
182
+ if (config.target === void 0) this.config.onConflict.push(sql` on conflict do nothing`);
183
+ else {
184
+ const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
185
+ const whereSql = config.where ? sql` where ${config.where}` : sql``;
186
+ this.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);
187
+ }
188
+ return this;
189
+ }
190
+ /**
191
+ * Adds an `on conflict do update` clause to the query.
192
+ *
193
+ * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
194
+ *
195
+ * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
196
+ *
197
+ * @param config The `target`, `set` and `where` clauses.
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * // Update the row if there's a conflict
202
+ * await db.insert(cars)
203
+ * .values({ id: 1, brand: 'BMW' })
204
+ * .onConflictDoUpdate({
205
+ * target: cars.id,
206
+ * set: { brand: 'Porsche' }
207
+ * });
208
+ *
209
+ * // Upsert with 'where' clause
210
+ * await db.insert(cars)
211
+ * .values({ id: 1, brand: 'BMW' })
212
+ * .onConflictDoUpdate({
213
+ * target: cars.id,
214
+ * set: { brand: 'newBMW' },
215
+ * where: sql`${cars.createdAt} > '2023-01-01'::date`,
216
+ * });
217
+ * ```
218
+ */
219
+ onConflictDoUpdate(config) {
220
+ if (config.where && (config.targetWhere || config.setWhere)) throw new Error("You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.");
221
+ if (!this.config.onConflict) this.config.onConflict = [];
222
+ const whereSql = config.where ? sql` where ${config.where}` : void 0;
223
+ const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
224
+ const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
225
+ const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
226
+ const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
227
+ this.config.onConflict.push(sql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`);
228
+ return this;
229
+ }
230
+ /** @internal */
231
+ getSQL() {
232
+ return this.dialect.buildInsertQuery(this.config);
233
+ }
234
+ toSQL() {
235
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
236
+ return rest;
237
+ }
238
+ /** @internal */
239
+ _prepare(isOneTimeQuery = true) {
240
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](this.dialect.sqlToQuery(this.getSQL()), this.config.returning, this.config.returning ? "all" : "run", true, void 0, {
241
+ type: "insert",
242
+ tables: extractUsedTable(this.config.table)
243
+ });
244
+ }
245
+ prepare() {
246
+ return this._prepare(false);
247
+ }
248
+ run = (placeholderValues) => {
249
+ return this._prepare().run(placeholderValues);
250
+ };
251
+ all = (placeholderValues) => {
252
+ return this._prepare().all(placeholderValues);
253
+ };
254
+ get = (placeholderValues) => {
255
+ return this._prepare().get(placeholderValues);
256
+ };
257
+ values = (placeholderValues) => {
258
+ return this._prepare().values(placeholderValues);
259
+ };
260
+ async execute() {
261
+ return this.config.returning ? this.all() : this.run();
262
+ }
263
+ $dynamic() {
264
+ return this;
265
+ }
266
+ };
267
+ var SQLiteUpdateBuilder = class {
268
+ constructor(table, session, dialect, withList) {
269
+ this.table = table;
270
+ this.session = session;
271
+ this.dialect = dialect;
272
+ this.withList = withList;
273
+ }
274
+ static [entityKind] = "SQLiteUpdateBuilder";
275
+ set(values) {
276
+ return new SQLiteUpdateBase(this.table, mapUpdateSet(this.table, values), this.session, this.dialect, this.withList);
277
+ }
278
+ };
279
+ var SQLiteUpdateBase = class extends QueryPromise {
280
+ constructor(table, set, session, dialect, withList) {
281
+ super();
282
+ this.session = session;
283
+ this.dialect = dialect;
284
+ this.config = {
285
+ set,
286
+ table,
287
+ withList,
288
+ joins: []
289
+ };
290
+ }
291
+ static [entityKind] = "SQLiteUpdate";
292
+ /** @internal */
293
+ config;
294
+ from(source) {
295
+ this.config.from = source;
296
+ return this;
297
+ }
298
+ createJoin(joinType) {
299
+ return (table, on) => {
300
+ const tableName = getTableLikeName(table);
301
+ if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
302
+ if (typeof on === "function") {
303
+ const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
304
+ on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
305
+ sqlAliasedBehavior: "sql",
306
+ sqlBehavior: "sql"
307
+ })), from && new Proxy(from, new SelectionProxyHandler({
308
+ sqlAliasedBehavior: "sql",
309
+ sqlBehavior: "sql"
310
+ })));
311
+ }
312
+ this.config.joins.push({
313
+ on,
314
+ table,
315
+ joinType,
316
+ alias: tableName
317
+ });
318
+ return this;
319
+ };
320
+ }
321
+ leftJoin = this.createJoin("left");
322
+ rightJoin = this.createJoin("right");
323
+ innerJoin = this.createJoin("inner");
324
+ fullJoin = this.createJoin("full");
325
+ /**
326
+ * Adds a 'where' clause to the query.
327
+ *
328
+ * Calling this method will update only those rows that fulfill a specified condition.
329
+ *
330
+ * See docs: {@link https://orm.drizzle.team/docs/update}
331
+ *
332
+ * @param where the 'where' clause.
333
+ *
334
+ * @example
335
+ * You can use conditional operators and `sql function` to filter the rows to be updated.
336
+ *
337
+ * ```ts
338
+ * // Update all cars with green color
339
+ * db.update(cars).set({ color: 'red' })
340
+ * .where(eq(cars.color, 'green'));
341
+ * // or
342
+ * db.update(cars).set({ color: 'red' })
343
+ * .where(sql`${cars.color} = 'green'`)
344
+ * ```
345
+ *
346
+ * You can logically combine conditional operators with `and()` and `or()` operators:
347
+ *
348
+ * ```ts
349
+ * // Update all BMW cars with a green color
350
+ * db.update(cars).set({ color: 'red' })
351
+ * .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
352
+ *
353
+ * // Update all cars with the green or blue color
354
+ * db.update(cars).set({ color: 'red' })
355
+ * .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
356
+ * ```
357
+ */
358
+ where(where) {
359
+ this.config.where = where;
360
+ return this;
361
+ }
362
+ orderBy(...columns) {
363
+ if (typeof columns[0] === "function") {
364
+ const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
365
+ sqlAliasedBehavior: "alias",
366
+ sqlBehavior: "sql"
367
+ })));
368
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
369
+ this.config.orderBy = orderByArray;
370
+ } else {
371
+ const orderByArray = columns;
372
+ this.config.orderBy = orderByArray;
373
+ }
374
+ return this;
375
+ }
376
+ limit(limit) {
377
+ this.config.limit = limit;
378
+ return this;
379
+ }
380
+ returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
381
+ this.config.returning = orderSelectedFields(fields);
382
+ return this;
383
+ }
384
+ /** @internal */
385
+ getSQL() {
386
+ return this.dialect.buildUpdateQuery(this.config);
387
+ }
388
+ toSQL() {
389
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
390
+ return rest;
391
+ }
392
+ /** @internal */
393
+ _prepare(isOneTimeQuery = true) {
394
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](this.dialect.sqlToQuery(this.getSQL()), this.config.returning, this.config.returning ? "all" : "run", true, void 0, {
395
+ type: "insert",
396
+ tables: extractUsedTable(this.config.table)
397
+ });
398
+ }
399
+ prepare() {
400
+ return this._prepare(false);
401
+ }
402
+ run = (placeholderValues) => {
403
+ return this._prepare().run(placeholderValues);
404
+ };
405
+ all = (placeholderValues) => {
406
+ return this._prepare().all(placeholderValues);
407
+ };
408
+ get = (placeholderValues) => {
409
+ return this._prepare().get(placeholderValues);
410
+ };
411
+ values = (placeholderValues) => {
412
+ return this._prepare().values(placeholderValues);
413
+ };
414
+ async execute() {
415
+ return this.config.returning ? this.all() : this.run();
416
+ }
417
+ $dynamic() {
418
+ return this;
419
+ }
420
+ };
421
+ var SQLiteCountBuilder = class SQLiteCountBuilder extends SQL {
422
+ constructor(params) {
423
+ super(SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
424
+ this.params = params;
425
+ this.session = params.session;
426
+ this.sql = SQLiteCountBuilder.buildCount(params.source, params.filters);
427
+ }
428
+ sql;
429
+ static [entityKind] = "SQLiteCountBuilderAsync";
430
+ [Symbol.toStringTag] = "SQLiteCountBuilderAsync";
431
+ session;
432
+ static buildEmbeddedCount(source, filters) {
433
+ return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
434
+ }
435
+ static buildCount(source, filters) {
436
+ return sql`select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters}`;
437
+ }
438
+ then(onfulfilled, onrejected) {
439
+ return Promise.resolve(this.session.count(this.sql)).then(onfulfilled, onrejected);
440
+ }
441
+ catch(onRejected) {
442
+ return this.then(void 0, onRejected);
443
+ }
444
+ finally(onFinally) {
445
+ return this.then((value) => {
446
+ onFinally?.();
447
+ return value;
448
+ }, (reason) => {
449
+ onFinally?.();
450
+ throw reason;
451
+ });
452
+ }
453
+ };
454
+ var RelationalQueryBuilder = class {
455
+ constructor(mode, fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
456
+ this.mode = mode;
457
+ this.fullSchema = fullSchema;
458
+ this.schema = schema;
459
+ this.tableNamesMap = tableNamesMap;
460
+ this.table = table;
461
+ this.tableConfig = tableConfig;
462
+ this.dialect = dialect;
463
+ this.session = session;
464
+ }
465
+ static [entityKind] = "SQLiteAsyncRelationalQueryBuilder";
466
+ findMany(config) {
467
+ return this.mode === "sync" ? new SQLiteSyncRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? config : {}, "many") : new SQLiteRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? config : {}, "many");
468
+ }
469
+ findFirst(config) {
470
+ return this.mode === "sync" ? new SQLiteSyncRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? {
471
+ ...config,
472
+ limit: 1
473
+ } : { limit: 1 }, "first") : new SQLiteRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? {
474
+ ...config,
475
+ limit: 1
476
+ } : { limit: 1 }, "first");
477
+ }
478
+ };
479
+ var SQLiteRelationalQuery = class extends QueryPromise {
480
+ constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
481
+ super();
482
+ this.fullSchema = fullSchema;
483
+ this.schema = schema;
484
+ this.tableNamesMap = tableNamesMap;
485
+ this.table = table;
486
+ this.tableConfig = tableConfig;
487
+ this.dialect = dialect;
488
+ this.session = session;
489
+ this.config = config;
490
+ this.mode = mode;
491
+ }
492
+ static [entityKind] = "SQLiteAsyncRelationalQuery";
493
+ /** @internal */
494
+ mode;
495
+ /** @internal */
496
+ getSQL() {
497
+ return this.dialect.buildRelationalQuery({
498
+ fullSchema: this.fullSchema,
499
+ schema: this.schema,
500
+ tableNamesMap: this.tableNamesMap,
501
+ table: this.table,
502
+ tableConfig: this.tableConfig,
503
+ queryConfig: this.config,
504
+ tableAlias: this.tableConfig.tsName
505
+ }).sql;
506
+ }
507
+ /** @internal */
508
+ _prepare(isOneTimeQuery = false) {
509
+ const { query, builtQuery } = this._toSQL();
510
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](builtQuery, void 0, this.mode === "first" ? "get" : "all", true, (rawRows, mapColumnValue) => {
511
+ const rows = rawRows.map((row) => mapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue));
512
+ if (this.mode === "first") return rows[0];
513
+ return rows;
514
+ });
515
+ }
516
+ prepare() {
517
+ return this._prepare(false);
518
+ }
519
+ _toSQL() {
520
+ const query = this.dialect.buildRelationalQuery({
521
+ fullSchema: this.fullSchema,
522
+ schema: this.schema,
523
+ tableNamesMap: this.tableNamesMap,
524
+ table: this.table,
525
+ tableConfig: this.tableConfig,
526
+ queryConfig: this.config,
527
+ tableAlias: this.tableConfig.tsName
528
+ });
529
+ return {
530
+ query,
531
+ builtQuery: this.dialect.sqlToQuery(query.sql)
532
+ };
533
+ }
534
+ toSQL() {
535
+ return this._toSQL().builtQuery;
536
+ }
537
+ /** @internal */
538
+ executeRaw() {
539
+ if (this.mode === "first") return this._prepare(false).get();
540
+ return this._prepare(false).all();
541
+ }
542
+ async execute() {
543
+ return this.executeRaw();
544
+ }
545
+ };
546
+ var SQLiteSyncRelationalQuery = class extends SQLiteRelationalQuery {
547
+ static [entityKind] = "SQLiteSyncRelationalQuery";
548
+ sync() {
549
+ return this.executeRaw();
550
+ }
551
+ };
552
+ var SQLiteRaw = class extends QueryPromise {
553
+ constructor(execute, getSQL, action, dialect, mapBatchResult) {
554
+ super();
555
+ this.execute = execute;
556
+ this.getSQL = getSQL;
557
+ this.dialect = dialect;
558
+ this.mapBatchResult = mapBatchResult;
559
+ this.config = { action };
560
+ }
561
+ static [entityKind] = "SQLiteRaw";
562
+ /** @internal */
563
+ config;
564
+ getQuery() {
565
+ return {
566
+ ...this.dialect.sqlToQuery(this.getSQL()),
567
+ method: this.config.action
568
+ };
569
+ }
570
+ mapResult(result, isFromBatch) {
571
+ return isFromBatch ? this.mapBatchResult(result) : result;
572
+ }
573
+ _prepare() {
574
+ return this;
575
+ }
576
+ /** @internal */
577
+ isResponseInArrayMode() {
578
+ return false;
579
+ }
580
+ };
581
+ var BaseSQLiteDatabase = class {
582
+ constructor(resultKind, dialect, session, schema) {
583
+ this.resultKind = resultKind;
584
+ this.dialect = dialect;
585
+ this.session = session;
586
+ this._ = schema ? {
587
+ schema: schema.schema,
588
+ fullSchema: schema.fullSchema,
589
+ tableNamesMap: schema.tableNamesMap
590
+ } : {
591
+ schema: void 0,
592
+ fullSchema: {},
593
+ tableNamesMap: {}
594
+ };
595
+ this.query = {};
596
+ const query = this.query;
597
+ if (this._.schema) for (const [tableName, columns] of Object.entries(this._.schema)) query[tableName] = new RelationalQueryBuilder(resultKind, schema.fullSchema, this._.schema, this._.tableNamesMap, schema.fullSchema[tableName], columns, dialect, session);
598
+ this.$cache = { invalidate: async (_params) => {} };
599
+ }
600
+ static [entityKind] = "BaseSQLiteDatabase";
601
+ query;
602
+ /**
603
+ * Creates a subquery that defines a temporary named result set as a CTE.
604
+ *
605
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
606
+ *
607
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
608
+ *
609
+ * @param alias The alias for the subquery.
610
+ *
611
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
612
+ *
613
+ * @example
614
+ *
615
+ * ```ts
616
+ * // Create a subquery with alias 'sq' and use it in the select query
617
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
618
+ *
619
+ * const result = await db.with(sq).select().from(sq);
620
+ * ```
621
+ *
622
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
623
+ *
624
+ * ```ts
625
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
626
+ * const sq = db.$with('sq').as(db.select({
627
+ * name: sql<string>`upper(${users.name})`.as('name'),
628
+ * })
629
+ * .from(users));
630
+ *
631
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
632
+ * ```
633
+ */
634
+ $with = (alias, selection) => {
635
+ const self = this;
636
+ const as = (qb) => {
637
+ if (typeof qb === "function") qb = qb(new QueryBuilder(self.dialect));
638
+ return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
639
+ alias,
640
+ sqlAliasedBehavior: "alias",
641
+ sqlBehavior: "error"
642
+ }));
643
+ };
644
+ return { as };
645
+ };
646
+ $count(source, filters) {
647
+ return new SQLiteCountBuilder({
648
+ source,
649
+ filters,
650
+ session: this.session
651
+ });
652
+ }
653
+ /**
654
+ * Incorporates a previously defined CTE (using `$with`) into the main query.
655
+ *
656
+ * This method allows the main query to reference a temporary named result set.
657
+ *
658
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
659
+ *
660
+ * @param queries The CTEs to incorporate into the main query.
661
+ *
662
+ * @example
663
+ *
664
+ * ```ts
665
+ * // Define a subquery 'sq' as a CTE using $with
666
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
667
+ *
668
+ * // Incorporate the CTE 'sq' into the main query and select from it
669
+ * const result = await db.with(sq).select().from(sq);
670
+ * ```
671
+ */
672
+ with(...queries) {
673
+ const self = this;
674
+ function select(fields) {
675
+ return new SQLiteSelectBuilder({
676
+ fields: fields ?? void 0,
677
+ session: self.session,
678
+ dialect: self.dialect,
679
+ withList: queries
680
+ });
681
+ }
682
+ function selectDistinct(fields) {
683
+ return new SQLiteSelectBuilder({
684
+ fields: fields ?? void 0,
685
+ session: self.session,
686
+ dialect: self.dialect,
687
+ withList: queries,
688
+ distinct: true
689
+ });
690
+ }
691
+ function update(table) {
692
+ return new SQLiteUpdateBuilder(table, self.session, self.dialect, queries);
693
+ }
694
+ function insert(into) {
695
+ return new SQLiteInsertBuilder(into, self.session, self.dialect, queries);
696
+ }
697
+ function delete_(from) {
698
+ return new SQLiteDeleteBase(from, self.session, self.dialect, queries);
699
+ }
700
+ return {
701
+ select,
702
+ selectDistinct,
703
+ update,
704
+ insert,
705
+ delete: delete_
706
+ };
707
+ }
708
+ select(fields) {
709
+ return new SQLiteSelectBuilder({
710
+ fields: fields ?? void 0,
711
+ session: this.session,
712
+ dialect: this.dialect
713
+ });
714
+ }
715
+ selectDistinct(fields) {
716
+ return new SQLiteSelectBuilder({
717
+ fields: fields ?? void 0,
718
+ session: this.session,
719
+ dialect: this.dialect,
720
+ distinct: true
721
+ });
722
+ }
723
+ /**
724
+ * Creates an update query.
725
+ *
726
+ * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
727
+ *
728
+ * Use `.set()` method to specify which values to update.
729
+ *
730
+ * See docs: {@link https://orm.drizzle.team/docs/update}
731
+ *
732
+ * @param table The table to update.
733
+ *
734
+ * @example
735
+ *
736
+ * ```ts
737
+ * // Update all rows in the 'cars' table
738
+ * await db.update(cars).set({ color: 'red' });
739
+ *
740
+ * // Update rows with filters and conditions
741
+ * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
742
+ *
743
+ * // Update with returning clause
744
+ * const updatedCar: Car[] = await db.update(cars)
745
+ * .set({ color: 'red' })
746
+ * .where(eq(cars.id, 1))
747
+ * .returning();
748
+ * ```
749
+ */
750
+ update(table) {
751
+ return new SQLiteUpdateBuilder(table, this.session, this.dialect);
752
+ }
753
+ $cache;
754
+ /**
755
+ * Creates an insert query.
756
+ *
757
+ * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
758
+ *
759
+ * See docs: {@link https://orm.drizzle.team/docs/insert}
760
+ *
761
+ * @param table The table to insert into.
762
+ *
763
+ * @example
764
+ *
765
+ * ```ts
766
+ * // Insert one row
767
+ * await db.insert(cars).values({ brand: 'BMW' });
768
+ *
769
+ * // Insert multiple rows
770
+ * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
771
+ *
772
+ * // Insert with returning clause
773
+ * const insertedCar: Car[] = await db.insert(cars)
774
+ * .values({ brand: 'BMW' })
775
+ * .returning();
776
+ * ```
777
+ */
778
+ insert(into) {
779
+ return new SQLiteInsertBuilder(into, this.session, this.dialect);
780
+ }
781
+ /**
782
+ * Creates a delete query.
783
+ *
784
+ * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
785
+ *
786
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
787
+ *
788
+ * @param table The table to delete from.
789
+ *
790
+ * @example
791
+ *
792
+ * ```ts
793
+ * // Delete all rows in the 'cars' table
794
+ * await db.delete(cars);
795
+ *
796
+ * // Delete rows with filters and conditions
797
+ * await db.delete(cars).where(eq(cars.color, 'green'));
798
+ *
799
+ * // Delete with returning clause
800
+ * const deletedCar: Car[] = await db.delete(cars)
801
+ * .where(eq(cars.id, 1))
802
+ * .returning();
803
+ * ```
804
+ */
805
+ delete(from) {
806
+ return new SQLiteDeleteBase(from, this.session, this.dialect);
807
+ }
808
+ run(query) {
809
+ const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
810
+ if (this.resultKind === "async") return new SQLiteRaw(async () => this.session.run(sequel), () => sequel, "run", this.dialect, this.session.extractRawRunValueFromBatchResult.bind(this.session));
811
+ return this.session.run(sequel);
812
+ }
813
+ all(query) {
814
+ const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
815
+ if (this.resultKind === "async") return new SQLiteRaw(async () => this.session.all(sequel), () => sequel, "all", this.dialect, this.session.extractRawAllValueFromBatchResult.bind(this.session));
816
+ return this.session.all(sequel);
817
+ }
818
+ get(query) {
819
+ const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
820
+ if (this.resultKind === "async") return new SQLiteRaw(async () => this.session.get(sequel), () => sequel, "get", this.dialect, this.session.extractRawGetValueFromBatchResult.bind(this.session));
821
+ return this.session.get(sequel);
822
+ }
823
+ values(query) {
824
+ const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
825
+ if (this.resultKind === "async") return new SQLiteRaw(async () => this.session.values(sequel), () => sequel, "values", this.dialect, this.session.extractRawValuesValueFromBatchResult.bind(this.session));
826
+ return this.session.values(sequel);
827
+ }
828
+ transaction(transaction, config) {
829
+ return this.session.transaction(transaction, config);
830
+ }
831
+ };
832
+ var ExecuteResultSync = class extends QueryPromise {
833
+ constructor(resultCb) {
834
+ super();
835
+ this.resultCb = resultCb;
836
+ }
837
+ static [entityKind] = "ExecuteResultSync";
838
+ async execute() {
839
+ return this.resultCb();
840
+ }
841
+ sync() {
842
+ return this.resultCb();
843
+ }
844
+ };
845
+ var SQLitePreparedQuery = class {
846
+ constructor(mode, executeMethod, query, cache, queryMetadata, cacheConfig) {
847
+ this.mode = mode;
848
+ this.executeMethod = executeMethod;
849
+ this.query = query;
850
+ this.cache = cache;
851
+ this.queryMetadata = queryMetadata;
852
+ this.cacheConfig = cacheConfig;
853
+ if (cache && cache.strategy() === "all" && cacheConfig === void 0) this.cacheConfig = {
854
+ enable: true,
855
+ autoInvalidate: true
856
+ };
857
+ if (!this.cacheConfig?.enable) this.cacheConfig = void 0;
858
+ }
859
+ static [entityKind] = "PreparedQuery";
860
+ /** @internal */
861
+ joinsNotNullableMap;
862
+ /** @internal */
863
+ async queryWithCache(queryString, params, query) {
864
+ if (this.cache === void 0 || is(this.cache, NoopCache) || this.queryMetadata === void 0) try {
865
+ return await query();
866
+ } catch (e) {
867
+ throw new DrizzleQueryError(queryString, params, e);
868
+ }
869
+ if (this.cacheConfig && !this.cacheConfig.enable) try {
870
+ return await query();
871
+ } catch (e) {
872
+ throw new DrizzleQueryError(queryString, params, e);
873
+ }
874
+ if ((this.queryMetadata.type === "insert" || this.queryMetadata.type === "update" || this.queryMetadata.type === "delete") && this.queryMetadata.tables.length > 0) try {
875
+ const [res] = await Promise.all([query(), this.cache.onMutate({ tables: this.queryMetadata.tables })]);
876
+ return res;
877
+ } catch (e) {
878
+ throw new DrizzleQueryError(queryString, params, e);
879
+ }
880
+ if (!this.cacheConfig) try {
881
+ return await query();
882
+ } catch (e) {
883
+ throw new DrizzleQueryError(queryString, params, e);
884
+ }
885
+ if (this.queryMetadata.type === "select") {
886
+ const fromCache = await this.cache.get(this.cacheConfig.tag ?? await hashQuery(queryString, params), this.queryMetadata.tables, this.cacheConfig.tag !== void 0, this.cacheConfig.autoInvalidate);
887
+ if (fromCache === void 0) {
888
+ let result;
889
+ try {
890
+ result = await query();
891
+ } catch (e) {
892
+ throw new DrizzleQueryError(queryString, params, e);
893
+ }
894
+ await this.cache.put(this.cacheConfig.tag ?? await hashQuery(queryString, params), result, this.cacheConfig.autoInvalidate ? this.queryMetadata.tables : [], this.cacheConfig.tag !== void 0, this.cacheConfig.config);
895
+ return result;
896
+ }
897
+ return fromCache;
898
+ }
899
+ try {
900
+ return await query();
901
+ } catch (e) {
902
+ throw new DrizzleQueryError(queryString, params, e);
903
+ }
904
+ }
905
+ getQuery() {
906
+ return this.query;
907
+ }
908
+ mapRunResult(result, _isFromBatch) {
909
+ return result;
910
+ }
911
+ mapAllResult(_result, _isFromBatch) {
912
+ throw new Error("Not implemented");
913
+ }
914
+ mapGetResult(_result, _isFromBatch) {
915
+ throw new Error("Not implemented");
916
+ }
917
+ execute(placeholderValues) {
918
+ if (this.mode === "async") return this[this.executeMethod](placeholderValues);
919
+ return new ExecuteResultSync(() => this[this.executeMethod](placeholderValues));
920
+ }
921
+ mapResult(response, isFromBatch) {
922
+ switch (this.executeMethod) {
923
+ case "run": return this.mapRunResult(response, isFromBatch);
924
+ case "all": return this.mapAllResult(response, isFromBatch);
925
+ case "get": return this.mapGetResult(response, isFromBatch);
926
+ }
927
+ }
928
+ };
929
+ var SQLiteSession = class {
930
+ constructor(dialect) {
931
+ this.dialect = dialect;
932
+ }
933
+ static [entityKind] = "SQLiteSession";
934
+ prepareOneTimeQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
935
+ return this.prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig);
936
+ }
937
+ run(query) {
938
+ const staticQuery = this.dialect.sqlToQuery(query);
939
+ try {
940
+ return this.prepareOneTimeQuery(staticQuery, void 0, "run", false).run();
941
+ } catch (err) {
942
+ throw new DrizzleError({
943
+ cause: err,
944
+ message: `Failed to run the query '${staticQuery.sql}'`
945
+ });
946
+ }
947
+ }
948
+ /** @internal */
949
+ extractRawRunValueFromBatchResult(result) {
950
+ return result;
951
+ }
952
+ all(query) {
953
+ return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).all();
954
+ }
955
+ /** @internal */
956
+ extractRawAllValueFromBatchResult(_result) {
957
+ throw new Error("Not implemented");
958
+ }
959
+ get(query) {
960
+ return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).get();
961
+ }
962
+ /** @internal */
963
+ extractRawGetValueFromBatchResult(_result) {
964
+ throw new Error("Not implemented");
965
+ }
966
+ values(query) {
967
+ return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).values();
968
+ }
969
+ async count(sql) {
970
+ return (await this.values(sql))[0][0];
971
+ }
972
+ /** @internal */
973
+ extractRawValuesValueFromBatchResult(_result) {
974
+ throw new Error("Not implemented");
975
+ }
976
+ };
977
+ var SQLiteTransaction = class extends BaseSQLiteDatabase {
978
+ constructor(resultType, dialect, session, schema, nestedIndex = 0) {
979
+ super(resultType, dialect, session, schema);
980
+ this.schema = schema;
981
+ this.nestedIndex = nestedIndex;
982
+ }
983
+ static [entityKind] = "SQLiteTransaction";
984
+ rollback() {
985
+ throw new TransactionRollbackError();
986
+ }
987
+ };
988
+ //#endregion
989
+ export { SQLiteTransaction as i, SQLitePreparedQuery as n, SQLiteSession as r, BaseSQLiteDatabase as t };