@nextlyhq/adapter-drizzle 0.0.2-alpha.5 → 0.0.2-alpha.50

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,7 +1,8 @@
1
+ import { AnyRelations, SQL } 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-Bj84e15B.js';
3
4
  import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BIQ0YQZ_.js';
4
- import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.js';
5
+ import { D as DatabaseErrorKind, a as DatabaseError } from './error-BrdknH2s.js';
5
6
 
6
7
  /**
7
8
  * Base database adapter abstract class.
@@ -16,53 +17,6 @@ import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.js'
16
17
  * @packageDocumentation
17
18
  */
18
19
 
19
- /**
20
- * Abstract base class for database adapters.
21
- *
22
- * @remarks
23
- * All dialect-specific adapters must extend this class and implement the abstract methods.
24
- * Default implementations are provided for CRUD operations, which can be overridden for
25
- * optimization or dialect-specific behavior.
26
- *
27
- * ## Required Implementations
28
- *
29
- * Subclasses must implement:
30
- * - `dialect` - Database dialect identifier
31
- * - `connect()` - Establish database connection
32
- * - `disconnect()` - Close database connection
33
- * - `executeQuery()` - Execute raw SQL query
34
- * - `transaction()` - Execute operations within a transaction
35
- * - `getCapabilities()` - Report database feature support
36
- *
37
- * ## Optional Overrides
38
- *
39
- * Subclasses can override default CRUD methods for optimization:
40
- * - `select()`, `selectOne()` - Custom query optimization
41
- * - `insert()`, `insertMany()` - Bulk insert optimization
42
- * - `update()`, `delete()` - Custom update/delete logic
43
- * - `upsert()` - Dialect-specific upsert syntax
44
- *
45
- * @example
46
- * ```typescript
47
- * export class PostgresAdapter extends DrizzleAdapter {
48
- * readonly dialect = 'postgresql' as const;
49
- *
50
- * async connect() {
51
- * this.pool = new Pool({ connectionString: this.config.url });
52
- * // ... connection logic
53
- * }
54
- *
55
- * async executeQuery<T>(sql: string, params?: SqlParam[]) {
56
- * const result = await this.pool.query(sql, params);
57
- * return result.rows as T[];
58
- * }
59
- *
60
- * // ... other required methods
61
- * }
62
- * ```
63
- *
64
- * @public
65
- */
66
20
  declare abstract class DrizzleAdapter {
67
21
  /**
68
22
  * Database dialect identifier.
@@ -106,11 +60,29 @@ declare abstract class DrizzleAdapter {
106
60
  * The transaction is automatically committed on success or rolled back on error.
107
61
  * Supports nested transactions via savepoints on databases that support them.
108
62
  *
63
+ * Two kinds of error leave this method, and a caller has to be able to tell
64
+ * them apart. An error carrying the Nextly application brand — see
65
+ * `isApplicationError` — arrives exactly as it was thrown, because that is
66
+ * the application refusing the write rather than the database failing to
67
+ * perform it, and rewriting it would discard the code and payload the caller
68
+ * is meant to act on.
69
+ *
70
+ * Everything else arrives as a `DatabaseError` with its kind classified, and
71
+ * that deliberately includes an unbranded error the callback itself threw:
72
+ * the brand is the only thing distinguishing a deliberate refusal from a
73
+ * driver failure that surfaced through callback code, and guessing from the
74
+ * throw site would put raw driver text on the wire under a caller's own
75
+ * error shape.
76
+ *
77
+ * The rollback is the same either way.
78
+ *
109
79
  * @param callback - Function to execute within transaction
110
80
  * @param options - Transaction options
111
81
  * @returns Result from the callback
112
82
  *
113
- * @throws {DatabaseError} If transaction fails
83
+ * @throws {DatabaseError} If the transaction itself fails, or if the callback
84
+ * threw an error that does not carry the application brand
85
+ * @throws The callback's own error, unchanged, when it carries that brand
114
86
  */
115
87
  abstract transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
116
88
  /**
@@ -136,17 +108,18 @@ declare abstract class DrizzleAdapter {
136
108
  * - Consistent error handling
137
109
  * - Proper connection pooling
138
110
  *
139
- * @param schema - Optional schema object for typed queries
111
+ * @param relations - Optional drizzle v1 relations config (defineRelations
112
+ * output) that enables the typed relational query API on the instance
140
113
  * @returns Raw Drizzle ORM database instance
141
114
  *
142
115
  * @example
143
116
  * ```typescript
144
117
  * // For legacy code that needs direct Drizzle access
145
- * const db = adapter.getDrizzle(mySchemas);
118
+ * const db = adapter.getDrizzle(myRelations); // defineRelations output
146
119
  * const result = await db.insert(users).values({ ... }).returning();
147
120
  * ```
148
121
  */
149
- abstract getDrizzle<T = unknown>(schema?: Record<string, unknown>): T;
122
+ abstract getDrizzle<T = unknown>(relations?: AnyRelations): T;
150
123
  /**
151
124
  * Table resolver for looking up Drizzle table objects by name.
152
125
  * When set, CRUD methods use Drizzle's query API instead of raw SQL.
@@ -167,6 +140,27 @@ declare abstract class DrizzleAdapter {
167
140
  * Returns null if no resolver is set or table is not found.
168
141
  */
169
142
  protected getTableObject(tableName: string): unknown;
143
+ /**
144
+ * Run a Drizzle-built statement and return its rows.
145
+ *
146
+ * @remarks
147
+ * The CRUD methods resolve their table through the schema registry and reject
148
+ * any name it does not declare, which leaves no way to read from a table the
149
+ * ORM does not know — one mid-rename, above all — except by assembling SQL and
150
+ * quoting identifiers by hand. This takes Drizzle's `sql` template instead, so
151
+ * the dialect in use decides the quoting and the parameter binding.
152
+ *
153
+ * Concrete rather than abstract so existing adapters keep working unchanged.
154
+ * The three drivers disagree about both the call and the result: node-postgres
155
+ * returns `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 has
156
+ * no `execute` at all and answers `all`. Keeping that here rather than at each
157
+ * call site is the point — a caller reasoning about it would be reasoning
158
+ * about a driver it cannot see.
159
+ *
160
+ * @param statement - Drizzle `sql` template to run
161
+ * @returns Rows the statement produced
162
+ */
163
+ queryStatement<T = Record<string, unknown>>(statement: SQL): Promise<T[]>;
170
164
  /**
171
165
  * Map data keys from SQL column names (snake_case) to Drizzle JS property names (camelCase).
172
166
  * Drizzle schemas define columns as e.g. `createdAt: timestamp("created_at")` — the JS
@@ -174,6 +168,44 @@ declare abstract class DrizzleAdapter {
174
168
  * because they match the DB column names. This method maps them to the JS names Drizzle expects.
175
169
  */
176
170
  protected mapDataToColumnNames(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
171
+ /**
172
+ * Map data keys from Drizzle JS property names to SQL column names for the
173
+ * raw-SQL transaction insert path. The transaction context builds INSERT
174
+ * statements from Object.keys(data) used directly as column identifiers, so a
175
+ * table whose Drizzle property names differ from its SQL column names
176
+ * (camelCase core tables like nextly_versions) needs its keys translated
177
+ * first. For tables whose property names already equal their column names
178
+ * (the dynamic dc_/single_/comp_ tables) every lookup is identity, so
179
+ * existing callers are unaffected.
180
+ */
181
+ protected mapKeysToSqlColumns(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
182
+ /**
183
+ * Map a list of column identifiers (Drizzle property names) to their SQL
184
+ * column names, for the raw-SQL transaction insert paths that build a
185
+ * RETURNING clause from `options.returning`. Same identity behavior as
186
+ * `mapKeysToSqlColumns`: names that are already SQL columns (the dynamic
187
+ * dc_/single_/comp_ tables) pass through unchanged.
188
+ */
189
+ protected mapColumnNamesToSql(tableObj: unknown, names: string[]): string[];
190
+ /**
191
+ * Remap a raw-SQL result row's KEYS from SQL column names to Drizzle property
192
+ * names, so the raw-SQL transaction insert paths return the same key casing
193
+ * as the non-transactional (Drizzle) insert. Keys only - values are left
194
+ * untouched, so this does not change how JSON/date columns are decoded. For
195
+ * tables whose property names already equal their SQL columns (the dynamic
196
+ * dc_/single_/comp_ tables) every lookup is identity, so existing callers see
197
+ * no change.
198
+ */
199
+ protected mapRowKeysToJs<T = unknown>(tableObj: unknown, row: T): T;
200
+ /**
201
+ * Build a Drizzle column projection object (`{ propertyName: column }`) from a
202
+ * requested column list, used by `select` (columns) and `insert` (returning).
203
+ * A requested name resolves against either the Drizzle property name
204
+ * (camelCase) or the SQL column name (snake_case); the projection is keyed by
205
+ * the property name so the row shape matches a full select. Returns undefined
206
+ * for `"*"` or when nothing resolves, so callers fall back to all columns.
207
+ */
208
+ protected buildColumnProjection(tableObj: unknown, names: string[] | "*" | undefined): Record<string, unknown> | undefined;
177
209
  /**
178
210
  * Check if the adapter is currently connected.
179
211
  *
@@ -286,7 +318,7 @@ declare abstract class DrizzleAdapter {
286
318
  * });
287
319
  * ```
288
320
  */
289
- select<T = unknown>(table: string, options?: SelectOptions): Promise<T[]>;
321
+ select<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T[]>;
290
322
  /**
291
323
  * Select a single record from a table.
292
324
  *
@@ -307,7 +339,7 @@ declare abstract class DrizzleAdapter {
307
339
  * });
308
340
  * ```
309
341
  */
310
- selectOne<T = unknown>(table: string, options?: SelectOptions): Promise<T | null>;
342
+ selectOne<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T | null>;
311
343
  /**
312
344
  * Insert a single record into a table.
313
345
  *
@@ -378,7 +410,7 @@ declare abstract class DrizzleAdapter {
378
410
  * );
379
411
  * ```
380
412
  */
381
- update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions): Promise<T[]>;
413
+ update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions, executor?: unknown): Promise<T[]>;
382
414
  /**
383
415
  * Delete records from a table.
384
416
  *
@@ -401,7 +433,7 @@ declare abstract class DrizzleAdapter {
401
433
  * console.log(`Deleted ${count} users`);
402
434
  * ```
403
435
  */
404
- delete(table: string, where: WhereClause, _options?: DeleteOptions): Promise<number>;
436
+ delete(table: string, where: WhereClause, _options?: DeleteOptions, executor?: unknown): Promise<number>;
405
437
  /**
406
438
  * Upsert (INSERT or UPDATE) a record.
407
439
  *
@@ -429,7 +461,7 @@ declare abstract class DrizzleAdapter {
429
461
  * });
430
462
  * ```
431
463
  */
432
- upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions): Promise<T>;
464
+ upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions, executor?: unknown): Promise<T>;
433
465
  /**
434
466
  * Run pending migrations.
435
467
  *
@@ -1,7 +1,8 @@
1
+ import { AnyRelations, SQL } 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-BUc56kip.cjs';
3
4
  import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BDn8WfSL.cjs';
4
- import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.cjs';
5
+ import { D as DatabaseErrorKind, a as DatabaseError } from './error-BrdknH2s.cjs';
5
6
 
6
7
  /**
7
8
  * Base database adapter abstract class.
@@ -16,53 +17,6 @@ import { D as DatabaseErrorKind, a as DatabaseError } from './error-um1d_3Uo.cjs
16
17
  * @packageDocumentation
17
18
  */
18
19
 
19
- /**
20
- * Abstract base class for database adapters.
21
- *
22
- * @remarks
23
- * All dialect-specific adapters must extend this class and implement the abstract methods.
24
- * Default implementations are provided for CRUD operations, which can be overridden for
25
- * optimization or dialect-specific behavior.
26
- *
27
- * ## Required Implementations
28
- *
29
- * Subclasses must implement:
30
- * - `dialect` - Database dialect identifier
31
- * - `connect()` - Establish database connection
32
- * - `disconnect()` - Close database connection
33
- * - `executeQuery()` - Execute raw SQL query
34
- * - `transaction()` - Execute operations within a transaction
35
- * - `getCapabilities()` - Report database feature support
36
- *
37
- * ## Optional Overrides
38
- *
39
- * Subclasses can override default CRUD methods for optimization:
40
- * - `select()`, `selectOne()` - Custom query optimization
41
- * - `insert()`, `insertMany()` - Bulk insert optimization
42
- * - `update()`, `delete()` - Custom update/delete logic
43
- * - `upsert()` - Dialect-specific upsert syntax
44
- *
45
- * @example
46
- * ```typescript
47
- * export class PostgresAdapter extends DrizzleAdapter {
48
- * readonly dialect = 'postgresql' as const;
49
- *
50
- * async connect() {
51
- * this.pool = new Pool({ connectionString: this.config.url });
52
- * // ... connection logic
53
- * }
54
- *
55
- * async executeQuery<T>(sql: string, params?: SqlParam[]) {
56
- * const result = await this.pool.query(sql, params);
57
- * return result.rows as T[];
58
- * }
59
- *
60
- * // ... other required methods
61
- * }
62
- * ```
63
- *
64
- * @public
65
- */
66
20
  declare abstract class DrizzleAdapter {
67
21
  /**
68
22
  * Database dialect identifier.
@@ -106,11 +60,29 @@ declare abstract class DrizzleAdapter {
106
60
  * The transaction is automatically committed on success or rolled back on error.
107
61
  * Supports nested transactions via savepoints on databases that support them.
108
62
  *
63
+ * Two kinds of error leave this method, and a caller has to be able to tell
64
+ * them apart. An error carrying the Nextly application brand — see
65
+ * `isApplicationError` — arrives exactly as it was thrown, because that is
66
+ * the application refusing the write rather than the database failing to
67
+ * perform it, and rewriting it would discard the code and payload the caller
68
+ * is meant to act on.
69
+ *
70
+ * Everything else arrives as a `DatabaseError` with its kind classified, and
71
+ * that deliberately includes an unbranded error the callback itself threw:
72
+ * the brand is the only thing distinguishing a deliberate refusal from a
73
+ * driver failure that surfaced through callback code, and guessing from the
74
+ * throw site would put raw driver text on the wire under a caller's own
75
+ * error shape.
76
+ *
77
+ * The rollback is the same either way.
78
+ *
109
79
  * @param callback - Function to execute within transaction
110
80
  * @param options - Transaction options
111
81
  * @returns Result from the callback
112
82
  *
113
- * @throws {DatabaseError} If transaction fails
83
+ * @throws {DatabaseError} If the transaction itself fails, or if the callback
84
+ * threw an error that does not carry the application brand
85
+ * @throws The callback's own error, unchanged, when it carries that brand
114
86
  */
115
87
  abstract transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
116
88
  /**
@@ -136,17 +108,18 @@ declare abstract class DrizzleAdapter {
136
108
  * - Consistent error handling
137
109
  * - Proper connection pooling
138
110
  *
139
- * @param schema - Optional schema object for typed queries
111
+ * @param relations - Optional drizzle v1 relations config (defineRelations
112
+ * output) that enables the typed relational query API on the instance
140
113
  * @returns Raw Drizzle ORM database instance
141
114
  *
142
115
  * @example
143
116
  * ```typescript
144
117
  * // For legacy code that needs direct Drizzle access
145
- * const db = adapter.getDrizzle(mySchemas);
118
+ * const db = adapter.getDrizzle(myRelations); // defineRelations output
146
119
  * const result = await db.insert(users).values({ ... }).returning();
147
120
  * ```
148
121
  */
149
- abstract getDrizzle<T = unknown>(schema?: Record<string, unknown>): T;
122
+ abstract getDrizzle<T = unknown>(relations?: AnyRelations): T;
150
123
  /**
151
124
  * Table resolver for looking up Drizzle table objects by name.
152
125
  * When set, CRUD methods use Drizzle's query API instead of raw SQL.
@@ -167,6 +140,27 @@ declare abstract class DrizzleAdapter {
167
140
  * Returns null if no resolver is set or table is not found.
168
141
  */
169
142
  protected getTableObject(tableName: string): unknown;
143
+ /**
144
+ * Run a Drizzle-built statement and return its rows.
145
+ *
146
+ * @remarks
147
+ * The CRUD methods resolve their table through the schema registry and reject
148
+ * any name it does not declare, which leaves no way to read from a table the
149
+ * ORM does not know — one mid-rename, above all — except by assembling SQL and
150
+ * quoting identifiers by hand. This takes Drizzle's `sql` template instead, so
151
+ * the dialect in use decides the quoting and the parameter binding.
152
+ *
153
+ * Concrete rather than abstract so existing adapters keep working unchanged.
154
+ * The three drivers disagree about both the call and the result: node-postgres
155
+ * returns `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 has
156
+ * no `execute` at all and answers `all`. Keeping that here rather than at each
157
+ * call site is the point — a caller reasoning about it would be reasoning
158
+ * about a driver it cannot see.
159
+ *
160
+ * @param statement - Drizzle `sql` template to run
161
+ * @returns Rows the statement produced
162
+ */
163
+ queryStatement<T = Record<string, unknown>>(statement: SQL): Promise<T[]>;
170
164
  /**
171
165
  * Map data keys from SQL column names (snake_case) to Drizzle JS property names (camelCase).
172
166
  * Drizzle schemas define columns as e.g. `createdAt: timestamp("created_at")` — the JS
@@ -174,6 +168,44 @@ declare abstract class DrizzleAdapter {
174
168
  * because they match the DB column names. This method maps them to the JS names Drizzle expects.
175
169
  */
176
170
  protected mapDataToColumnNames(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
171
+ /**
172
+ * Map data keys from Drizzle JS property names to SQL column names for the
173
+ * raw-SQL transaction insert path. The transaction context builds INSERT
174
+ * statements from Object.keys(data) used directly as column identifiers, so a
175
+ * table whose Drizzle property names differ from its SQL column names
176
+ * (camelCase core tables like nextly_versions) needs its keys translated
177
+ * first. For tables whose property names already equal their column names
178
+ * (the dynamic dc_/single_/comp_ tables) every lookup is identity, so
179
+ * existing callers are unaffected.
180
+ */
181
+ protected mapKeysToSqlColumns(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
182
+ /**
183
+ * Map a list of column identifiers (Drizzle property names) to their SQL
184
+ * column names, for the raw-SQL transaction insert paths that build a
185
+ * RETURNING clause from `options.returning`. Same identity behavior as
186
+ * `mapKeysToSqlColumns`: names that are already SQL columns (the dynamic
187
+ * dc_/single_/comp_ tables) pass through unchanged.
188
+ */
189
+ protected mapColumnNamesToSql(tableObj: unknown, names: string[]): string[];
190
+ /**
191
+ * Remap a raw-SQL result row's KEYS from SQL column names to Drizzle property
192
+ * names, so the raw-SQL transaction insert paths return the same key casing
193
+ * as the non-transactional (Drizzle) insert. Keys only - values are left
194
+ * untouched, so this does not change how JSON/date columns are decoded. For
195
+ * tables whose property names already equal their SQL columns (the dynamic
196
+ * dc_/single_/comp_ tables) every lookup is identity, so existing callers see
197
+ * no change.
198
+ */
199
+ protected mapRowKeysToJs<T = unknown>(tableObj: unknown, row: T): T;
200
+ /**
201
+ * Build a Drizzle column projection object (`{ propertyName: column }`) from a
202
+ * requested column list, used by `select` (columns) and `insert` (returning).
203
+ * A requested name resolves against either the Drizzle property name
204
+ * (camelCase) or the SQL column name (snake_case); the projection is keyed by
205
+ * the property name so the row shape matches a full select. Returns undefined
206
+ * for `"*"` or when nothing resolves, so callers fall back to all columns.
207
+ */
208
+ protected buildColumnProjection(tableObj: unknown, names: string[] | "*" | undefined): Record<string, unknown> | undefined;
177
209
  /**
178
210
  * Check if the adapter is currently connected.
179
211
  *
@@ -286,7 +318,7 @@ declare abstract class DrizzleAdapter {
286
318
  * });
287
319
  * ```
288
320
  */
289
- select<T = unknown>(table: string, options?: SelectOptions): Promise<T[]>;
321
+ select<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T[]>;
290
322
  /**
291
323
  * Select a single record from a table.
292
324
  *
@@ -307,7 +339,7 @@ declare abstract class DrizzleAdapter {
307
339
  * });
308
340
  * ```
309
341
  */
310
- selectOne<T = unknown>(table: string, options?: SelectOptions): Promise<T | null>;
342
+ selectOne<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T | null>;
311
343
  /**
312
344
  * Insert a single record into a table.
313
345
  *
@@ -378,7 +410,7 @@ declare abstract class DrizzleAdapter {
378
410
  * );
379
411
  * ```
380
412
  */
381
- update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions): Promise<T[]>;
413
+ update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions, executor?: unknown): Promise<T[]>;
382
414
  /**
383
415
  * Delete records from a table.
384
416
  *
@@ -401,7 +433,7 @@ declare abstract class DrizzleAdapter {
401
433
  * console.log(`Deleted ${count} users`);
402
434
  * ```
403
435
  */
404
- delete(table: string, where: WhereClause, _options?: DeleteOptions): Promise<number>;
436
+ delete(table: string, where: WhereClause, _options?: DeleteOptions, executor?: unknown): Promise<number>;
405
437
  /**
406
438
  * Upsert (INSERT or UPDATE) a record.
407
439
  *
@@ -429,7 +461,7 @@ declare abstract class DrizzleAdapter {
429
461
  * });
430
462
  * ```
431
463
  */
432
- upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions): Promise<T>;
464
+ upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions, executor?: unknown): Promise<T>;
433
465
  /**
434
466
  * Run pending migrations.
435
467
  *
@@ -64,6 +64,23 @@ interface DatabaseError extends Error {
64
64
  * @public
65
65
  */
66
66
  declare function isDatabaseError(error: unknown): error is DatabaseError;
67
+ /**
68
+ * Whether an error is the application's verdict rather than the database's
69
+ * failure.
70
+ *
71
+ * Work running inside a transaction may throw to roll the write back — a
72
+ * refused value, a permission denial — and such an error is not something the
73
+ * driver produced. Classifying it as a database error replaces its code and its
74
+ * payload with a generic one, so a caller that asked for a refusal is handed an
75
+ * unexplained failure instead, and per-field validation detail is lost on the
76
+ * way out.
77
+ *
78
+ * @param error - Error to check
79
+ * @returns True if the error was raised by application code
80
+ *
81
+ * @public
82
+ */
83
+ declare function isApplicationError(error: unknown): boolean;
67
84
  /**
68
85
  * Database error constructor options.
69
86
  *
@@ -102,4 +119,4 @@ interface DatabaseErrorOptions {
102
119
  */
103
120
  declare function createDatabaseError(options: DatabaseErrorOptions): DatabaseError;
104
121
 
105
- export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as i };
122
+ export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as d, isApplicationError as i };
@@ -64,6 +64,23 @@ interface DatabaseError extends Error {
64
64
  * @public
65
65
  */
66
66
  declare function isDatabaseError(error: unknown): error is DatabaseError;
67
+ /**
68
+ * Whether an error is the application's verdict rather than the database's
69
+ * failure.
70
+ *
71
+ * Work running inside a transaction may throw to roll the write back — a
72
+ * refused value, a permission denial — and such an error is not something the
73
+ * driver produced. Classifying it as a database error replaces its code and its
74
+ * payload with a generic one, so a caller that asked for a refusal is handed an
75
+ * unexplained failure instead, and per-field validation detail is lost on the
76
+ * way out.
77
+ *
78
+ * @param error - Error to check
79
+ * @returns True if the error was raised by application code
80
+ *
81
+ * @public
82
+ */
83
+ declare function isApplicationError(error: unknown): boolean;
67
84
  /**
68
85
  * Database error constructor options.
69
86
  *
@@ -102,4 +119,4 @@ interface DatabaseErrorOptions {
102
119
  */
103
120
  declare function createDatabaseError(options: DatabaseErrorOptions): DatabaseError;
104
121
 
105
- export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as i };
122
+ export { type DatabaseErrorKind as D, type DatabaseError as a, type DatabaseErrorOptions as b, createDatabaseError as c, isDatabaseError as d, isApplicationError as i };