@nextlyhq/adapter-drizzle 0.0.2-alpha.35 → 0.0.2-alpha.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.
@@ -1,5 +1,6 @@
1
+ import { AnyRelations } from 'drizzle-orm';
1
2
  import { S as SupportedDialect, a as SqlParam, T as TableResolver } from './core-CVO7WYDj.cjs';
2
- import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-BbO5meEV.cjs';
3
+ import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-UX4eZjAX.cjs';
3
4
  import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BDn8WfSL.cjs';
4
5
  import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.cjs';
5
6
 
@@ -136,17 +137,18 @@ declare abstract class DrizzleAdapter {
136
137
  * - Consistent error handling
137
138
  * - Proper connection pooling
138
139
  *
139
- * @param schema - Optional schema object for typed queries
140
+ * @param relations - Optional drizzle v1 relations config (defineRelations
141
+ * output) that enables the typed relational query API on the instance
140
142
  * @returns Raw Drizzle ORM database instance
141
143
  *
142
144
  * @example
143
145
  * ```typescript
144
146
  * // For legacy code that needs direct Drizzle access
145
- * const db = adapter.getDrizzle(mySchemas);
147
+ * const db = adapter.getDrizzle(myRelations); // defineRelations output
146
148
  * const result = await db.insert(users).values({ ... }).returning();
147
149
  * ```
148
150
  */
149
- abstract getDrizzle<T = unknown>(schema?: Record<string, unknown>): T;
151
+ abstract getDrizzle<T = unknown>(relations?: AnyRelations): T;
150
152
  /**
151
153
  * Table resolver for looking up Drizzle table objects by name.
152
154
  * When set, CRUD methods use Drizzle's query API instead of raw SQL.
@@ -174,6 +176,44 @@ declare abstract class DrizzleAdapter {
174
176
  * because they match the DB column names. This method maps them to the JS names Drizzle expects.
175
177
  */
176
178
  protected mapDataToColumnNames(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
179
+ /**
180
+ * Map data keys from Drizzle JS property names to SQL column names for the
181
+ * raw-SQL transaction insert path. The transaction context builds INSERT
182
+ * statements from Object.keys(data) used directly as column identifiers, so a
183
+ * table whose Drizzle property names differ from its SQL column names
184
+ * (camelCase core tables like nextly_versions) needs its keys translated
185
+ * first. For tables whose property names already equal their column names
186
+ * (the dynamic dc_/single_/comp_ tables) every lookup is identity, so
187
+ * existing callers are unaffected.
188
+ */
189
+ protected mapKeysToSqlColumns(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
190
+ /**
191
+ * Map a list of column identifiers (Drizzle property names) to their SQL
192
+ * column names, for the raw-SQL transaction insert paths that build a
193
+ * RETURNING clause from `options.returning`. Same identity behavior as
194
+ * `mapKeysToSqlColumns`: names that are already SQL columns (the dynamic
195
+ * dc_/single_/comp_ tables) pass through unchanged.
196
+ */
197
+ protected mapColumnNamesToSql(tableObj: unknown, names: string[]): string[];
198
+ /**
199
+ * Remap a raw-SQL result row's KEYS from SQL column names to Drizzle property
200
+ * names, so the raw-SQL transaction insert paths return the same key casing
201
+ * as the non-transactional (Drizzle) insert. Keys only - values are left
202
+ * untouched, so this does not change how JSON/date columns are decoded. For
203
+ * tables whose property names already equal their SQL columns (the dynamic
204
+ * dc_/single_/comp_ tables) every lookup is identity, so existing callers see
205
+ * no change.
206
+ */
207
+ protected mapRowKeysToJs<T = unknown>(tableObj: unknown, row: T): T;
208
+ /**
209
+ * Build a Drizzle column projection object (`{ propertyName: column }`) from a
210
+ * requested column list, used by `select` (columns) and `insert` (returning).
211
+ * A requested name resolves against either the Drizzle property name
212
+ * (camelCase) or the SQL column name (snake_case); the projection is keyed by
213
+ * the property name so the row shape matches a full select. Returns undefined
214
+ * for `"*"` or when nothing resolves, so callers fall back to all columns.
215
+ */
216
+ protected buildColumnProjection(tableObj: unknown, names: string[] | "*" | undefined): Record<string, unknown> | undefined;
177
217
  /**
178
218
  * Check if the adapter is currently connected.
179
219
  *
@@ -286,7 +326,7 @@ declare abstract class DrizzleAdapter {
286
326
  * });
287
327
  * ```
288
328
  */
289
- select<T = unknown>(table: string, options?: SelectOptions): Promise<T[]>;
329
+ select<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T[]>;
290
330
  /**
291
331
  * Select a single record from a table.
292
332
  *
@@ -307,7 +347,7 @@ declare abstract class DrizzleAdapter {
307
347
  * });
308
348
  * ```
309
349
  */
310
- selectOne<T = unknown>(table: string, options?: SelectOptions): Promise<T | null>;
350
+ selectOne<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T | null>;
311
351
  /**
312
352
  * Insert a single record into a table.
313
353
  *
@@ -378,7 +418,7 @@ declare abstract class DrizzleAdapter {
378
418
  * );
379
419
  * ```
380
420
  */
381
- update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions): Promise<T[]>;
421
+ update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions, executor?: unknown): Promise<T[]>;
382
422
  /**
383
423
  * Delete records from a table.
384
424
  *
@@ -401,7 +441,7 @@ declare abstract class DrizzleAdapter {
401
441
  * console.log(`Deleted ${count} users`);
402
442
  * ```
403
443
  */
404
- delete(table: string, where: WhereClause, _options?: DeleteOptions): Promise<number>;
444
+ delete(table: string, where: WhereClause, _options?: DeleteOptions, executor?: unknown): Promise<number>;
405
445
  /**
406
446
  * Upsert (INSERT or UPDATE) a record.
407
447
  *
@@ -429,7 +469,7 @@ declare abstract class DrizzleAdapter {
429
469
  * });
430
470
  * ```
431
471
  */
432
- upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions): Promise<T>;
472
+ upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions, executor?: unknown): Promise<T>;
433
473
  /**
434
474
  * Run pending migrations.
435
475
  *
@@ -1,5 +1,6 @@
1
+ import { AnyRelations } from 'drizzle-orm';
1
2
  import { S as SupportedDialect, a as SqlParam, T as TableResolver } from './core-CVO7WYDj.js';
2
- import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-Qe70wDOC.js';
3
+ import { T as TransactionContext, e as TransactionOptions, D as DatabaseCapabilities, P as PoolStats, S as SelectOptions, I as InsertOptions, W as WhereClause, U as UpdateOptions, f as DeleteOptions, g as UpsertOptions, a as Migration, d as MigrationResult } from './migration-BVH4_wPB.js';
3
4
  import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BIQ0YQZ_.js';
4
5
  import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.js';
5
6
 
@@ -136,17 +137,18 @@ declare abstract class DrizzleAdapter {
136
137
  * - Consistent error handling
137
138
  * - Proper connection pooling
138
139
  *
139
- * @param schema - Optional schema object for typed queries
140
+ * @param relations - Optional drizzle v1 relations config (defineRelations
141
+ * output) that enables the typed relational query API on the instance
140
142
  * @returns Raw Drizzle ORM database instance
141
143
  *
142
144
  * @example
143
145
  * ```typescript
144
146
  * // For legacy code that needs direct Drizzle access
145
- * const db = adapter.getDrizzle(mySchemas);
147
+ * const db = adapter.getDrizzle(myRelations); // defineRelations output
146
148
  * const result = await db.insert(users).values({ ... }).returning();
147
149
  * ```
148
150
  */
149
- abstract getDrizzle<T = unknown>(schema?: Record<string, unknown>): T;
151
+ abstract getDrizzle<T = unknown>(relations?: AnyRelations): T;
150
152
  /**
151
153
  * Table resolver for looking up Drizzle table objects by name.
152
154
  * When set, CRUD methods use Drizzle's query API instead of raw SQL.
@@ -174,6 +176,44 @@ declare abstract class DrizzleAdapter {
174
176
  * because they match the DB column names. This method maps them to the JS names Drizzle expects.
175
177
  */
176
178
  protected mapDataToColumnNames(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
179
+ /**
180
+ * Map data keys from Drizzle JS property names to SQL column names for the
181
+ * raw-SQL transaction insert path. The transaction context builds INSERT
182
+ * statements from Object.keys(data) used directly as column identifiers, so a
183
+ * table whose Drizzle property names differ from its SQL column names
184
+ * (camelCase core tables like nextly_versions) needs its keys translated
185
+ * first. For tables whose property names already equal their column names
186
+ * (the dynamic dc_/single_/comp_ tables) every lookup is identity, so
187
+ * existing callers are unaffected.
188
+ */
189
+ protected mapKeysToSqlColumns(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
190
+ /**
191
+ * Map a list of column identifiers (Drizzle property names) to their SQL
192
+ * column names, for the raw-SQL transaction insert paths that build a
193
+ * RETURNING clause from `options.returning`. Same identity behavior as
194
+ * `mapKeysToSqlColumns`: names that are already SQL columns (the dynamic
195
+ * dc_/single_/comp_ tables) pass through unchanged.
196
+ */
197
+ protected mapColumnNamesToSql(tableObj: unknown, names: string[]): string[];
198
+ /**
199
+ * Remap a raw-SQL result row's KEYS from SQL column names to Drizzle property
200
+ * names, so the raw-SQL transaction insert paths return the same key casing
201
+ * as the non-transactional (Drizzle) insert. Keys only - values are left
202
+ * untouched, so this does not change how JSON/date columns are decoded. For
203
+ * tables whose property names already equal their SQL columns (the dynamic
204
+ * dc_/single_/comp_ tables) every lookup is identity, so existing callers see
205
+ * no change.
206
+ */
207
+ protected mapRowKeysToJs<T = unknown>(tableObj: unknown, row: T): T;
208
+ /**
209
+ * Build a Drizzle column projection object (`{ propertyName: column }`) from a
210
+ * requested column list, used by `select` (columns) and `insert` (returning).
211
+ * A requested name resolves against either the Drizzle property name
212
+ * (camelCase) or the SQL column name (snake_case); the projection is keyed by
213
+ * the property name so the row shape matches a full select. Returns undefined
214
+ * for `"*"` or when nothing resolves, so callers fall back to all columns.
215
+ */
216
+ protected buildColumnProjection(tableObj: unknown, names: string[] | "*" | undefined): Record<string, unknown> | undefined;
177
217
  /**
178
218
  * Check if the adapter is currently connected.
179
219
  *
@@ -286,7 +326,7 @@ declare abstract class DrizzleAdapter {
286
326
  * });
287
327
  * ```
288
328
  */
289
- select<T = unknown>(table: string, options?: SelectOptions): Promise<T[]>;
329
+ select<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T[]>;
290
330
  /**
291
331
  * Select a single record from a table.
292
332
  *
@@ -307,7 +347,7 @@ declare abstract class DrizzleAdapter {
307
347
  * });
308
348
  * ```
309
349
  */
310
- selectOne<T = unknown>(table: string, options?: SelectOptions): Promise<T | null>;
350
+ selectOne<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T | null>;
311
351
  /**
312
352
  * Insert a single record into a table.
313
353
  *
@@ -378,7 +418,7 @@ declare abstract class DrizzleAdapter {
378
418
  * );
379
419
  * ```
380
420
  */
381
- update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions): Promise<T[]>;
421
+ update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions, executor?: unknown): Promise<T[]>;
382
422
  /**
383
423
  * Delete records from a table.
384
424
  *
@@ -401,7 +441,7 @@ declare abstract class DrizzleAdapter {
401
441
  * console.log(`Deleted ${count} users`);
402
442
  * ```
403
443
  */
404
- delete(table: string, where: WhereClause, _options?: DeleteOptions): Promise<number>;
444
+ delete(table: string, where: WhereClause, _options?: DeleteOptions, executor?: unknown): Promise<number>;
405
445
  /**
406
446
  * Upsert (INSERT or UPDATE) a record.
407
447
  *
@@ -429,7 +469,7 @@ declare abstract class DrizzleAdapter {
429
469
  * });
430
470
  * ```
431
471
  */
432
- upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions): Promise<T>;
472
+ upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions, executor?: unknown): Promise<T>;
433
473
  /**
434
474
  * Run pending migrations.
435
475
  *
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ var drizzleOrm = require('drizzle-orm');
4
4
 
5
5
  // src/adapter.ts
6
6
  function buildDrizzleWhere(table, where) {
7
- const columns = drizzleOrm.getTableColumns(table);
7
+ const columns = drizzleOrm.getColumns(table);
8
8
  return processWhereClause(columns, where);
9
9
  }
10
10
  function processWhereClause(columns, where) {
@@ -175,6 +175,107 @@ var DrizzleAdapter = class {
175
175
  }
176
176
  return mapped;
177
177
  }
178
+ /**
179
+ * Map data keys from Drizzle JS property names to SQL column names for the
180
+ * raw-SQL transaction insert path. The transaction context builds INSERT
181
+ * statements from Object.keys(data) used directly as column identifiers, so a
182
+ * table whose Drizzle property names differ from its SQL column names
183
+ * (camelCase core tables like nextly_versions) needs its keys translated
184
+ * first. For tables whose property names already equal their column names
185
+ * (the dynamic dc_/single_/comp_ tables) every lookup is identity, so
186
+ * existing callers are unaffected.
187
+ */
188
+ mapKeysToSqlColumns(tableObj, data) {
189
+ if (!tableObj || typeof tableObj !== "object") return data;
190
+ const jsToSql = /* @__PURE__ */ new Map();
191
+ for (const [jsName, colDef] of Object.entries(
192
+ tableObj
193
+ )) {
194
+ if (colDef && typeof colDef === "object" && "name" in colDef && typeof colDef.name === "string") {
195
+ jsToSql.set(jsName, colDef.name);
196
+ }
197
+ }
198
+ if (jsToSql.size === 0) return data;
199
+ const out = {};
200
+ for (const [key, value] of Object.entries(data)) {
201
+ out[jsToSql.get(key) ?? key] = value;
202
+ }
203
+ return out;
204
+ }
205
+ /**
206
+ * Map a list of column identifiers (Drizzle property names) to their SQL
207
+ * column names, for the raw-SQL transaction insert paths that build a
208
+ * RETURNING clause from `options.returning`. Same identity behavior as
209
+ * `mapKeysToSqlColumns`: names that are already SQL columns (the dynamic
210
+ * dc_/single_/comp_ tables) pass through unchanged.
211
+ */
212
+ mapColumnNamesToSql(tableObj, names) {
213
+ if (!tableObj || typeof tableObj !== "object") return names;
214
+ const jsToSql = /* @__PURE__ */ new Map();
215
+ for (const [jsName, colDef] of Object.entries(
216
+ tableObj
217
+ )) {
218
+ if (colDef && typeof colDef === "object" && "name" in colDef && typeof colDef.name === "string") {
219
+ jsToSql.set(jsName, colDef.name);
220
+ }
221
+ }
222
+ if (jsToSql.size === 0) return names;
223
+ return names.map((n) => jsToSql.get(n) ?? n);
224
+ }
225
+ /**
226
+ * Remap a raw-SQL result row's KEYS from SQL column names to Drizzle property
227
+ * names, so the raw-SQL transaction insert paths return the same key casing
228
+ * as the non-transactional (Drizzle) insert. Keys only - values are left
229
+ * untouched, so this does not change how JSON/date columns are decoded. For
230
+ * tables whose property names already equal their SQL columns (the dynamic
231
+ * dc_/single_/comp_ tables) every lookup is identity, so existing callers see
232
+ * no change.
233
+ */
234
+ mapRowKeysToJs(tableObj, row) {
235
+ if (!tableObj || typeof tableObj !== "object" || !row || typeof row !== "object") {
236
+ return row;
237
+ }
238
+ const sqlToJs = /* @__PURE__ */ new Map();
239
+ for (const [jsName, colDef] of Object.entries(
240
+ tableObj
241
+ )) {
242
+ if (colDef && typeof colDef === "object" && "name" in colDef && typeof colDef.name === "string") {
243
+ sqlToJs.set(colDef.name, jsName);
244
+ }
245
+ }
246
+ if (sqlToJs.size === 0) return row;
247
+ const out = {};
248
+ for (const [key, value] of Object.entries(row)) {
249
+ out[sqlToJs.get(key) ?? key] = value;
250
+ }
251
+ return out;
252
+ }
253
+ /**
254
+ * Build a Drizzle column projection object (`{ propertyName: column }`) from a
255
+ * requested column list, used by `select` (columns) and `insert` (returning).
256
+ * A requested name resolves against either the Drizzle property name
257
+ * (camelCase) or the SQL column name (snake_case); the projection is keyed by
258
+ * the property name so the row shape matches a full select. Returns undefined
259
+ * for `"*"` or when nothing resolves, so callers fall back to all columns.
260
+ */
261
+ buildColumnProjection(tableObj, names) {
262
+ if (names == null || names === "*" || !tableObj || typeof tableObj !== "object") {
263
+ return void 0;
264
+ }
265
+ const cols = drizzleOrm.getColumns(tableObj);
266
+ const byAnyName = {};
267
+ for (const [jsName, col] of Object.entries(cols)) {
268
+ byAnyName[jsName] = { jsName, col };
269
+ const sqlName = col?.name;
270
+ if (typeof sqlName === "string") byAnyName[sqlName] = { jsName, col };
271
+ }
272
+ const projection = {};
273
+ for (const name of names) {
274
+ const hit = byAnyName[name];
275
+ if (hit) projection[hit.jsName] = hit.col;
276
+ }
277
+ return Object.keys(projection).length ? projection : void 0;
278
+ }
178
279
  // ============================================================
179
280
  // Connection Status (Default implementations, can override)
180
281
  // ============================================================
@@ -328,12 +429,13 @@ var DrizzleAdapter = class {
328
429
  * });
329
430
  * ```
330
431
  */
331
- async select(table, options) {
432
+ async select(table, options, executor) {
332
433
  const tableObj = this.getTableObject(table);
333
434
  if (tableObj) {
334
435
  try {
335
- const db = this.getDrizzle();
336
- let query = db.select().from(tableObj);
436
+ const db = executor ?? this.getDrizzle();
437
+ const projection = options?.columns?.length ? this.buildColumnProjection(tableObj, options.columns) : void 0;
438
+ let query = projection ? db.select(projection).from(tableObj) : db.select().from(tableObj);
337
439
  if (options?.where) {
338
440
  const whereCondition = buildDrizzleWhere(
339
441
  tableObj,
@@ -344,7 +446,7 @@ var DrizzleAdapter = class {
344
446
  }
345
447
  }
346
448
  if (options?.orderBy?.length) {
347
- const columns = drizzleOrm.getTableColumns(tableObj);
449
+ const columns = drizzleOrm.getColumns(tableObj);
348
450
  const orderClauses = options.orderBy.map((o) => {
349
451
  const col = columns[o.column];
350
452
  if (!col) return void 0;
@@ -391,8 +493,12 @@ var DrizzleAdapter = class {
391
493
  * });
392
494
  * ```
393
495
  */
394
- async selectOne(table, options) {
395
- const results = await this.select(table, { ...options, limit: 1 });
496
+ async selectOne(table, options, executor) {
497
+ const results = await this.select(
498
+ table,
499
+ { ...options, limit: 1 },
500
+ executor
501
+ );
396
502
  return results.length > 0 ? results[0] : null;
397
503
  }
398
504
  /**
@@ -424,19 +530,22 @@ var DrizzleAdapter = class {
424
530
  const mappedData = this.mapDataToColumnNames(tableObj, data);
425
531
  const db = this.getDrizzle();
426
532
  const caps = this.getCapabilities();
427
- if (caps.supportsReturning && options?.returning) {
428
- const result2 = await db.insert(tableObj).values(mappedData).returning();
533
+ const returning = options?.returning;
534
+ const wantsReturning = returning != null && !(Array.isArray(returning) && returning.length === 0);
535
+ if (caps.supportsReturning && wantsReturning) {
536
+ const projection = this.buildColumnProjection(tableObj, returning);
537
+ const insertQuery = db.insert(tableObj).values(mappedData);
538
+ const result2 = await (projection ? insertQuery.returning(projection) : insertQuery.returning());
429
539
  return Array.isArray(result2) ? result2[0] : result2;
430
540
  }
431
541
  const result = await db.insert(tableObj).values(mappedData);
432
- if (!caps.supportsReturning && options?.returning) {
433
- if (data.id !== void 0) {
434
- return await this.selectOne(table, {
435
- where: {
436
- and: [{ column: "id", op: "=", value: data.id }]
437
- }
438
- });
439
- }
542
+ if (!caps.supportsReturning && wantsReturning && data.id !== void 0) {
543
+ return await this.selectOne(table, {
544
+ columns: returning === "*" ? void 0 : returning,
545
+ where: {
546
+ and: [{ column: "id", op: "=", value: data.id }]
547
+ }
548
+ });
440
549
  }
441
550
  return Array.isArray(result) ? result[0] : result;
442
551
  } catch (error) {
@@ -506,11 +615,11 @@ var DrizzleAdapter = class {
506
615
  * );
507
616
  * ```
508
617
  */
509
- async update(table, data, where, options) {
618
+ async update(table, data, where, options, executor) {
510
619
  const tableObj = this.getTableObject(table);
511
620
  if (tableObj) {
512
621
  try {
513
- const db = this.getDrizzle();
622
+ const db = executor ?? this.getDrizzle();
514
623
  const caps = this.getCapabilities();
515
624
  const mappedData = this.mapDataToColumnNames(tableObj, data);
516
625
  let query = db.update(tableObj).set(mappedData);
@@ -523,7 +632,7 @@ var DrizzleAdapter = class {
523
632
  }
524
633
  await query;
525
634
  if (!caps.supportsReturning && options?.returning) {
526
- return await this.select(table, { where });
635
+ return await this.select(table, { where }, executor);
527
636
  }
528
637
  return [];
529
638
  } catch (error) {
@@ -558,11 +667,11 @@ var DrizzleAdapter = class {
558
667
  * console.log(`Deleted ${count} users`);
559
668
  * ```
560
669
  */
561
- async delete(table, where, _options) {
670
+ async delete(table, where, _options, executor) {
562
671
  const tableObj = this.getTableObject(table);
563
672
  if (tableObj) {
564
673
  try {
565
- const db = this.getDrizzle();
674
+ const db = executor ?? this.getDrizzle();
566
675
  let query = db.delete(tableObj);
567
676
  const whereCondition = buildDrizzleWhere(tableObj, where);
568
677
  if (whereCondition) {
@@ -607,13 +716,13 @@ var DrizzleAdapter = class {
607
716
  * });
608
717
  * ```
609
718
  */
610
- async upsert(table, data, options) {
719
+ async upsert(table, data, options, executor) {
611
720
  const tableObj = this.getTableObject(table);
612
721
  if (tableObj) {
613
722
  try {
614
- const db = this.getDrizzle();
723
+ const db = executor ?? this.getDrizzle();
615
724
  const caps = this.getCapabilities();
616
- const columns = drizzleOrm.getTableColumns(tableObj);
725
+ const columns = drizzleOrm.getColumns(tableObj);
617
726
  const conflictTarget = options.conflictColumns.map((col) => columns[col]).filter(Boolean);
618
727
  const conflictSet = new Set(options.conflictColumns);
619
728
  const updateData = {};
@@ -638,17 +747,21 @@ var DrizzleAdapter = class {
638
747
  }
639
748
  await query;
640
749
  if (options.conflictColumns.length && data[options.conflictColumns[0]] !== void 0) {
641
- return await this.selectOne(table, {
642
- where: {
643
- and: [
644
- {
645
- column: options.conflictColumns[0],
646
- op: "=",
647
- value: data[options.conflictColumns[0]]
648
- }
649
- ]
650
- }
651
- });
750
+ return await this.selectOne(
751
+ table,
752
+ {
753
+ where: {
754
+ and: [
755
+ {
756
+ column: options.conflictColumns[0],
757
+ op: "=",
758
+ value: data[options.conflictColumns[0]]
759
+ }
760
+ ]
761
+ }
762
+ },
763
+ executor
764
+ );
652
765
  }
653
766
  return data;
654
767
  } catch (error) {
@@ -974,7 +1087,7 @@ var DrizzleAdapter = class {
974
1087
  break;
975
1088
  case "mysql":
976
1089
  sql = `
977
- SELECT table_name
1090
+ SELECT table_name AS table_name
978
1091
  FROM information_schema.tables
979
1092
  WHERE table_schema = DATABASE()
980
1093
  AND table_type = 'BASE TABLE'