@nextlyhq/adapter-drizzle 0.0.1

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 (43) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +9 -0
  3. package/dist/adapter-BxJVtttb.d.ts +592 -0
  4. package/dist/adapter-nvlxFkF-.d.cts +592 -0
  5. package/dist/core-CVO7WYDj.d.cts +74 -0
  6. package/dist/core-CVO7WYDj.d.ts +74 -0
  7. package/dist/error-um1d_3Uo.d.cts +105 -0
  8. package/dist/error-um1d_3Uo.d.ts +105 -0
  9. package/dist/index.cjs +1137 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +57 -0
  12. package/dist/index.d.ts +57 -0
  13. package/dist/index.mjs +1134 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/migration-BbO5meEV.d.cts +622 -0
  16. package/dist/migration-Qe70wDOC.d.ts +622 -0
  17. package/dist/migrations.cjs +195 -0
  18. package/dist/migrations.cjs.map +1 -0
  19. package/dist/migrations.d.cts +351 -0
  20. package/dist/migrations.d.ts +351 -0
  21. package/dist/migrations.mjs +185 -0
  22. package/dist/migrations.mjs.map +1 -0
  23. package/dist/schema/index.cjs +10 -0
  24. package/dist/schema/index.cjs.map +1 -0
  25. package/dist/schema/index.d.cts +133 -0
  26. package/dist/schema/index.d.ts +133 -0
  27. package/dist/schema/index.mjs +7 -0
  28. package/dist/schema/index.mjs.map +1 -0
  29. package/dist/schema-BDn8WfSL.d.cts +200 -0
  30. package/dist/schema-BIQ0YQZ_.d.ts +200 -0
  31. package/dist/types/index.cjs +24 -0
  32. package/dist/types/index.cjs.map +1 -0
  33. package/dist/types/index.d.cts +210 -0
  34. package/dist/types/index.d.ts +210 -0
  35. package/dist/types/index.mjs +21 -0
  36. package/dist/types/index.mjs.map +1 -0
  37. package/dist/version-check.cjs +154 -0
  38. package/dist/version-check.cjs.map +1 -0
  39. package/dist/version-check.d.cts +43 -0
  40. package/dist/version-check.d.ts +43 -0
  41. package/dist/version-check.mjs +150 -0
  42. package/dist/version-check.mjs.map +1 -0
  43. package/package.json +94 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NextlyHQ <info@nextlyhq.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @nextlyhq/adapter-drizzle
2
+
3
+ Internal Drizzle ORM utilities for Nextly's database adapters.
4
+
5
+ > This package is part of Nextly's internals. It is installed automatically as a dependency of [`nextly`](../nextly). Choose [`@nextlyhq/adapter-postgres`](../adapter-postgres), [`@nextlyhq/adapter-mysql`](../adapter-mysql), or [`@nextlyhq/adapter-sqlite`](../adapter-sqlite) for your project.
6
+
7
+ ## License
8
+
9
+ [MIT](../../LICENSE.md)
@@ -0,0 +1,592 @@
1
+ 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 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
+
6
+ /**
7
+ * Base database adapter abstract class.
8
+ *
9
+ * @remarks
10
+ * This abstract class provides the foundation for all dialect-specific database adapters
11
+ * (PostgreSQL, MySQL, SQLite). It defines required abstract methods that must be implemented
12
+ * by subclasses, while providing default implementations for CRUD operations and query building.
13
+ *
14
+ * Dialect adapters can override any default method to provide optimized implementations.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+
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
+ declare abstract class DrizzleAdapter {
67
+ /**
68
+ * Database dialect identifier.
69
+ *
70
+ * @remarks
71
+ * Must be set by subclass to identify the database type.
72
+ */
73
+ abstract readonly dialect: SupportedDialect;
74
+ /**
75
+ * Establish connection to the database.
76
+ *
77
+ * @remarks
78
+ * This method should be idempotent - calling it multiple times
79
+ * should not create multiple connections.
80
+ *
81
+ * @throws {DatabaseError} If connection fails
82
+ */
83
+ abstract connect(): Promise<void>;
84
+ /**
85
+ * Close database connection and release resources.
86
+ *
87
+ * @remarks
88
+ * This method should be idempotent - calling it multiple times
89
+ * should be safe.
90
+ */
91
+ abstract disconnect(): Promise<void>;
92
+ /**
93
+ * Execute a raw SQL query.
94
+ *
95
+ * @param sql - SQL query to execute
96
+ * @param params - Query parameters
97
+ * @returns Array of result rows
98
+ *
99
+ * @throws {DatabaseError} If query execution fails
100
+ */
101
+ abstract executeQuery<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
102
+ /**
103
+ * Execute operations within a database transaction.
104
+ *
105
+ * @remarks
106
+ * The transaction is automatically committed on success or rolled back on error.
107
+ * Supports nested transactions via savepoints on databases that support them.
108
+ *
109
+ * @param callback - Function to execute within transaction
110
+ * @param options - Transaction options
111
+ * @returns Result from the callback
112
+ *
113
+ * @throws {DatabaseError} If transaction fails
114
+ */
115
+ abstract transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
116
+ /**
117
+ * Get database capabilities.
118
+ *
119
+ * @remarks
120
+ * Returns static capability flags for this adapter's dialect.
121
+ * Used by services to conditionally enable features or implement fallbacks.
122
+ *
123
+ * @returns Database capability flags
124
+ */
125
+ abstract getCapabilities(): DatabaseCapabilities;
126
+ /**
127
+ * Get the raw Drizzle ORM instance for direct queries.
128
+ *
129
+ * @remarks
130
+ * This method provides escape hatch access to the raw Drizzle instance.
131
+ * Use this when you need to run complex queries that the adapter API
132
+ * doesn't support, or for legacy code migration.
133
+ *
134
+ * **Note:** Prefer using adapter methods when possible as they provide:
135
+ * - Database-agnostic API
136
+ * - Consistent error handling
137
+ * - Proper connection pooling
138
+ *
139
+ * @param schema - Optional schema object for typed queries
140
+ * @returns Raw Drizzle ORM database instance
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // For legacy code that needs direct Drizzle access
145
+ * const db = adapter.getDrizzle(mySchemas);
146
+ * const result = await db.insert(users).values({ ... }).returning();
147
+ * ```
148
+ */
149
+ abstract getDrizzle<T = unknown>(schema?: Record<string, unknown>): T;
150
+ /**
151
+ * Table resolver for looking up Drizzle table objects by name.
152
+ * When set, CRUD methods use Drizzle's query API instead of raw SQL.
153
+ * Set via setTableResolver() after boot-time schema loading.
154
+ */
155
+ protected tableResolver: TableResolver | null;
156
+ /**
157
+ * Set the table resolver for Drizzle query API support.
158
+ * When a resolver is set, CRUD methods (select, insert, update, delete, upsert)
159
+ * will use Drizzle's query API (db.select().from(), etc.) instead of raw SQL
160
+ * string building. Falls back to raw SQL if the resolver doesn't have the table.
161
+ *
162
+ * @param resolver - TableResolver implementation (e.g. SchemaRegistry)
163
+ */
164
+ setTableResolver(resolver: TableResolver): void;
165
+ /**
166
+ * Get a Drizzle table object by name from the resolver.
167
+ * Returns null if no resolver is set or table is not found.
168
+ */
169
+ protected getTableObject(tableName: string): unknown;
170
+ /**
171
+ * Map data keys from SQL column names (snake_case) to Drizzle JS property names (camelCase).
172
+ * Drizzle schemas define columns as e.g. `createdAt: timestamp("created_at")` — the JS
173
+ * property is `createdAt` but the SQL column is `created_at`. Services pass snake_case keys
174
+ * because they match the DB column names. This method maps them to the JS names Drizzle expects.
175
+ */
176
+ protected mapDataToColumnNames(tableObj: unknown, data: Record<string, unknown>): Record<string, unknown>;
177
+ /**
178
+ * Check if the adapter is currently connected.
179
+ *
180
+ * @remarks
181
+ * Default implementation returns false. Subclasses should override
182
+ * to provide accurate connection status.
183
+ *
184
+ * @returns True if connected, false otherwise
185
+ */
186
+ isConnected(): boolean;
187
+ /**
188
+ * Get connection pool statistics.
189
+ *
190
+ * @remarks
191
+ * Returns null by default. Subclasses with connection pooling
192
+ * should override to provide pool statistics.
193
+ *
194
+ * @returns Pool statistics or null if not applicable
195
+ */
196
+ getPoolStats(): PoolStats | null;
197
+ /**
198
+ * Default query timeout in milliseconds.
199
+ *
200
+ * @remarks
201
+ * This value is used by executeWithTimeout() when no explicit timeout
202
+ * is provided. Subclasses should set this from their config.
203
+ *
204
+ * @default 15000 (15 seconds)
205
+ *
206
+ * @protected
207
+ */
208
+ protected defaultQueryTimeoutMs: number;
209
+ /**
210
+ * Execute an async operation with a timeout.
211
+ *
212
+ * @remarks
213
+ * Wraps an async operation with a timeout that aborts if the operation
214
+ * exceeds the specified duration. Uses Promise.race for clean timeout
215
+ * handling without memory leaks.
216
+ *
217
+ * When the timeout is reached, a DatabaseError with kind 'timeout' is thrown.
218
+ * Note that this does NOT cancel the underlying database query - it only
219
+ * prevents the calling code from waiting indefinitely. For true query
220
+ * cancellation, use database-level statement timeouts (PostgreSQL) or
221
+ * similar mechanisms.
222
+ *
223
+ * @param operation - Async operation to execute
224
+ * @param timeoutMs - Timeout in milliseconds (defaults to defaultQueryTimeoutMs)
225
+ * @returns Result of the operation
226
+ *
227
+ * @throws {DatabaseError} With kind 'timeout' if operation exceeds timeout
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * // Use default timeout
232
+ * const result = await adapter.executeWithTimeout(
233
+ * () => adapter.select('users', { limit: 1000 })
234
+ * );
235
+ *
236
+ * // Use custom timeout for specific operation
237
+ * const result = await adapter.executeWithTimeout(
238
+ * () => adapter.select('large_table'),
239
+ * 60000 // 60 seconds for large queries
240
+ * );
241
+ * ```
242
+ *
243
+ * @public
244
+ */
245
+ executeWithTimeout<T>(operation: () => Promise<T>, timeoutMs?: number): Promise<T>;
246
+ /**
247
+ * Set the default query timeout.
248
+ *
249
+ * @remarks
250
+ * This method allows runtime configuration of the default timeout.
251
+ * Subclasses should call this in their constructor or connect() method
252
+ * based on their configuration.
253
+ *
254
+ * @param timeoutMs - Timeout in milliseconds (0 to disable)
255
+ *
256
+ * @protected
257
+ */
258
+ protected setDefaultQueryTimeout(timeoutMs: number): void;
259
+ /**
260
+ * Get the current default query timeout.
261
+ *
262
+ * @returns Current default timeout in milliseconds
263
+ *
264
+ * @public
265
+ */
266
+ getDefaultQueryTimeout(): number;
267
+ /**
268
+ * Select multiple records from a table.
269
+ *
270
+ * @remarks
271
+ * Default implementation builds a SELECT query and executes it.
272
+ * Subclasses can override for optimization or dialect-specific features.
273
+ *
274
+ * @param table - Table name
275
+ * @param options - Select options (filtering, sorting, pagination)
276
+ * @returns Array of matching records
277
+ *
278
+ * @throws {DatabaseError} If query fails
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * const users = await adapter.select('users', {
283
+ * where: { and: [{ column: 'role', op: '=', value: 'admin' }] },
284
+ * orderBy: [{ column: 'created_at', direction: 'desc' }],
285
+ * limit: 10
286
+ * });
287
+ * ```
288
+ */
289
+ select<T = unknown>(table: string, options?: SelectOptions): Promise<T[]>;
290
+ /**
291
+ * Select a single record from a table.
292
+ *
293
+ * @remarks
294
+ * Default implementation uses `select()` with limit 1 and returns first result.
295
+ * Returns null if no matching record is found.
296
+ *
297
+ * @param table - Table name
298
+ * @param options - Select options
299
+ * @returns First matching record or null
300
+ *
301
+ * @throws {DatabaseError} If query fails
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const user = await adapter.selectOne('users', {
306
+ * where: { and: [{ column: 'email', op: '=', value: 'user@example.com' }] }
307
+ * });
308
+ * ```
309
+ */
310
+ selectOne<T = unknown>(table: string, options?: SelectOptions): Promise<T | null>;
311
+ /**
312
+ * Insert a single record into a table.
313
+ *
314
+ * @remarks
315
+ * Default implementation handles databases with and without RETURNING support.
316
+ * For databases without RETURNING (MySQL), performs INSERT followed by SELECT.
317
+ *
318
+ * @param table - Table name
319
+ * @param data - Record data to insert
320
+ * @param options - Insert options
321
+ * @returns Inserted record (with RETURNING columns if specified)
322
+ *
323
+ * @throws {DatabaseError} If insert fails
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * const user = await adapter.insert('users', {
328
+ * email: 'user@example.com',
329
+ * name: 'John Doe'
330
+ * }, { returning: ['id', 'email', 'created_at'] });
331
+ * ```
332
+ */
333
+ insert<T = unknown>(table: string, data: Record<string, unknown>, options?: InsertOptions): Promise<T>;
334
+ /**
335
+ * Insert multiple records into a table.
336
+ *
337
+ * @remarks
338
+ * Default implementation performs individual inserts in sequence.
339
+ * Subclasses can override for bulk insert optimization (e.g., COPY in PostgreSQL).
340
+ *
341
+ * @param table - Table name
342
+ * @param data - Array of records to insert
343
+ * @param options - Insert options
344
+ * @returns Inserted records (with RETURNING columns if specified)
345
+ *
346
+ * @throws {DatabaseError} If insert fails
347
+ *
348
+ * @example
349
+ * ```typescript
350
+ * const users = await adapter.insertMany('users', [
351
+ * { email: 'user1@example.com', name: 'User 1' },
352
+ * { email: 'user2@example.com', name: 'User 2' }
353
+ * ], { returning: ['id'] });
354
+ * ```
355
+ */
356
+ insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions): Promise<T[]>;
357
+ /**
358
+ * Update records in a table.
359
+ *
360
+ * @remarks
361
+ * Default implementation builds an UPDATE query with WHERE clause.
362
+ * Returns updated records if RETURNING is supported and requested.
363
+ *
364
+ * @param table - Table name
365
+ * @param data - Data to update
366
+ * @param where - Conditions for records to update
367
+ * @param options - Update options
368
+ * @returns Updated records (with RETURNING columns if specified)
369
+ *
370
+ * @throws {DatabaseError} If update fails
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * const updated = await adapter.update('users',
375
+ * { status: 'active' },
376
+ * { and: [{ column: 'id', op: '=', value: userId }] },
377
+ * { returning: ['id', 'status', 'updated_at'] }
378
+ * );
379
+ * ```
380
+ */
381
+ update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions): Promise<T[]>;
382
+ /**
383
+ * Delete records from a table.
384
+ *
385
+ * @remarks
386
+ * Default implementation builds a DELETE query with WHERE clause.
387
+ * Returns the number of deleted records.
388
+ *
389
+ * @param table - Table name
390
+ * @param where - Conditions for records to delete
391
+ * @param options - Delete options
392
+ * @returns Number of deleted records
393
+ *
394
+ * @throws {DatabaseError} If delete fails
395
+ *
396
+ * @example
397
+ * ```typescript
398
+ * const count = await adapter.delete('users', {
399
+ * and: [{ column: 'status', op: '=', value: 'inactive' }]
400
+ * });
401
+ * console.log(`Deleted ${count} users`);
402
+ * ```
403
+ */
404
+ delete(table: string, where: WhereClause, _options?: DeleteOptions): Promise<number>;
405
+ /**
406
+ * Upsert (INSERT or UPDATE) a record.
407
+ *
408
+ * @remarks
409
+ * Default implementation uses dialect-specific ON CONFLICT syntax.
410
+ * PostgreSQL/SQLite: ON CONFLICT ... DO UPDATE
411
+ * MySQL: ON DUPLICATE KEY UPDATE
412
+ *
413
+ * @param table - Table name
414
+ * @param data - Record data
415
+ * @param options - Upsert options (must specify conflict columns)
416
+ * @returns Upserted record (with RETURNING columns if specified)
417
+ *
418
+ * @throws {DatabaseError} If upsert fails
419
+ *
420
+ * @example
421
+ * ```typescript
422
+ * const user = await adapter.upsert('users', {
423
+ * email: 'user@example.com',
424
+ * name: 'Updated Name'
425
+ * }, {
426
+ * conflictColumns: ['email'],
427
+ * updateColumns: ['name'],
428
+ * returning: ['id', 'email', 'name']
429
+ * });
430
+ * ```
431
+ */
432
+ upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions): Promise<T>;
433
+ /**
434
+ * Run pending migrations.
435
+ *
436
+ * @remarks
437
+ * Default implementation is a placeholder. Subclasses should implement
438
+ * migration tracking and execution logic.
439
+ *
440
+ * @param migrations - Array of migrations to run
441
+ * @returns Migration result with applied and pending migrations
442
+ *
443
+ * @throws {DatabaseError} If migration fails
444
+ */
445
+ migrate(_migrations: Migration[]): Promise<MigrationResult>;
446
+ /**
447
+ * Rollback the last migration.
448
+ *
449
+ * @remarks
450
+ * Default implementation is a placeholder. Subclasses should implement
451
+ * migration rollback logic.
452
+ *
453
+ * @returns Migration result after rollback
454
+ *
455
+ * @throws {DatabaseError} If rollback fails
456
+ */
457
+ rollback(): Promise<MigrationResult>;
458
+ /**
459
+ * Get migration status.
460
+ *
461
+ * @remarks
462
+ * Default implementation is a placeholder. Subclasses should implement
463
+ * migration status checking.
464
+ *
465
+ * @returns Current migration status
466
+ *
467
+ * @throws {DatabaseError} If status check fails
468
+ */
469
+ getMigrationStatus(): Promise<MigrationResult>;
470
+ /**
471
+ * Create a new table.
472
+ *
473
+ * @remarks
474
+ * Default implementation is a placeholder. Subclasses should implement
475
+ * table creation logic.
476
+ *
477
+ * @param definition - Table definition
478
+ * @param options - Creation options
479
+ *
480
+ * @throws {DatabaseError} If table creation fails
481
+ */
482
+ createTable(definition: TableDefinition, options?: CreateTableOptions): Promise<void>;
483
+ /**
484
+ * Drop a table.
485
+ *
486
+ * @remarks
487
+ * Default implementation is a placeholder. Subclasses should implement
488
+ * table dropping logic.
489
+ *
490
+ * @param tableName - Name of table to drop
491
+ * @param options - Drop options
492
+ *
493
+ * @throws {DatabaseError} If table drop fails
494
+ */
495
+ dropTable(tableName: string, options?: DropTableOptions): Promise<void>;
496
+ /**
497
+ * Alter an existing table.
498
+ *
499
+ * @remarks
500
+ * Default implementation is a placeholder. Subclasses should implement
501
+ * table alteration logic.
502
+ *
503
+ * @param tableName - Name of table to alter
504
+ * @param operations - Alteration operations
505
+ * @param options - Alter options
506
+ *
507
+ * @throws {DatabaseError} If table alteration fails
508
+ */
509
+ alterTable(tableName: string, operations: AlterTableOperation[], _options?: AlterTableOptions): Promise<void>;
510
+ /**
511
+ * Check if a table exists in the database.
512
+ *
513
+ * @remarks
514
+ * Uses dialect-specific information schema queries to check table existence.
515
+ * This is useful for development mode auto-sync to determine whether to
516
+ * CREATE or DROP/CREATE tables.
517
+ *
518
+ * @param tableName - Name of table to check
519
+ * @param schema - Optional schema name (defaults to 'public' for PostgreSQL)
520
+ * @returns True if table exists, false otherwise
521
+ *
522
+ * @throws {DatabaseError} If query fails
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * const exists = await adapter.tableExists('users');
527
+ * if (exists) {
528
+ * await adapter.dropTable('users');
529
+ * }
530
+ * await adapter.createTable(userTableDef);
531
+ * ```
532
+ */
533
+ tableExists(tableName: string, schema?: string): Promise<boolean>;
534
+ /**
535
+ * Get list of all tables in the database.
536
+ *
537
+ * @remarks
538
+ * Uses dialect-specific information schema queries to list tables.
539
+ * Useful for detecting orphaned tables or validating schema state.
540
+ *
541
+ * @param schema - Optional schema name (defaults to 'public' for PostgreSQL)
542
+ * @returns Array of table names
543
+ *
544
+ * @throws {DatabaseError} If query fails
545
+ */
546
+ listTables(schema?: string): Promise<string[]>;
547
+ /**
548
+ * Escape a table or column identifier.
549
+ *
550
+ * @remarks
551
+ * Default uses double quotes (SQL standard).
552
+ * MySQL adapter should override to use backticks.
553
+ *
554
+ * @param identifier - Identifier to escape
555
+ * @returns Escaped identifier
556
+ *
557
+ * @protected
558
+ */
559
+ protected escapeIdentifier(identifier: string): string;
560
+ /**
561
+ * Create a DatabaseError with proper error kind classification.
562
+ *
563
+ * @remarks
564
+ * Protected helper for subclasses to create consistent errors.
565
+ * Subclasses can override to add dialect-specific error classification.
566
+ *
567
+ * @param kind - Error kind
568
+ * @param message - Error message
569
+ * @param cause - Original error
570
+ * @returns DatabaseError instance
571
+ *
572
+ * @protected
573
+ */
574
+ protected createDatabaseError(kind: DatabaseErrorKind, message: string, cause?: Error): DatabaseError;
575
+ /**
576
+ * Handle query errors and convert to DatabaseError.
577
+ *
578
+ * @remarks
579
+ * Protected helper for consistent error handling across CRUD operations.
580
+ * Subclasses can override to add dialect-specific error classification.
581
+ *
582
+ * @param error - Original error
583
+ * @param operation - Operation that failed
584
+ * @param table - Table name
585
+ * @returns DatabaseError instance
586
+ *
587
+ * @protected
588
+ */
589
+ protected handleQueryError(error: unknown, operation: string, table: string): DatabaseError;
590
+ }
591
+
592
+ export { DrizzleAdapter as D };