@nextlyhq/adapter-drizzle 0.0.2-alpha.67 → 0.0.2-alpha.69

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 (63) hide show
  1. package/dist/adapter-BypoOEEN.d.cts +1166 -0
  2. package/dist/adapter-CSP-Ek-L.d.ts +1166 -0
  3. package/dist/index-BYb6cDli.d.ts +1168 -0
  4. package/dist/index-C4HJsfwA.d.cts +1168 -0
  5. package/dist/index.cjs +2258 -2183
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +5 -10
  8. package/dist/index.d.ts +5 -10
  9. package/dist/index.mjs +2257 -2181
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/migrations.cjs +345 -146
  12. package/dist/migrations.cjs.map +1 -1
  13. package/dist/migrations.d.cts +93 -110
  14. package/dist/migrations.d.ts +93 -110
  15. package/dist/migrations.mjs +344 -144
  16. package/dist/migrations.mjs.map +1 -1
  17. package/dist/schema/index.cjs +21 -6
  18. package/dist/schema/index.cjs.map +1 -1
  19. package/dist/schema/index.d.cts +5 -116
  20. package/dist/schema/index.d.ts +5 -116
  21. package/dist/schema/index.mjs +20 -4
  22. package/dist/schema/index.mjs.map +1 -1
  23. package/dist/schema-Bkkr3JMC.d.cts +264 -0
  24. package/dist/schema-Bkkr3JMC.d.ts +264 -0
  25. package/dist/schema-name.cjs +34 -12
  26. package/dist/schema-name.cjs.map +1 -1
  27. package/dist/schema-name.d.cts +3 -15
  28. package/dist/schema-name.d.ts +3 -15
  29. package/dist/schema-name.mjs +33 -10
  30. package/dist/schema-name.mjs.map +1 -1
  31. package/dist/text-match.cjs +42 -8
  32. package/dist/text-match.cjs.map +1 -1
  33. package/dist/text-match.d.cts +4 -16
  34. package/dist/text-match.d.ts +4 -16
  35. package/dist/text-match.mjs +41 -6
  36. package/dist/text-match.mjs.map +1 -1
  37. package/dist/types/index.cjs +8 -69
  38. package/dist/types/index.d.cts +3 -225
  39. package/dist/types/index.d.ts +3 -225
  40. package/dist/types/index.mjs +1 -64
  41. package/dist/types-CNyA1oIm.cjs +185 -0
  42. package/dist/types-CNyA1oIm.cjs.map +1 -0
  43. package/dist/types-CaF_5jNk.mjs +150 -0
  44. package/dist/types-CaF_5jNk.mjs.map +1 -0
  45. package/dist/version-check.cjs +116 -133
  46. package/dist/version-check.cjs.map +1 -1
  47. package/dist/version-check.d.cts +46 -47
  48. package/dist/version-check.d.ts +46 -47
  49. package/dist/version-check.mjs +115 -131
  50. package/dist/version-check.mjs.map +1 -1
  51. package/package.json +12 -16
  52. package/dist/adapter-bUAaPzjV.d.cts +0 -1143
  53. package/dist/adapter-iJ5hbUvL.d.ts +0 -1143
  54. package/dist/core-CVO7WYDj.d.cts +0 -74
  55. package/dist/core-CVO7WYDj.d.ts +0 -74
  56. package/dist/error-BrdknH2s.d.cts +0 -122
  57. package/dist/error-BrdknH2s.d.ts +0 -122
  58. package/dist/migration-BqHebSwM.d.ts +0 -831
  59. package/dist/migration-Bu0WLdX4.d.cts +0 -831
  60. package/dist/schema-BDn8WfSL.d.cts +0 -200
  61. package/dist/schema-BIQ0YQZ_.d.ts +0 -200
  62. package/dist/types/index.cjs.map +0 -1
  63. package/dist/types/index.mjs.map +0 -1
@@ -1,1143 +0,0 @@
1
- import { AnyRelations, SQL } from 'drizzle-orm';
2
- import { T as TransactionContext, S as SelectOptions, W as WhereClause, D as DeleteOptions, U as UpsertOptions, e as TransactionOptions, f as DatabaseCapabilities, P as PoolStats, C as CountOptions, I as InsertOptions, g as UpdateOptions, a as Migration, d as MigrationResult } from './migration-BqHebSwM.js';
3
- import { S as SupportedDialect, a as SqlParam, T as TableResolver } from './core-CVO7WYDj.js';
4
- import { T as TableDefinition, C as CreateTableOptions, D as DropTableOptions, A as AlterTableOperation, a as AlterTableOptions } from './schema-BIQ0YQZ_.js';
5
- import { D as DatabaseErrorKind, a as DatabaseError } from './error-BrdknH2s.js';
6
-
7
- /**
8
- * A pooled adapter's Drizzle transactions, each on a connection the adapter
9
- * checks out and returns itself.
10
- *
11
- * Drizzle's own `transaction()` on a pool checks a connection out, but does
12
- * not return it as carefully as the adapter's `transaction()` does: it sends
13
- * BEGIN outside its `try`, so a failed BEGIN never gives the connection back;
14
- * and when its ROLLBACK fails it hands the connection to the pool as if
15
- * nothing had happened, possibly still inside the transaction, and throws the
16
- * ROLLBACK's error in place of the work's. Core services open their
17
- * transactions through that handle, so it gets the same care here: Drizzle
18
- * runs the transaction on a connection this module owns, and this module
19
- * decides how the connection goes back.
20
- *
21
- * @module pinned-transaction
22
- */
23
- /**
24
- * Drizzle's database handle, as far as running a transaction goes.
25
- *
26
- * The callback takes `unknown` and the options `never`, so every dialect's
27
- * handle fits, whose callback receives its own transaction type and whose
28
- * options are its own.
29
- */
30
- interface DrizzleTransactor {
31
- transaction<T>(work: (tx: unknown) => Promise<T>, config?: never): Promise<T>;
32
- }
33
- /** One connection a pooled adapter checked out for one transaction. */
34
- interface PinnedConnection {
35
- /** Drizzle bound to this connection alone, with the handle's relations. */
36
- drizzle: DrizzleTransactor;
37
- /**
38
- * Sends ROLLBACK on this connection. Harmless when no transaction is open
39
- * on it: PostgreSQL answers with a warning, MySQL does nothing.
40
- */
41
- rollback(): Promise<unknown>;
42
- /**
43
- * Gives the connection back: to the pool, or, when `dirty`, closed and
44
- * removed from it, because it may still be inside the transaction.
45
- */
46
- release(dirty: boolean): void;
47
- }
48
-
49
- /**
50
- * Transaction CRUD forwarder helper for database adapters.
51
- *
52
- * @remarks
53
- * Encapsulates the delegation pattern where a transaction context forwards its
54
- * CRUD methods to the adapter's implementation while passing the transaction-bound
55
- * Drizzle executor.
56
- *
57
- * @packageDocumentation
58
- */
59
-
60
- /**
61
- * Interface representing an adapter that can execute CRUD operations with an optional executor.
62
- */
63
- interface TransactionCrudDelegator {
64
- select<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T[]>;
65
- selectOne<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T | null>;
66
- updateCount(table: string, data: Record<string, unknown>, where: WhereClause, executor?: unknown): Promise<number>;
67
- delete(table: string, where: WhereClause, options?: DeleteOptions, executor?: unknown): Promise<number>;
68
- upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions, executor?: unknown): Promise<T>;
69
- }
70
- /**
71
- * Transaction context CRUD methods provided by the forwarder.
72
- *
73
- * `update` is not among them. The pooled `update` goes through the Drizzle
74
- * query builder, which writes the columns the runtime model declares; a
75
- * transaction's update must reach the columns the physical table has, and
76
- * each adapter binds the base class's `transactionUpdate` beside its
77
- * transactional `insert`.
78
- */
79
- type TransactionCrudForwarders = Pick<TransactionContext, "select" | "selectOne" | "updateCount" | "delete" | "upsert" | "getDrizzle">;
80
-
81
- /**
82
- * Base database adapter abstract class.
83
- *
84
- * @remarks
85
- * This abstract class provides the foundation for all dialect-specific database adapters
86
- * (PostgreSQL, MySQL, SQLite). It defines required abstract methods that must be implemented
87
- * by subclasses, while providing default implementations for CRUD operations and query building.
88
- *
89
- * Dialect adapters can override any default method to provide optimized implementations.
90
- *
91
- * @packageDocumentation
92
- */
93
-
94
- declare abstract class DrizzleAdapter {
95
- /**
96
- * Database dialect identifier.
97
- *
98
- * @remarks
99
- * Must be set by subclass to identify the database type.
100
- */
101
- abstract readonly dialect: SupportedDialect;
102
- /**
103
- * Establish connection to the database.
104
- *
105
- * @remarks
106
- * This method should be idempotent - calling it multiple times
107
- * should not create multiple connections.
108
- *
109
- * @throws {DatabaseError} If connection fails
110
- */
111
- abstract connect(): Promise<void>;
112
- /**
113
- * Close database connection and release resources.
114
- *
115
- * @remarks
116
- * This method should be idempotent - calling it multiple times
117
- * should be safe.
118
- */
119
- abstract disconnect(): Promise<void>;
120
- /**
121
- * Execute a raw SQL query.
122
- *
123
- * @param sql - SQL query to execute
124
- * @param params - Query parameters
125
- * @returns Array of result rows
126
- *
127
- * @throws {DatabaseError} If query execution fails
128
- */
129
- abstract executeQuery<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
130
- /**
131
- * Execute operations within a database transaction.
132
- *
133
- * @remarks
134
- * The transaction is automatically committed on success or rolled back on error.
135
- * Supports nested transactions via savepoints on databases that support them.
136
- *
137
- * Two kinds of error leave this method, and a caller has to be able to tell
138
- * them apart. An error carrying the Nextly application brand — see
139
- * `isApplicationError` — arrives exactly as it was thrown, because that is
140
- * the application refusing the write rather than the database failing to
141
- * perform it, and rewriting it would discard the code and payload the caller
142
- * is meant to act on.
143
- *
144
- * Everything else arrives as a `DatabaseError` with its kind classified, and
145
- * that deliberately includes an unbranded error the callback itself threw:
146
- * the brand is the only thing distinguishing a deliberate refusal from a
147
- * driver failure that surfaced through callback code, and guessing from the
148
- * throw site would put raw driver text on the wire under a caller's own
149
- * error shape.
150
- *
151
- * The rollback is the same either way.
152
- *
153
- * @param callback - Function to execute within transaction
154
- * @param options - Transaction options
155
- * @returns Result from the callback
156
- *
157
- * @throws {DatabaseError} If the transaction itself fails, or if the callback
158
- * threw an error that does not carry the application brand
159
- * @throws The callback's own error, unchanged, when it carries that brand
160
- */
161
- abstract transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
162
- /**
163
- * Whether a `transaction()` call made from the current async context would
164
- * join a transaction already open on this adapter, as a savepoint, rather
165
- * than open one of its own.
166
- *
167
- * A caller about to do something no rollback can undo — removing a stored
168
- * file, say — asks this first: work that joins an enclosing transaction is
169
- * undone with it, while the effect it performs after its own savepoint
170
- * releases is not.
171
- *
172
- * False here. Concrete rather than abstract so existing adapters keep
173
- * working unchanged, and false is right for a pooled adapter: a call made
174
- * inside another transaction's work opens its own transaction on its own
175
- * connection, which commits independently.
176
- *
177
- * @returns True when the call would nest in an open transaction
178
- */
179
- inTransaction(): boolean;
180
- /**
181
- * The transaction each async flow is inside, kept per flow rather than per
182
- * connection: on SQLite every request shares the one connection, and
183
- * another request's open transaction says nothing about this one.
184
- */
185
- private readonly flowTransactions;
186
- /**
187
- * Whether the calling async flow is inside a transaction on this adapter
188
- * that has not finished: its own, or one it was started from inside.
189
- *
190
- * A write that must outlive any rollback — a count of a failed attempt, the
191
- * spend of a single-use secret — asks this before running in a transaction
192
- * of its own. Made inside an open transaction on SQLite, it joins that
193
- * transaction as a savepoint and is undone with it. On PostgreSQL and MySQL
194
- * it would commit on a connection of its own, so refusing it there too
195
- * keeps code that passes on one dialect from failing on another. Unlike
196
- * {@link inTransaction}, which asks whether a call would nest and is always
197
- * false on a pooled adapter, this answers alike on every dialect, and
198
- * another flow's open transaction never answers true.
199
- *
200
- * Covers transactions opened through {@link transaction} and through the
201
- * Drizzle handle's own `transaction` on the dialects whose handle takes
202
- * async work. A dialect that keeps scopes of its own judges from those
203
- * instead; an adapter that does neither answers false.
204
- *
205
- * @experimental
206
- * @returns True while a transaction the calling flow is inside is open
207
- */
208
- transactionOpenInFlow(): boolean;
209
- /**
210
- * Run a whole transaction, from its BEGIN until its COMMIT or ROLLBACK has
211
- * run, as the calling flow's open transaction, for
212
- * {@link transactionOpenInFlow}. A dialect's `transaction` runs through
213
- * this unless it judges the flow from scopes of its own.
214
- *
215
- * The transaction counts as open for its work and for anything the work
216
- * starts, awaited or not, until it has finished. Something the work starts
217
- * that outlives it then sees it closed, or the one enclosing it still open.
218
- *
219
- * @param run - The transaction, BEGIN to COMMIT or ROLLBACK
220
- * @returns What `run` resolves to
221
- */
222
- protected runInFlowTransaction<T>(run: () => Promise<T>): Promise<T>;
223
- /**
224
- * Run each of a pool-bound Drizzle handle's transactions on a connection
225
- * `checkout` hands it, and return that connection as the adapter's own
226
- * `transaction()` does: closed rather than pooled when no ROLLBACK can be
227
- * confirmed on it, and never leaked by a failed BEGIN (`pinTransactions`).
228
- *
229
- * For PostgreSQL's and MySQL's handles. Apply it before
230
- * {@link trackFlowTransactions}, which wraps whatever `transaction` the
231
- * handle has at that point.
232
- *
233
- * @param db - A Drizzle handle on this adapter's pool
234
- * @param checkout - Checks out a connection for one transaction
235
- * @returns The same handle, its `transaction` replaced
236
- */
237
- protected pinDrizzleTransactions<D extends DrizzleTransactor>(db: D, checkout: () => Promise<PinnedConnection>): D;
238
- /**
239
- * Make a Drizzle handle's own `transaction` count for
240
- * {@link transactionOpenInFlow}, as the adapter's does.
241
- *
242
- * Core's services run their transactions through the handle on PostgreSQL
243
- * and MySQL; without this, a call made inside one would be refused on
244
- * SQLite, where they go through the adapter, and let through on the
245
- * others. Not for SQLite's handle: its `transaction` takes only
246
- * synchronous work, which no async flow can be inside.
247
- *
248
- * @param db - A Drizzle handle this adapter created
249
- * @returns The same handle, its `transaction` tracked
250
- */
251
- protected trackFlowTransactions<D extends DrizzleTransactor>(db: D): D;
252
- /**
253
- * Run `effect` once the write made from the current async context has
254
- * committed: an event, a hook, a cache flush, anything outside the database
255
- * that must not happen for a change that is rolled back.
256
- *
257
- * A caller invokes this after its own transaction has resolved. Where that
258
- * transaction was nested in an enclosing one, as a savepoint, the change is
259
- * not durable yet, and an adapter that nests (see {@link inTransaction})
260
- * holds `effect` until the outermost transaction commits, and drops it when
261
- * that transaction, or the savepoint it was registered in, rolls back. A
262
- * held effect runs after the commit, before the outermost `transaction()`
263
- * call resolves, in registration order; one that then throws or rejects is
264
- * handed to `onDeferredFailure` rather than failing a transaction that has
265
- * committed.
266
- *
267
- * Here `effect` runs now and the returned promise settles with it, its
268
- * failure included. Concrete rather than abstract, as `inTransaction` is,
269
- * and right for a pooled adapter: each transaction has its own connection
270
- * and has committed by the time its caller continues.
271
- *
272
- * @experimental
273
- * @param effect - What to run once the change is durable
274
- * @param onDeferredFailure - Receives the error of a held effect that fails
275
- * @returns Settles once `effect` has run, or once it has been held
276
- */
277
- afterCommit(effect: () => unknown, _onDeferredFailure?: (error: unknown) => void): Promise<void>;
278
- /**
279
- * Get database capabilities.
280
- *
281
- * @remarks
282
- * Returns static capability flags for this adapter's dialect.
283
- * Used by services to conditionally enable features or implement fallbacks.
284
- *
285
- * @returns Database capability flags
286
- */
287
- abstract getCapabilities(): DatabaseCapabilities;
288
- /**
289
- * The schema this adapter's connections resolve unqualified names in.
290
- *
291
- * @remarks
292
- * Read-only, and optional because only PostgreSQL has a schema namespace:
293
- * MySQL's "schema" is its database and SQLite has one file. An adapter that
294
- * sets no `search_path` of its own answers `undefined`, meaning the server's
295
- * default applies.
296
- *
297
- * Exposed so the caller that built its own adapter can be held to the same
298
- * schema the rest of the application assumes. The value lives in the
299
- * adapter's config, and a mismatch is not an error anywhere below: every
300
- * query succeeds, in a namespace nothing else is looking at.
301
- *
302
- * @returns The configured schema name, or `undefined` when none is set
303
- */
304
- getConfiguredSchema?(): string | undefined;
305
- /**
306
- * Get the raw Drizzle ORM instance for direct queries.
307
- *
308
- * @remarks
309
- * This method provides escape hatch access to the raw Drizzle instance.
310
- * Use this when you need to run complex queries that the adapter API
311
- * doesn't support, or for legacy code migration.
312
- *
313
- * **Note:** Prefer using adapter methods when possible as they provide:
314
- * - Database-agnostic API
315
- * - Consistent error handling
316
- * - Proper connection pooling
317
- *
318
- * @param relations - Optional drizzle v1 relations config (defineRelations
319
- * output) that enables the typed relational query API on the instance
320
- * @returns Raw Drizzle ORM database instance
321
- *
322
- * @example
323
- * ```typescript
324
- * // For legacy code that needs direct Drizzle access
325
- * const db = adapter.getDrizzle(myRelations); // defineRelations output
326
- * const result = await db.insert(users).values({ ... }).returning();
327
- * ```
328
- */
329
- abstract getDrizzle<T = unknown>(relations?: AnyRelations): T;
330
- /**
331
- * Table resolver for looking up Drizzle table objects by name.
332
- * When set, CRUD methods use Drizzle's query API instead of raw SQL.
333
- * Set via setTableResolver() after boot-time schema loading.
334
- */
335
- protected tableResolver: TableResolver | null;
336
- /**
337
- * Set the table resolver for Drizzle query API support.
338
- * When a resolver is set, CRUD methods (select, insert, update, delete, upsert)
339
- * will use Drizzle's query API (db.select().from(), etc.) instead of raw SQL
340
- * string building. Falls back to raw SQL if the resolver doesn't have the table.
341
- *
342
- * @param resolver - TableResolver implementation (e.g. SchemaRegistry)
343
- */
344
- setTableResolver(resolver: TableResolver): void;
345
- /**
346
- * Get a Drizzle table object by name from the resolver.
347
- * Returns null if no resolver is set or table is not found.
348
- */
349
- protected getTableObject(tableName: string): unknown;
350
- /**
351
- * Run a Drizzle-built statement and return its rows.
352
- *
353
- * @remarks
354
- * The CRUD methods resolve their table through the schema registry and reject
355
- * any name it does not declare, which leaves no way to read from a table the
356
- * ORM does not know — one mid-rename, above all — except by assembling SQL and
357
- * quoting identifiers by hand. This takes Drizzle's `sql` template instead, so
358
- * the dialect in use decides the quoting and the parameter binding.
359
- *
360
- * Concrete rather than abstract so existing adapters keep working unchanged.
361
- * The three drivers disagree about both the call and the result: node-postgres
362
- * returns `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 has
363
- * no `execute` at all and answers `all`. Keeping that here rather than at each
364
- * call site is the point — a caller reasoning about it would be reasoning
365
- * about a driver it cannot see.
366
- *
367
- * @param statement - Drizzle `sql` template to run
368
- * @returns Rows the statement produced
369
- */
370
- queryStatement<T = Record<string, unknown>>(statement: SQL): Promise<T[]>;
371
- /**
372
- * Map data keys from SQL column names (snake_case) to Drizzle JS property names (camelCase).
373
- * Drizzle schemas define columns as e.g. `createdAt: timestamp("created_at")` — the JS
374
- * property is `createdAt` but the SQL column is `created_at`. Services pass snake_case keys
375
- * because they match the DB column names. This method maps them to the JS names Drizzle expects.
376
- */
377
- protected mapDataToColumnNames(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
378
- /**
379
- * Map data keys from Drizzle JS property names to SQL column names for the
380
- * raw-SQL transaction insert path. The transaction context builds INSERT
381
- * statements from Object.keys(data) used directly as column identifiers, so a
382
- * table whose Drizzle property names differ from its SQL column names
383
- * (camelCase core tables like nextly_versions) needs its keys translated
384
- * first. For tables whose property names already equal their column names
385
- * (the dynamic dc_/single_/comp_ tables) every lookup is identity, so
386
- * existing callers are unaffected.
387
- */
388
- protected mapKeysToSqlColumns(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
389
- /**
390
- * Map a list of column identifiers (Drizzle property names) to their SQL
391
- * column names, for the raw-SQL transaction insert paths that build a
392
- * RETURNING clause from `options.returning`. Same identity behavior as
393
- * `mapKeysToSqlColumns`: names that are already SQL columns (the dynamic
394
- * dc_/single_/comp_ tables) pass through unchanged.
395
- */
396
- protected mapColumnNamesToSql(tableObj: unknown, names: string[]): string[];
397
- /**
398
- * Remap a raw-SQL result row's KEYS from SQL column names to Drizzle property
399
- * names, so the raw-SQL transaction insert paths return the same key casing
400
- * as the non-transactional (Drizzle) insert. Keys only - values are left
401
- * untouched, so this does not change how JSON/date columns are decoded. For
402
- * tables whose property names already equal their SQL columns (the dynamic
403
- * dc_/single_/comp_ tables) every lookup is identity, so existing callers see
404
- * no change.
405
- */
406
- protected mapRowKeysToJs<T = unknown>(tableObj: unknown, row: T): T;
407
- /**
408
- * Decode a raw-SQL result row's DATE column values the way a Drizzle query
409
- * would, so a write answers with the same representation a read of the same
410
- * column gives.
411
- *
412
- * A Drizzle query path runs every value through its column definition; a
413
- * raw-SQL path does not, so a dialect that stores a timestamp as a number
414
- * answers a write with that number while every read answers a `Date`. Only
415
- * date columns are touched, and a value that is already a `Date` is left
416
- * alone, so a driver that decodes on its own is unaffected.
417
- *
418
- * Runs after {@link mapRowKeysToJs}: keys are Drizzle property names by then,
419
- * which is what the table definition is keyed by.
420
- */
421
- protected mapDateValuesFromDriver<T = unknown>(tableObj: unknown, row: T): T;
422
- /**
423
- * Encode a row's DATE values the way a Drizzle query would before binding
424
- * them, so what lands in the column does not depend on the server's timezone.
425
- *
426
- * A column declared without a time zone stores a wall clock and records
427
- * nothing about which zone it belongs to, so both ends have to agree. Drizzle
428
- * writes UTC and reads UTC. A driver handed a `Date` writes the LOCAL wall
429
- * clock instead, and the same row then reads back shifted by the offset --
430
- * on a UTC server the two agree and nothing is visibly wrong, which is why
431
- * this survives CI.
432
- *
433
- * Only date columns are touched. A value that is not a `Date` is left as it
434
- * is, so a caller that already encoded one is not encoded twice.
435
- *
436
- * Keys may be spelled either way at this point, so both the Drizzle property
437
- * name and the SQL column name resolve.
438
- */
439
- protected mapDateValuesToDriver(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
440
- /**
441
- * Bring a row about to be written through a raw-SQL statement into the shape
442
- * a Drizzle query would have bound: SQL column names for keys, encoded values
443
- * for date columns.
444
- *
445
- * The mirror of {@link mapRowFromRawSql}. The raw-SQL write paths exist
446
- * because a dialect needs SQL a Drizzle query cannot express, not because
447
- * their callers want different values in the table.
448
- */
449
- protected mapRowToRawSql(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
450
- /**
451
- * Bring a raw-SQL result row into the shape a Drizzle query would have
452
- * produced: Drizzle property names for keys, decoded values for date columns.
453
- *
454
- * The raw-SQL write paths exist because a dialect needs SQL a Drizzle query
455
- * cannot express, not because their callers want a different row shape, so
456
- * every one of them ends here.
457
- */
458
- protected mapRowFromRawSql<T = unknown>(tableObj: unknown, row: T, aliases?: ReadonlyArray<{
459
- alias: string;
460
- jsName: string;
461
- }>): T;
462
- /**
463
- * The date columns a statement is about to return, and the alias each one's
464
- * wall clock is spelled out under.
465
- *
466
- * A driver turns a timestamp into a `Date` using ITS zone before any of this
467
- * code runs, and that conversion is lossy: a wall clock inside a
468
- * daylight-saving gap is a local time that does not exist, so the driver
469
- * normalizes it and the original is gone. Asking the database for the wall
470
- * clock as text alongside the row is the only way to read it exactly.
471
- *
472
- * `"*"` covers every date column; a projection covers only the ones it asked
473
- * for, so a caller still gets back what it requested and nothing more.
474
- */
475
- protected dateWallClockAliases(tableObj: unknown, returning: string[] | "*" | undefined): Array<{
476
- sqlName: string;
477
- alias: string;
478
- jsName: string;
479
- }>;
480
- /**
481
- * Replace each date in a row with the wall clock the database spelled out,
482
- * read as UTC, and drop the aliases that carried it.
483
- *
484
- * The statement writes a UTC wall clock, so reading one back as UTC is what
485
- * makes a write and a later read agree. Whatever the column actually stored
486
- * is what arrives -- a column keeping only whole seconds reports whole
487
- * seconds -- because this is the database's own text, not a value
488
- * reconstructed from the one that was bound.
489
- */
490
- protected applyWallClockAliases<T>(row: T, aliases: ReadonlyArray<{
491
- alias: string;
492
- jsName: string;
493
- }>): T;
494
- /**
495
- * Build a Drizzle column projection object (`{ propertyName: column }`) from a
496
- * requested column list, used by `select` (columns) and `insert` (returning).
497
- * A requested name resolves against either the Drizzle property name
498
- * (camelCase) or the SQL column name (snake_case); the projection is keyed by
499
- * the property name so the row shape matches a full select. Returns undefined
500
- * for `"*"` or when nothing resolves, so callers fall back to all columns.
501
- */
502
- protected buildColumnProjection(tableObj: unknown, names: string[] | "*" | undefined): Record<string, unknown> | undefined;
503
- /**
504
- * The requested column names split into what this table has and what it does not.
505
- *
506
- * One resolution, reported both ways, because two callers need different halves
507
- * of the same answer: a projection drops what it cannot find, while a distinct
508
- * count has to REFUSE it. Resolving twice would let the two disagree about what
509
- * "found" means — the SQL-name alias below is exactly the kind of detail a
510
- * second implementation gets wrong — and the count would then reject a column
511
- * the projection happily uses.
512
- *
513
- * Both spellings resolve: a caller may name the Drizzle property or the SQL
514
- * column, and either maps to the same projection key.
515
- */
516
- protected resolveColumns(tableObj: unknown, names: readonly string[]): {
517
- projection: Record<string, unknown>;
518
- unresolved: string[];
519
- };
520
- /**
521
- * Check if the adapter is currently connected.
522
- *
523
- * @remarks
524
- * Default implementation returns false. Subclasses should override
525
- * to provide accurate connection status.
526
- *
527
- * @returns True if connected, false otherwise
528
- */
529
- isConnected(): boolean;
530
- /**
531
- * Get connection pool statistics.
532
- *
533
- * @remarks
534
- * Returns null by default. Subclasses with connection pooling
535
- * should override to provide pool statistics.
536
- *
537
- * @returns Pool statistics or null if not applicable
538
- */
539
- getPoolStats(): PoolStats | null;
540
- /**
541
- * Default query timeout in milliseconds.
542
- *
543
- * @remarks
544
- * This value is used by executeWithTimeout() when no explicit timeout
545
- * is provided. Subclasses should set this from their config.
546
- *
547
- * @default 15000 (15 seconds)
548
- *
549
- * @protected
550
- */
551
- protected defaultQueryTimeoutMs: number;
552
- /**
553
- * Execute an async operation with a timeout.
554
- *
555
- * @remarks
556
- * Wraps an async operation with a timeout that aborts if the operation
557
- * exceeds the specified duration. Uses Promise.race for clean timeout
558
- * handling without memory leaks.
559
- *
560
- * When the timeout is reached, a DatabaseError with kind 'timeout' is thrown.
561
- * Note that this does NOT cancel the underlying database query - it only
562
- * prevents the calling code from waiting indefinitely. For true query
563
- * cancellation, use database-level statement timeouts (PostgreSQL) or
564
- * similar mechanisms.
565
- *
566
- * @param operation - Async operation to execute
567
- * @param timeoutMs - Timeout in milliseconds (defaults to defaultQueryTimeoutMs)
568
- * @returns Result of the operation
569
- *
570
- * @throws {DatabaseError} With kind 'timeout' if operation exceeds timeout
571
- *
572
- * @example
573
- * ```typescript
574
- * // Use default timeout
575
- * const result = await adapter.executeWithTimeout(
576
- * () => adapter.select('users', { limit: 1000 })
577
- * );
578
- *
579
- * // Use custom timeout for specific operation
580
- * const result = await adapter.executeWithTimeout(
581
- * () => adapter.select('large_table'),
582
- * 60000 // 60 seconds for large queries
583
- * );
584
- * ```
585
- *
586
- * @public
587
- */
588
- executeWithTimeout<T>(operation: () => Promise<T>, timeoutMs?: number): Promise<T>;
589
- /**
590
- * Set the default query timeout.
591
- *
592
- * @remarks
593
- * This method allows runtime configuration of the default timeout.
594
- * Subclasses should call this in their constructor or connect() method
595
- * based on their configuration.
596
- *
597
- * @param timeoutMs - Timeout in milliseconds (0 to disable)
598
- *
599
- * @protected
600
- */
601
- protected setDefaultQueryTimeout(timeoutMs: number): void;
602
- /**
603
- * Get the current default query timeout.
604
- *
605
- * @returns Current default timeout in milliseconds
606
- *
607
- * @public
608
- */
609
- getDefaultQueryTimeout(): number;
610
- /**
611
- * Select multiple records from a table.
612
- *
613
- * @remarks
614
- * Default implementation builds a SELECT query and executes it.
615
- * Subclasses can override for optimization or dialect-specific features.
616
- *
617
- * @param table - Table name
618
- * @param options - Select options (filtering, sorting, pagination)
619
- * @returns Array of matching records
620
- *
621
- * @throws {DatabaseError} If query fails
622
- *
623
- * @example
624
- * ```typescript
625
- * const users = await adapter.select('users', {
626
- * where: { and: [{ column: 'role', op: '=', value: 'admin' }] },
627
- * orderBy: [{ column: 'created_at', direction: 'desc' }],
628
- * limit: 10
629
- * });
630
- * ```
631
- */
632
- select<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T[]>;
633
- /**
634
- * Select a single record from a table.
635
- *
636
- * @remarks
637
- * Default implementation uses `select()` with limit 1 and returns first result.
638
- * Returns null if no matching record is found.
639
- *
640
- * @param table - Table name
641
- * @param options - Select options
642
- * @returns First matching record or null
643
- *
644
- * @throws {DatabaseError} If query fails
645
- *
646
- * @example
647
- * ```typescript
648
- * const user = await adapter.selectOne('users', {
649
- * where: { and: [{ column: 'email', op: '=', value: 'user@example.com' }] }
650
- * });
651
- * ```
652
- */
653
- /** The registered table object, or a refusal naming what is missing. */
654
- private requireTableObject;
655
- /**
656
- * The columns a distinct count groups by, or `undefined` for a row count.
657
- *
658
- * 🔴 EVERY named column must resolve, not merely one of them. A `distinctOn`
659
- * naming no column this table has would fall through to a row count, and one
660
- * naming a valid column beside a misspelled or since-removed column would
661
- * count distinct over a NARROWER key than the caller asked for. Both answer a
662
- * different question than the one asked, silently; the second is the worse of
663
- * the two, because a subset key groups more rows together and so UNDERCOUNTS,
664
- * which reads as a plausible number rather than as a fault. Refused here,
665
- * where the mistake was made, rather than surfacing as a wrong figure.
666
- */
667
- private countProjection;
668
- /**
669
- * `COUNT(*)` over a `SELECT DISTINCT` subquery.
670
- *
671
- * Its own function because it is a genuinely different query from the plain
672
- * count rather than a variation on one, and because building both inline made
673
- * the public method a chain of decisions the complexity gate objected to
674
- * before a reader would have.
675
- */
676
- private countDistinctRows;
677
- /** `COUNT(*)` over the table itself. */
678
- private countAllRows;
679
- /**
680
- * How many rows match, or how many DISTINCT combinations of some columns do.
681
- *
682
- * The data layer had no count at all: collection totals go through
683
- * `countEntries`, an access-controlled path built for collection tables, and
684
- * nothing could count a system table. A caller wanting one selected the rows
685
- * and measured the array, which transfers every row to learn a number and
686
- * cannot be bounded without making the number wrong.
687
- *
688
- * 🔴 `distinctOn` compiles to `COUNT(*)` over a `SELECT DISTINCT` SUBQUERY,
689
- * never to `COUNT(DISTINCT a, b)`. The inline form is not portable and fails
690
- * in the direction that is hardest to notice -- MySQL accepts it, PostgreSQL
691
- * needs a row constructor, and SQLite rejects it outright with "wrong number
692
- * of arguments to function count()" -- so a query written against one engine
693
- * is a syntax error on another. The subquery is the single form all three
694
- * accept, and building it here rather than at each call site is what keeps
695
- * the answer identical per dialect.
696
- */
697
- count(table: string, options?: CountOptions, executor?: unknown): Promise<number>;
698
- selectOne<T = unknown>(table: string, options?: SelectOptions, executor?: unknown): Promise<T | null>;
699
- /**
700
- * Insert a single record into a table.
701
- *
702
- * @remarks
703
- * Default implementation handles databases with and without RETURNING support.
704
- * For databases without RETURNING (MySQL), performs INSERT followed by SELECT.
705
- *
706
- * @param table - Table name
707
- * @param data - Record data to insert
708
- * @param options - Insert options
709
- * @returns Inserted record (with RETURNING columns if specified)
710
- *
711
- * @throws {DatabaseError} If insert fails
712
- *
713
- * @example
714
- * ```typescript
715
- * const user = await adapter.insert('users', {
716
- * email: 'user@example.com',
717
- * name: 'John Doe'
718
- * }, { returning: ['id', 'email', 'created_at'] });
719
- * ```
720
- */
721
- insert<T = unknown>(table: string, data: Record<string, unknown>, options?: InsertOptions): Promise<T>;
722
- /**
723
- * Insert multiple records into a table.
724
- *
725
- * @remarks
726
- * Default implementation performs individual inserts in sequence.
727
- * Subclasses can override for bulk insert optimization (e.g., COPY in PostgreSQL).
728
- *
729
- * @param table - Table name
730
- * @param data - Array of records to insert
731
- * @param options - Insert options
732
- * @returns Inserted records (with RETURNING columns if specified)
733
- *
734
- * @throws {DatabaseError} If insert fails
735
- *
736
- * @example
737
- * ```typescript
738
- * const users = await adapter.insertMany('users', [
739
- * { email: 'user1@example.com', name: 'User 1' },
740
- * { email: 'user2@example.com', name: 'User 2' }
741
- * ], { returning: ['id'] });
742
- * ```
743
- */
744
- insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions): Promise<T[]>;
745
- /**
746
- * Update records in a table.
747
- *
748
- * @remarks
749
- * Default implementation builds an UPDATE query with WHERE clause.
750
- * Returns updated records if RETURNING is supported and requested.
751
- *
752
- * @param table - Table name
753
- * @param data - Data to update
754
- * @param where - Conditions for records to update
755
- * @param options - Update options
756
- * @returns Updated records (with RETURNING columns if specified)
757
- *
758
- * @throws {DatabaseError} If update fails
759
- *
760
- * @example
761
- * ```typescript
762
- * const updated = await adapter.update('users',
763
- * { status: 'active' },
764
- * { and: [{ column: 'id', op: '=', value: userId }] },
765
- * { returning: ['id', 'status', 'updated_at'] }
766
- * );
767
- * ```
768
- */
769
- update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions, executor?: unknown): Promise<T[]>;
770
- /**
771
- * Update records in a table and report how many rows the statement affected.
772
- *
773
- * The count is the whole return value, mirroring `delete`. `update` cannot answer this: without
774
- * `returning` it discards the driver's count, and WITH `returning` on a dialect that lacks
775
- * RETURNING it re-SELECTs using the same WHERE — so a conditional update that just changed a
776
- * column named in that WHERE reads back zero rows and a write that landed reports as unmatched.
777
- * Reading the driver's own count has no second query to disagree with the first.
778
- *
779
- * 🔴 MySQL reports CHANGED rows, not matched rows: an UPDATE that matches a row but writes values
780
- * identical to what it holds counts zero. A caller using this as a compare-and-set must therefore
781
- * include a column the write always moves — a version bump, a timestamp with enough resolution —
782
- * so that matched implies changed. Postgres (`rowCount`) and SQLite (`changes`) count matched
783
- * rows and do not need the precaution, which is exactly why it cannot be dropped: the dialect
784
- * where the distinction exists is the one with no RETURNING to fall back on.
785
- */
786
- updateCount(table: string, data: Record<string, unknown>, where: WhereClause, executor?: unknown): Promise<number>;
787
- /**
788
- * Delete records from a table.
789
- *
790
- * @remarks
791
- * Default implementation builds a DELETE query with WHERE clause.
792
- * Returns the number of deleted records.
793
- *
794
- * @param table - Table name
795
- * @param where - Conditions for records to delete
796
- * @param options - Delete options
797
- * @returns Number of deleted records
798
- *
799
- * @throws {DatabaseError} If delete fails
800
- *
801
- * @example
802
- * ```typescript
803
- * const count = await adapter.delete('users', {
804
- * and: [{ column: 'status', op: '=', value: 'inactive' }]
805
- * });
806
- * console.log(`Deleted ${count} users`);
807
- * ```
808
- */
809
- delete(table: string, where: WhereClause, _options?: DeleteOptions, executor?: unknown): Promise<number>;
810
- /**
811
- * Upsert (INSERT or UPDATE) a record.
812
- *
813
- * @remarks
814
- * Default implementation uses dialect-specific ON CONFLICT syntax.
815
- * PostgreSQL/SQLite: ON CONFLICT ... DO UPDATE
816
- * MySQL: the MySQL adapter overrides this, resolving the conflict by the
817
- * conflict columns (see its `upsert`)
818
- *
819
- * @param table - Table name
820
- * @param data - Record data
821
- * @param options - Upsert options (must specify conflict columns)
822
- * @returns Upserted record (with RETURNING columns if specified)
823
- *
824
- * @throws {DatabaseError} If upsert fails
825
- *
826
- * @example
827
- * ```typescript
828
- * const user = await adapter.upsert('users', {
829
- * email: 'user@example.com',
830
- * name: 'Updated Name'
831
- * }, {
832
- * conflictColumns: ['email'],
833
- * updateColumns: ['name'],
834
- * returning: ['id', 'email', 'name']
835
- * });
836
- * ```
837
- */
838
- upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions, executor?: unknown): Promise<T>;
839
- /**
840
- * Run pending migrations.
841
- *
842
- * @remarks
843
- * Default implementation is a placeholder. Subclasses should implement
844
- * migration tracking and execution logic.
845
- *
846
- * @param migrations - Array of migrations to run
847
- * @returns Migration result with applied and pending migrations
848
- *
849
- * @throws {DatabaseError} If migration fails
850
- */
851
- migrate(_migrations: Migration[]): Promise<MigrationResult>;
852
- /**
853
- * Rollback the last migration.
854
- *
855
- * @remarks
856
- * Default implementation is a placeholder. Subclasses should implement
857
- * migration rollback logic.
858
- *
859
- * @returns Migration result after rollback
860
- *
861
- * @throws {DatabaseError} If rollback fails
862
- */
863
- rollback(): Promise<MigrationResult>;
864
- /**
865
- * Get migration status.
866
- *
867
- * @remarks
868
- * Default implementation is a placeholder. Subclasses should implement
869
- * migration status checking.
870
- *
871
- * @returns Current migration status
872
- *
873
- * @throws {DatabaseError} If status check fails
874
- */
875
- getMigrationStatus(): Promise<MigrationResult>;
876
- /**
877
- * Create a new table.
878
- *
879
- * @remarks
880
- * Default implementation is a placeholder. Subclasses should implement
881
- * table creation logic.
882
- *
883
- * @param definition - Table definition
884
- * @param options - Creation options
885
- *
886
- * @throws {DatabaseError} If table creation fails
887
- */
888
- createTable(definition: TableDefinition, options?: CreateTableOptions): Promise<void>;
889
- /**
890
- * Drop a table.
891
- *
892
- * @remarks
893
- * Default implementation is a placeholder. Subclasses should implement
894
- * table dropping logic.
895
- *
896
- * @param tableName - Name of table to drop
897
- * @param options - Drop options
898
- *
899
- * @throws {DatabaseError} If table drop fails
900
- */
901
- dropTable(tableName: string, options?: DropTableOptions): Promise<void>;
902
- /**
903
- * Alter an existing table.
904
- *
905
- * @remarks
906
- * Default implementation is a placeholder. Subclasses should implement
907
- * table alteration logic.
908
- *
909
- * @param tableName - Name of table to alter
910
- * @param operations - Alteration operations
911
- * @param options - Alter options
912
- *
913
- * @throws {DatabaseError} If table alteration fails
914
- */
915
- alterTable(tableName: string, operations: AlterTableOperation[], _options?: AlterTableOptions): Promise<void>;
916
- /**
917
- * Check if a table exists in the database.
918
- *
919
- * @remarks
920
- * Uses dialect-specific information schema queries to check table existence.
921
- * This is useful for development mode auto-sync to determine whether to
922
- * CREATE or DROP/CREATE tables.
923
- *
924
- * @param tableName - Name of table to check
925
- * @param schema - Optional schema name (defaults to 'public' for PostgreSQL)
926
- * @returns True if table exists, false otherwise
927
- *
928
- * @throws {DatabaseError} If query fails
929
- *
930
- * @example
931
- * ```typescript
932
- * const exists = await adapter.tableExists('users');
933
- * if (exists) {
934
- * await adapter.dropTable('users');
935
- * }
936
- * await adapter.createTable(userTableDef);
937
- * ```
938
- */
939
- tableExists(tableName: string, schema?: string): Promise<boolean>;
940
- /**
941
- * Get list of all tables in the database.
942
- *
943
- * @remarks
944
- * Uses dialect-specific information schema queries to list tables.
945
- * Useful for detecting orphaned tables or validating schema state.
946
- *
947
- * @param schema - Optional schema name (defaults to 'public' for PostgreSQL)
948
- * @returns Array of table names
949
- *
950
- * @throws {DatabaseError} If query fails
951
- */
952
- listTables(schema?: string): Promise<string[]>;
953
- /**
954
- * Escape a table or column identifier.
955
- *
956
- * @remarks
957
- * Default uses double quotes (SQL standard).
958
- * MySQL adapter should override to use backticks.
959
- *
960
- * @param identifier - Identifier to escape
961
- * @returns Escaped identifier
962
- *
963
- * @protected
964
- */
965
- protected escapeIdentifier(identifier: string): string;
966
- /**
967
- * Create a DatabaseError with proper error kind classification.
968
- *
969
- * @remarks
970
- * Protected helper for subclasses to create consistent errors.
971
- * Subclasses can override to add dialect-specific error classification.
972
- *
973
- * @param kind - Error kind
974
- * @param message - Error message
975
- * @param cause - Original error
976
- * @returns DatabaseError instance
977
- *
978
- * @protected
979
- */
980
- protected createDatabaseError(kind: DatabaseErrorKind, message: string, cause?: Error): DatabaseError;
981
- /**
982
- * Helper to create transaction context CRUD forwarding methods.
983
- *
984
- * @param txDb - Thunk returning the transaction-bound Drizzle executor
985
- * @returns Object providing forwarded CRUD and getDrizzle methods
986
- *
987
- * @protected
988
- */
989
- protected createTransactionForwarders(txDb: () => unknown): TransactionCrudForwarders;
990
- /**
991
- * The Drizzle handles one transaction hands out; see
992
- * `transactionDrizzleHandles`. `build` makes an instance on the
993
- * transaction's own connection, with the relations config when given one.
994
- *
995
- * @protected
996
- */
997
- protected transactionDrizzleHandles<TBare>(build: (relations?: AnyRelations) => TBare): {
998
- bare: () => TBare;
999
- withRelations: <T = unknown>(relations: AnyRelations) => T;
1000
- };
1001
- /**
1002
- * A transaction context's `update`, for each adapter to bind.
1003
- *
1004
- * Not forwarded to the pooled `update` the way `select` and `delete` are:
1005
- * that one goes through the Drizzle query builder, which writes the columns
1006
- * the runtime MODEL declares, and a transaction's update must reach the
1007
- * columns the physical TABLE has — the localization transition window
1008
- * writes a column the model has already moved to a companion table that
1009
- * does not exist yet. The INSERT half of every transaction context already
1010
- * builds its own statement for that reason; `update-statement.ts` is the
1011
- * UPDATE half, spelled once for the three adapters, and this runs it: on
1012
- * the transaction executor, classified with the operation and table named
1013
- * as the pooled `update` classifies its failures, and read back through
1014
- * `select` on the same executor when the caller asked for rows.
1015
- *
1016
- * That read is by the rows' IDENTITY where the dialect can report it: on
1017
- * PostgreSQL and SQLite the statement carries `RETURNING <primary key>`, and
1018
- * the read-back asks for exactly those rows — so a row another transaction
1019
- * adds under the same predicate meanwhile is not among them, and an update
1020
- * whose own write falsifies its predicate still reads its rows back. MySQL
1021
- * has no RETURNING, so there the read re-runs the predicate, as the pooled
1022
- * `update` always has on that dialect; a table with no primary key in its
1023
- * model reads back the same way.
1024
- *
1025
- * @param txDb - thunk returning the transaction-bound Drizzle instance
1026
- * @param run - how this dialect runs a statement on that instance, and the
1027
- * rows it returns when the statement carries RETURNING: better-sqlite3
1028
- * answers synchronously, the pooled drivers do not
1029
- * @param bindUnmodeled - how a value binds when the model declares no
1030
- * column for it; a declared column binds through its own encoder
1031
- * @returns the context's `update` method
1032
- */
1033
- protected transactionUpdate(txDb: () => unknown, run: (statement: SQL, returnsRows: boolean) => Promise<Record<string, unknown>[] | undefined> | Record<string, unknown>[] | undefined, bindUnmodeled: (value: unknown) => unknown): TransactionContext["update"];
1034
- /**
1035
- * The columns that identify a row of this table, under both spellings: the
1036
- * SQL name RETURNING reports and the Drizzle property name the query
1037
- * builder's WHERE is addressed by. Columns flagged primary first; failing
1038
- * that, the table-level primary key the dialect's table config carries
1039
- * (`primaryKey({ columns })` leaves each column's flag false), which each
1040
- * adapter reads through its own dialect. Empty when the model declares
1041
- * neither, and the read-back falls back to the caller's predicate.
1042
- */
1043
- protected identityColumns(tableObj: Record<string, unknown>): Array<{
1044
- jsName: string;
1045
- sqlName: string;
1046
- }>;
1047
- /**
1048
- * How a value binds to a column the model does not declare, on a driver
1049
- * that binds scalars, dates and binary natively: a structured value goes
1050
- * as JSON text, since what node-postgres and mysql2 make of a bare object
1051
- * or array is not JSON. For the adapters to hand `transactionUpdate`.
1052
- */
1053
- protected bindUnmodeledStructuredAsJson(value: unknown): unknown;
1054
- /**
1055
- * Refuse an upsert target every dialect would not answer alike: a conflict
1056
- * column named twice, which SQLite rejects as no constraint's target and
1057
- * MySQL would accept; and, when nothing is to be updated, a conflict column
1058
- * left for the database to fill, since the row that stands is then read
1059
- * back by a value the caller never gave. Shared with the dialects that
1060
- * override `upsert`, so the refusals are one rule.
1061
- */
1062
- protected assertUpsertTarget(table: string, data: Record<string, unknown>, options: UpsertOptions, keepExisting: boolean): void;
1063
- /**
1064
- * The columns of a table-level `primaryKey({ columns })`, as the dialect's
1065
- * table config reports them. The base class cannot read that config without
1066
- * naming a dialect, so each adapter answers for its own; a dialect that does
1067
- * not answer reports none.
1068
- */
1069
- protected compositePrimaryKey(_tableObj: Record<string, unknown>): object[];
1070
- /** The registered table object, or the error every CRUD method throws without one. */
1071
- private resolvedTableObject;
1072
- /**
1073
- * The statement `transactionUpdate` runs.
1074
- *
1075
- * @throws when nothing would be written — every key `undefined`, or none at
1076
- * all. The query builder refused that too ("No values to set"), and a
1077
- * patch that names nothing is a caller's mistake rather than a write of
1078
- * nothing.
1079
- */
1080
- private buildTransactionUpdate;
1081
- /**
1082
- * Whether a transaction's `update` reads the rows it changed back: the
1083
- * caller named columns, or `*`. An empty list, like no option at all, asks
1084
- * for nothing and `update` answers `[]`, as it always has. The rows come
1085
- * from a read of the update's own WHERE on its own transaction, so they are
1086
- * the model's view of the row, decoded as every read is decoded — which is
1087
- * what the query-builder update returned for them, and why the named list
1088
- * selects nothing narrower.
1089
- */
1090
- private updateReturnsRows;
1091
- /**
1092
- * The driver's own error inside `error`: the first in its `cause` chain that
1093
- * `isDriverError` recognises, or `error` itself when none does.
1094
- *
1095
- * A query that runs through Drizzle fails with Drizzle's `DrizzleQueryError`,
1096
- * whose message is the SQL statement and which carries no driver code; the
1097
- * driver's error, the only object that knows what actually went wrong, is
1098
- * its `cause`. A dialect's {@link classifyError} classifies from what this
1099
- * returns, so a failure reads the same whether or not Drizzle wrapped it.
1100
- *
1101
- * The walk is bounded, because an error chain can be made cyclic and a
1102
- * classifier that can hang is worse than one that gives up. Falling back to
1103
- * `error` keeps an error that carries no code anywhere classified as before.
1104
- *
1105
- * @param error - The error as it was caught
1106
- * @param isDriverError - Whether a link in the chain is the driver's error
1107
- * @returns The driver's error, or `error` when no link is
1108
- */
1109
- protected driverErrorIn<T extends {
1110
- cause?: unknown;
1111
- }>(error: unknown, isDriverError: (candidate: T) => boolean): T;
1112
- /**
1113
- * Classify an error into a DatabaseError.
1114
- *
1115
- * @remarks
1116
- * Subclasses can override this method to add dialect-specific error code classification.
1117
- *
1118
- * @param error - Original error
1119
- * @param sql - SQL statement that caused the error (optional)
1120
- * @returns DatabaseError instance
1121
- *
1122
- * @protected
1123
- */
1124
- protected classifyError(error: unknown, sql?: string): DatabaseError;
1125
- /**
1126
- * Handle query errors and convert to DatabaseError.
1127
- *
1128
- * @remarks
1129
- * Protected helper for consistent error handling across CRUD operations.
1130
- * Delegates to `classifyError` and attaches operation and table context if not present.
1131
- * Subclasses override `classifyError` to provide dialect-specific error code classification.
1132
- *
1133
- * @param error - Original error
1134
- * @param operation - Operation that failed
1135
- * @param table - Table name
1136
- * @returns DatabaseError instance
1137
- *
1138
- * @protected
1139
- */
1140
- protected handleQueryError(error: unknown, operation: string, table: string): DatabaseError;
1141
- }
1142
-
1143
- export { DrizzleAdapter as D, type TransactionCrudDelegator as T, type TransactionCrudForwarders as a };