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,745 @@
1
+ import { C as sql, b as is, d as Table, g as entityKind, h as WithSubquery, n as Columns, r as Param, s as SQL } from "./sql-CNZp2yLp-Bwugq384.js";
2
+ import { D as haveSameKeys, E as hashQuery, N as mapUpdateSet, f as SelectionProxyHandler, i as DrizzleQueryError, j as mapRelationalRow, o as NoopCache, p as TransactionRollbackError, u as QueryPromise } from "./logger-TIsK7375-CLNNa25D.js";
3
+ import { n as MySqlSelectBuilder, o as QueryBuilder, s as extractUsedTable } from "./query-builder-CLJAKedv-DTZiP7B6.js";
4
+ //#region ../db/dist/session-CAUQtT0A.js
5
+ var MySqlCountBuilder = class MySqlCountBuilder extends SQL {
6
+ constructor(params) {
7
+ super(MySqlCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
8
+ this.params = params;
9
+ this.mapWith(Number);
10
+ this.session = params.session;
11
+ this.sql = MySqlCountBuilder.buildCount(params.source, params.filters);
12
+ }
13
+ sql;
14
+ static [entityKind] = "MySqlCountBuilder";
15
+ [Symbol.toStringTag] = "MySqlCountBuilder";
16
+ session;
17
+ static buildEmbeddedCount(source, filters) {
18
+ return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
19
+ }
20
+ static buildCount(source, filters) {
21
+ return sql`select count(*) as count from ${source}${sql.raw(" where ").if(filters)}${filters}`;
22
+ }
23
+ then(onfulfilled, onrejected) {
24
+ return Promise.resolve(this.session.count(this.sql)).then(onfulfilled, onrejected);
25
+ }
26
+ catch(onRejected) {
27
+ return this.then(void 0, onRejected);
28
+ }
29
+ finally(onFinally) {
30
+ return this.then((value) => {
31
+ onFinally?.();
32
+ return value;
33
+ }, (reason) => {
34
+ onFinally?.();
35
+ throw reason;
36
+ });
37
+ }
38
+ };
39
+ var MySqlDeleteBase = class extends QueryPromise {
40
+ constructor(table, session, dialect, withList) {
41
+ super();
42
+ this.table = table;
43
+ this.session = session;
44
+ this.dialect = dialect;
45
+ this.config = {
46
+ table,
47
+ withList
48
+ };
49
+ }
50
+ static [entityKind] = "MySqlDelete";
51
+ config;
52
+ /**
53
+ * Adds a `where` clause to the query.
54
+ *
55
+ * Calling this method will delete only those rows that fulfill a specified condition.
56
+ *
57
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
58
+ *
59
+ * @param where the `where` clause.
60
+ *
61
+ * @example
62
+ * You can use conditional operators and `sql function` to filter the rows to be deleted.
63
+ *
64
+ * ```ts
65
+ * // Delete all cars with green color
66
+ * db.delete(cars).where(eq(cars.color, 'green'));
67
+ * // or
68
+ * db.delete(cars).where(sql`${cars.color} = 'green'`)
69
+ * ```
70
+ *
71
+ * You can logically combine conditional operators with `and()` and `or()` operators:
72
+ *
73
+ * ```ts
74
+ * // Delete all BMW cars with a green color
75
+ * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
76
+ *
77
+ * // Delete all cars with the green or blue color
78
+ * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
79
+ * ```
80
+ */
81
+ where(where) {
82
+ this.config.where = where;
83
+ return this;
84
+ }
85
+ orderBy(...columns) {
86
+ if (typeof columns[0] === "function") {
87
+ const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
88
+ sqlAliasedBehavior: "alias",
89
+ sqlBehavior: "sql"
90
+ })));
91
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
92
+ this.config.orderBy = orderByArray;
93
+ } else {
94
+ const orderByArray = columns;
95
+ this.config.orderBy = orderByArray;
96
+ }
97
+ return this;
98
+ }
99
+ limit(limit) {
100
+ this.config.limit = limit;
101
+ return this;
102
+ }
103
+ /** @internal */
104
+ getSQL() {
105
+ return this.dialect.buildDeleteQuery(this.config);
106
+ }
107
+ toSQL() {
108
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
109
+ return rest;
110
+ }
111
+ prepare() {
112
+ return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, void 0, void 0, void 0, {
113
+ type: "delete",
114
+ tables: extractUsedTable(this.config.table)
115
+ });
116
+ }
117
+ execute = (placeholderValues) => {
118
+ return this.prepare().execute(placeholderValues);
119
+ };
120
+ createIterator = () => {
121
+ const self = this;
122
+ return async function* (placeholderValues) {
123
+ yield* self.prepare().iterator(placeholderValues);
124
+ };
125
+ };
126
+ iterator = this.createIterator();
127
+ $dynamic() {
128
+ return this;
129
+ }
130
+ };
131
+ var MySqlInsertBuilder = class {
132
+ constructor(table, session, dialect) {
133
+ this.table = table;
134
+ this.session = session;
135
+ this.dialect = dialect;
136
+ }
137
+ static [entityKind] = "MySqlInsertBuilder";
138
+ shouldIgnore = false;
139
+ ignore() {
140
+ this.shouldIgnore = true;
141
+ return this;
142
+ }
143
+ values(values) {
144
+ values = Array.isArray(values) ? values : [values];
145
+ if (values.length === 0) throw new Error("values() must be called with at least one value");
146
+ const mappedValues = values.map((entry) => {
147
+ const result = {};
148
+ const cols = this.table[Table.Symbol.Columns];
149
+ for (const colKey of Object.keys(entry)) {
150
+ const colValue = entry[colKey];
151
+ result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
152
+ }
153
+ return result;
154
+ });
155
+ return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
156
+ }
157
+ select(selectQuery) {
158
+ const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
159
+ 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");
160
+ return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
161
+ }
162
+ };
163
+ var MySqlInsertBase = class extends QueryPromise {
164
+ constructor(table, values, ignore, session, dialect, select) {
165
+ super();
166
+ this.session = session;
167
+ this.dialect = dialect;
168
+ this.config = {
169
+ table,
170
+ values,
171
+ select,
172
+ ignore
173
+ };
174
+ }
175
+ static [entityKind] = "MySqlInsert";
176
+ config;
177
+ cacheConfig;
178
+ /**
179
+ * Adds an `on duplicate key update` clause to the query.
180
+ *
181
+ * Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
182
+ *
183
+ * See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
184
+ *
185
+ * @param config The `set` clause
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * await db.insert(cars)
190
+ * .values({ id: 1, brand: 'BMW'})
191
+ * .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
192
+ * ```
193
+ *
194
+ * While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:
195
+ *
196
+ * ```ts
197
+ * import { sql } from 'drizzle-orm';
198
+ *
199
+ * await db.insert(cars)
200
+ * .values({ id: 1, brand: 'BMW' })
201
+ * .onDuplicateKeyUpdate({ set: { id: sql`id` } });
202
+ * ```
203
+ */
204
+ onDuplicateKeyUpdate(config) {
205
+ const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
206
+ this.config.onConflict = sql`update ${setSql}`;
207
+ return this;
208
+ }
209
+ $returningId() {
210
+ const returning = [];
211
+ for (const [key, value] of Object.entries(this.config.table[Table.Symbol.Columns])) if (value.primary) returning.push({
212
+ field: value,
213
+ path: [key]
214
+ });
215
+ this.config.returning = returning;
216
+ return this;
217
+ }
218
+ /** @internal */
219
+ getSQL() {
220
+ return this.dialect.buildInsertQuery(this.config).sql;
221
+ }
222
+ toSQL() {
223
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
224
+ return rest;
225
+ }
226
+ prepare() {
227
+ const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
228
+ return this.session.prepareQuery(this.dialect.sqlToQuery(sql2), void 0, void 0, generatedIds, this.config.returning, {
229
+ type: "insert",
230
+ tables: extractUsedTable(this.config.table)
231
+ }, this.cacheConfig);
232
+ }
233
+ execute = (placeholderValues) => {
234
+ return this.prepare().execute(placeholderValues);
235
+ };
236
+ createIterator = () => {
237
+ const self = this;
238
+ return async function* (placeholderValues) {
239
+ yield* self.prepare().iterator(placeholderValues);
240
+ };
241
+ };
242
+ iterator = this.createIterator();
243
+ $dynamic() {
244
+ return this;
245
+ }
246
+ };
247
+ var MySqlUpdateBuilder = class {
248
+ constructor(table, session, dialect, withList) {
249
+ this.table = table;
250
+ this.session = session;
251
+ this.dialect = dialect;
252
+ this.withList = withList;
253
+ }
254
+ static [entityKind] = "MySqlUpdateBuilder";
255
+ set(values) {
256
+ return new MySqlUpdateBase(this.table, mapUpdateSet(this.table, values), this.session, this.dialect, this.withList);
257
+ }
258
+ };
259
+ var MySqlUpdateBase = class extends QueryPromise {
260
+ constructor(table, set, session, dialect, withList) {
261
+ super();
262
+ this.session = session;
263
+ this.dialect = dialect;
264
+ this.config = {
265
+ set,
266
+ table,
267
+ withList
268
+ };
269
+ }
270
+ static [entityKind] = "MySqlUpdate";
271
+ config;
272
+ cacheConfig;
273
+ /**
274
+ * Adds a 'where' clause to the query.
275
+ *
276
+ * Calling this method will update only those rows that fulfill a specified condition.
277
+ *
278
+ * See docs: {@link https://orm.drizzle.team/docs/update}
279
+ *
280
+ * @param where the 'where' clause.
281
+ *
282
+ * @example
283
+ * You can use conditional operators and `sql function` to filter the rows to be updated.
284
+ *
285
+ * ```ts
286
+ * // Update all cars with green color
287
+ * db.update(cars).set({ color: 'red' })
288
+ * .where(eq(cars.color, 'green'));
289
+ * // or
290
+ * db.update(cars).set({ color: 'red' })
291
+ * .where(sql`${cars.color} = 'green'`)
292
+ * ```
293
+ *
294
+ * You can logically combine conditional operators with `and()` and `or()` operators:
295
+ *
296
+ * ```ts
297
+ * // Update all BMW cars with a green color
298
+ * db.update(cars).set({ color: 'red' })
299
+ * .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
300
+ *
301
+ * // Update all cars with the green or blue color
302
+ * db.update(cars).set({ color: 'red' })
303
+ * .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
304
+ * ```
305
+ */
306
+ where(where) {
307
+ this.config.where = where;
308
+ return this;
309
+ }
310
+ orderBy(...columns) {
311
+ if (typeof columns[0] === "function") {
312
+ const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
313
+ sqlAliasedBehavior: "alias",
314
+ sqlBehavior: "sql"
315
+ })));
316
+ const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
317
+ this.config.orderBy = orderByArray;
318
+ } else {
319
+ const orderByArray = columns;
320
+ this.config.orderBy = orderByArray;
321
+ }
322
+ return this;
323
+ }
324
+ limit(limit) {
325
+ this.config.limit = limit;
326
+ return this;
327
+ }
328
+ /** @internal */
329
+ getSQL() {
330
+ return this.dialect.buildUpdateQuery(this.config);
331
+ }
332
+ toSQL() {
333
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
334
+ return rest;
335
+ }
336
+ prepare() {
337
+ return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), void 0, void 0, void 0, this.config.returning, {
338
+ type: "insert",
339
+ tables: extractUsedTable(this.config.table)
340
+ }, this.cacheConfig);
341
+ }
342
+ execute = (placeholderValues) => {
343
+ return this.prepare().execute(placeholderValues);
344
+ };
345
+ createIterator = () => {
346
+ const self = this;
347
+ return async function* (placeholderValues) {
348
+ yield* self.prepare().iterator(placeholderValues);
349
+ };
350
+ };
351
+ iterator = this.createIterator();
352
+ $dynamic() {
353
+ return this;
354
+ }
355
+ };
356
+ var RelationalQueryBuilder = class {
357
+ constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, mode) {
358
+ this.fullSchema = fullSchema;
359
+ this.schema = schema;
360
+ this.tableNamesMap = tableNamesMap;
361
+ this.table = table;
362
+ this.tableConfig = tableConfig;
363
+ this.dialect = dialect;
364
+ this.session = session;
365
+ this.mode = mode;
366
+ }
367
+ static [entityKind] = "MySqlRelationalQueryBuilder";
368
+ findMany(config) {
369
+ return new MySqlRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? config : {}, "many", this.mode);
370
+ }
371
+ findFirst(config) {
372
+ return new MySqlRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? {
373
+ ...config,
374
+ limit: 1
375
+ } : { limit: 1 }, "first", this.mode);
376
+ }
377
+ };
378
+ var MySqlRelationalQuery = class extends QueryPromise {
379
+ constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, queryMode, mode) {
380
+ super();
381
+ this.fullSchema = fullSchema;
382
+ this.schema = schema;
383
+ this.tableNamesMap = tableNamesMap;
384
+ this.table = table;
385
+ this.tableConfig = tableConfig;
386
+ this.dialect = dialect;
387
+ this.session = session;
388
+ this.config = config;
389
+ this.queryMode = queryMode;
390
+ this.mode = mode;
391
+ }
392
+ static [entityKind] = "MySqlRelationalQuery";
393
+ prepare() {
394
+ const { query, builtQuery } = this._toSQL();
395
+ return this.session.prepareQuery(builtQuery, void 0, (rawRows) => {
396
+ const rows = rawRows.map((row) => mapRelationalRow(this.schema, this.tableConfig, row, query.selection));
397
+ if (this.queryMode === "first") return rows[0];
398
+ return rows;
399
+ });
400
+ }
401
+ _getQuery() {
402
+ return this.mode === "planetscale" ? this.dialect.buildRelationalQueryWithoutLateralSubqueries({
403
+ fullSchema: this.fullSchema,
404
+ schema: this.schema,
405
+ tableNamesMap: this.tableNamesMap,
406
+ table: this.table,
407
+ tableConfig: this.tableConfig,
408
+ queryConfig: this.config,
409
+ tableAlias: this.tableConfig.tsName
410
+ }) : this.dialect.buildRelationalQuery({
411
+ fullSchema: this.fullSchema,
412
+ schema: this.schema,
413
+ tableNamesMap: this.tableNamesMap,
414
+ table: this.table,
415
+ tableConfig: this.tableConfig,
416
+ queryConfig: this.config,
417
+ tableAlias: this.tableConfig.tsName
418
+ });
419
+ }
420
+ _toSQL() {
421
+ const query = this._getQuery();
422
+ return {
423
+ builtQuery: this.dialect.sqlToQuery(query.sql),
424
+ query
425
+ };
426
+ }
427
+ /** @internal */
428
+ getSQL() {
429
+ return this._getQuery().sql;
430
+ }
431
+ toSQL() {
432
+ return this._toSQL().builtQuery;
433
+ }
434
+ execute() {
435
+ return this.prepare().execute();
436
+ }
437
+ };
438
+ var MySqlDatabase = class {
439
+ constructor(dialect, session, schema, mode) {
440
+ this.dialect = dialect;
441
+ this.session = session;
442
+ this.mode = mode;
443
+ this._ = schema ? {
444
+ schema: schema.schema,
445
+ fullSchema: schema.fullSchema,
446
+ tableNamesMap: schema.tableNamesMap
447
+ } : {
448
+ schema: void 0,
449
+ fullSchema: {},
450
+ tableNamesMap: {}
451
+ };
452
+ this.query = {};
453
+ if (this._.schema) for (const [tableName, columns] of Object.entries(this._.schema)) this.query[tableName] = new RelationalQueryBuilder(schema.fullSchema, this._.schema, this._.tableNamesMap, schema.fullSchema[tableName], columns, dialect, session, this.mode);
454
+ this.$cache = { invalidate: async (_params) => {} };
455
+ }
456
+ static [entityKind] = "MySqlDatabase";
457
+ query;
458
+ /**
459
+ * Creates a subquery that defines a temporary named result set as a CTE.
460
+ *
461
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
462
+ *
463
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
464
+ *
465
+ * @param alias The alias for the subquery.
466
+ *
467
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
468
+ *
469
+ * @example
470
+ *
471
+ * ```ts
472
+ * // Create a subquery with alias 'sq' and use it in the select query
473
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
474
+ *
475
+ * const result = await db.with(sq).select().from(sq);
476
+ * ```
477
+ *
478
+ * 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:
479
+ *
480
+ * ```ts
481
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
482
+ * const sq = db.$with('sq').as(db.select({
483
+ * name: sql<string>`upper(${users.name})`.as('name'),
484
+ * })
485
+ * .from(users));
486
+ *
487
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
488
+ * ```
489
+ */
490
+ $with = (alias, selection) => {
491
+ const self = this;
492
+ const as = (qb) => {
493
+ if (typeof qb === "function") qb = qb(new QueryBuilder(self.dialect));
494
+ return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
495
+ alias,
496
+ sqlAliasedBehavior: "alias",
497
+ sqlBehavior: "error"
498
+ }));
499
+ };
500
+ return { as };
501
+ };
502
+ $count(source, filters) {
503
+ return new MySqlCountBuilder({
504
+ source,
505
+ filters,
506
+ session: this.session
507
+ });
508
+ }
509
+ $cache;
510
+ /**
511
+ * Incorporates a previously defined CTE (using `$with`) into the main query.
512
+ *
513
+ * This method allows the main query to reference a temporary named result set.
514
+ *
515
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
516
+ *
517
+ * @param queries The CTEs to incorporate into the main query.
518
+ *
519
+ * @example
520
+ *
521
+ * ```ts
522
+ * // Define a subquery 'sq' as a CTE using $with
523
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
524
+ *
525
+ * // Incorporate the CTE 'sq' into the main query and select from it
526
+ * const result = await db.with(sq).select().from(sq);
527
+ * ```
528
+ */
529
+ with(...queries) {
530
+ const self = this;
531
+ function select(fields) {
532
+ return new MySqlSelectBuilder({
533
+ fields: fields ?? void 0,
534
+ session: self.session,
535
+ dialect: self.dialect,
536
+ withList: queries
537
+ });
538
+ }
539
+ function selectDistinct(fields) {
540
+ return new MySqlSelectBuilder({
541
+ fields: fields ?? void 0,
542
+ session: self.session,
543
+ dialect: self.dialect,
544
+ withList: queries,
545
+ distinct: true
546
+ });
547
+ }
548
+ function update(table) {
549
+ return new MySqlUpdateBuilder(table, self.session, self.dialect, queries);
550
+ }
551
+ function delete_(table) {
552
+ return new MySqlDeleteBase(table, self.session, self.dialect, queries);
553
+ }
554
+ return {
555
+ select,
556
+ selectDistinct,
557
+ update,
558
+ delete: delete_
559
+ };
560
+ }
561
+ select(fields) {
562
+ return new MySqlSelectBuilder({
563
+ fields: fields ?? void 0,
564
+ session: this.session,
565
+ dialect: this.dialect
566
+ });
567
+ }
568
+ selectDistinct(fields) {
569
+ return new MySqlSelectBuilder({
570
+ fields: fields ?? void 0,
571
+ session: this.session,
572
+ dialect: this.dialect,
573
+ distinct: true
574
+ });
575
+ }
576
+ /**
577
+ * Creates an update query.
578
+ *
579
+ * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
580
+ *
581
+ * Use `.set()` method to specify which values to update.
582
+ *
583
+ * See docs: {@link https://orm.drizzle.team/docs/update}
584
+ *
585
+ * @param table The table to update.
586
+ *
587
+ * @example
588
+ *
589
+ * ```ts
590
+ * // Update all rows in the 'cars' table
591
+ * await db.update(cars).set({ color: 'red' });
592
+ *
593
+ * // Update rows with filters and conditions
594
+ * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
595
+ * ```
596
+ */
597
+ update(table) {
598
+ return new MySqlUpdateBuilder(table, this.session, this.dialect);
599
+ }
600
+ /**
601
+ * Creates an insert query.
602
+ *
603
+ * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
604
+ *
605
+ * See docs: {@link https://orm.drizzle.team/docs/insert}
606
+ *
607
+ * @param table The table to insert into.
608
+ *
609
+ * @example
610
+ *
611
+ * ```ts
612
+ * // Insert one row
613
+ * await db.insert(cars).values({ brand: 'BMW' });
614
+ *
615
+ * // Insert multiple rows
616
+ * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
617
+ * ```
618
+ */
619
+ insert(table) {
620
+ return new MySqlInsertBuilder(table, this.session, this.dialect);
621
+ }
622
+ /**
623
+ * Creates a delete query.
624
+ *
625
+ * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
626
+ *
627
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
628
+ *
629
+ * @param table The table to delete from.
630
+ *
631
+ * @example
632
+ *
633
+ * ```ts
634
+ * // Delete all rows in the 'cars' table
635
+ * await db.delete(cars);
636
+ *
637
+ * // Delete rows with filters and conditions
638
+ * await db.delete(cars).where(eq(cars.color, 'green'));
639
+ * ```
640
+ */
641
+ delete(table) {
642
+ return new MySqlDeleteBase(table, this.session, this.dialect);
643
+ }
644
+ execute(query) {
645
+ return this.session.execute(typeof query === "string" ? sql.raw(query) : query.getSQL());
646
+ }
647
+ transaction(transaction, config) {
648
+ return this.session.transaction(transaction, config);
649
+ }
650
+ };
651
+ var MySqlPreparedQuery = class {
652
+ constructor(cache, queryMetadata, cacheConfig) {
653
+ this.cache = cache;
654
+ this.queryMetadata = queryMetadata;
655
+ this.cacheConfig = cacheConfig;
656
+ if (cache && cache.strategy() === "all" && cacheConfig === void 0) this.cacheConfig = {
657
+ enable: true,
658
+ autoInvalidate: true
659
+ };
660
+ if (!this.cacheConfig?.enable) this.cacheConfig = void 0;
661
+ }
662
+ static [entityKind] = "MySqlPreparedQuery";
663
+ /** @internal */
664
+ async queryWithCache(queryString, params, query) {
665
+ if (this.cache === void 0 || is(this.cache, NoopCache) || this.queryMetadata === void 0) try {
666
+ return await query();
667
+ } catch (e) {
668
+ throw new DrizzleQueryError(queryString, params, e);
669
+ }
670
+ if (this.cacheConfig && !this.cacheConfig.enable) try {
671
+ return await query();
672
+ } catch (e) {
673
+ throw new DrizzleQueryError(queryString, params, e);
674
+ }
675
+ if ((this.queryMetadata.type === "insert" || this.queryMetadata.type === "update" || this.queryMetadata.type === "delete") && this.queryMetadata.tables.length > 0) try {
676
+ const [res] = await Promise.all([query(), this.cache.onMutate({ tables: this.queryMetadata.tables })]);
677
+ return res;
678
+ } catch (e) {
679
+ throw new DrizzleQueryError(queryString, params, e);
680
+ }
681
+ if (!this.cacheConfig) try {
682
+ return await query();
683
+ } catch (e) {
684
+ throw new DrizzleQueryError(queryString, params, e);
685
+ }
686
+ if (this.queryMetadata.type === "select") {
687
+ const fromCache = await this.cache.get(this.cacheConfig.tag ?? await hashQuery(queryString, params), this.queryMetadata.tables, this.cacheConfig.tag !== void 0, this.cacheConfig.autoInvalidate);
688
+ if (fromCache === void 0) {
689
+ let result;
690
+ try {
691
+ result = await query();
692
+ } catch (e) {
693
+ throw new DrizzleQueryError(queryString, params, e);
694
+ }
695
+ 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);
696
+ return result;
697
+ }
698
+ return fromCache;
699
+ }
700
+ try {
701
+ return await query();
702
+ } catch (e) {
703
+ throw new DrizzleQueryError(queryString, params, e);
704
+ }
705
+ }
706
+ /** @internal */
707
+ joinsNotNullableMap;
708
+ };
709
+ var MySqlSession = class {
710
+ constructor(dialect) {
711
+ this.dialect = dialect;
712
+ }
713
+ static [entityKind] = "MySqlSession";
714
+ execute(query) {
715
+ return this.prepareQuery(this.dialect.sqlToQuery(query), void 0).execute();
716
+ }
717
+ async count(sql2) {
718
+ const res = await this.execute(sql2);
719
+ return Number(res[0][0]["count"]);
720
+ }
721
+ getSetTransactionSQL(config) {
722
+ const parts = [];
723
+ if (config.isolationLevel) parts.push(`isolation level ${config.isolationLevel}`);
724
+ return parts.length ? sql`set transaction ${sql.raw(parts.join(" "))}` : void 0;
725
+ }
726
+ getStartTransactionSQL(config) {
727
+ const parts = [];
728
+ if (config.withConsistentSnapshot) parts.push("with consistent snapshot");
729
+ if (config.accessMode) parts.push(config.accessMode);
730
+ return parts.length ? sql`start transaction ${sql.raw(parts.join(" "))}` : void 0;
731
+ }
732
+ };
733
+ var MySqlTransaction = class extends MySqlDatabase {
734
+ constructor(dialect, session, schema, nestedIndex, mode) {
735
+ super(dialect, session, schema, mode);
736
+ this.schema = schema;
737
+ this.nestedIndex = nestedIndex;
738
+ }
739
+ static [entityKind] = "MySqlTransaction";
740
+ rollback() {
741
+ throw new TransactionRollbackError();
742
+ }
743
+ };
744
+ //#endregion
745
+ export { MySqlTransaction as i, MySqlPreparedQuery as n, MySqlSession as r, MySqlDatabase as t };