@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
@@ -0,0 +1,622 @@
1
+ import { a as SqlParam, S as SupportedDialect } from './core-CVO7WYDj.cjs';
2
+
3
+ /**
4
+ * Query building type definitions for database-agnostic queries.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+
9
+ /**
10
+ * Supported WHERE clause operators.
11
+ *
12
+ * @remarks
13
+ * - Standard comparison: =, !=, <, >, <=, >=
14
+ * - Set operations: IN, NOT IN
15
+ * - Pattern matching: LIKE, ILIKE (case-insensitive, PostgreSQL/emulated)
16
+ * - NULL checks: IS NULL, IS NOT NULL
17
+ * - Range: BETWEEN, NOT BETWEEN
18
+ * - JSON/Array: CONTAINS, OVERLAPS
19
+ *
20
+ * @public
21
+ */
22
+ type WhereOperator = "=" | "!=" | "<" | ">" | "<=" | ">=" | "IN" | "NOT IN" | "LIKE" | "ILIKE" | "IS NULL" | "IS NOT NULL" | "BETWEEN" | "NOT BETWEEN" | "CONTAINS" | "OVERLAPS";
23
+ /**
24
+ * Individual WHERE condition.
25
+ *
26
+ * @remarks
27
+ * Represents a single condition in a WHERE clause. For IS NULL and IS NOT NULL
28
+ * operators, the value field is optional.
29
+ *
30
+ * @public
31
+ */
32
+ interface WhereCondition {
33
+ /** Column name to filter on */
34
+ column: string;
35
+ /** Comparison operator */
36
+ op: WhereOperator;
37
+ /** Value(s) to compare against (optional for IS NULL/IS NOT NULL) */
38
+ value?: SqlParam | SqlParam[];
39
+ /** Second value for BETWEEN operator */
40
+ valueTo?: SqlParam;
41
+ }
42
+ /**
43
+ * Complex WHERE clause with logical operators.
44
+ *
45
+ * @remarks
46
+ * Supports nested conditions with AND, OR, and NOT logical operators.
47
+ * Can be recursively nested for complex queries.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const where: WhereClause = {
52
+ * and: [
53
+ * { column: "status", op: "=", value: "published" },
54
+ * {
55
+ * or: [
56
+ * { column: "author", op: "=", value: "john" },
57
+ * { column: "author", op: "=", value: "jane" }
58
+ * ]
59
+ * }
60
+ * ]
61
+ * };
62
+ * ```
63
+ *
64
+ * @public
65
+ */
66
+ interface WhereClause {
67
+ /** All conditions must be true (AND) */
68
+ and?: (WhereCondition | WhereClause)[];
69
+ /** At least one condition must be true (OR) */
70
+ or?: (WhereCondition | WhereClause)[];
71
+ /** Negate a condition (NOT) */
72
+ not?: WhereCondition | WhereClause;
73
+ }
74
+ /**
75
+ * ORDER BY specification for query results.
76
+ *
77
+ * @remarks
78
+ * Controls the sorting of query results. NULL handling varies by database
79
+ * but can be explicitly controlled with the nulls field.
80
+ *
81
+ * @public
82
+ */
83
+ interface OrderBySpec {
84
+ /** Column name to sort by */
85
+ column: string;
86
+ /** Sort direction (default: asc) */
87
+ direction?: "asc" | "desc";
88
+ /** NULL value ordering (database-specific defaults vary) */
89
+ nulls?: "first" | "last";
90
+ }
91
+ /**
92
+ * JOIN specification for table joins.
93
+ *
94
+ * @remarks
95
+ * Supports different types of JOINs. Note that complex joins may require
96
+ * dialect-specific handling.
97
+ *
98
+ * @public
99
+ */
100
+ interface JoinSpec {
101
+ /** Type of join */
102
+ type: "inner" | "left" | "right" | "full";
103
+ /** Table name to join */
104
+ table: string;
105
+ /** Join condition */
106
+ on: {
107
+ /** Column from the left table */
108
+ leftColumn: string;
109
+ /** Column from the right table */
110
+ rightColumn: string;
111
+ };
112
+ /** Optional alias for the joined table */
113
+ alias?: string;
114
+ }
115
+
116
+ /**
117
+ * CRUD operation type definitions.
118
+ *
119
+ * @packageDocumentation
120
+ */
121
+
122
+ /**
123
+ * Options for SELECT queries.
124
+ *
125
+ * @remarks
126
+ * Provides a database-agnostic way to build SELECT queries with filtering,
127
+ * sorting, pagination, and joins.
128
+ *
129
+ * @public
130
+ */
131
+ interface SelectOptions {
132
+ /** Specific columns to select (default: all columns) */
133
+ columns?: string[];
134
+ /** Filter conditions */
135
+ where?: WhereClause;
136
+ /** Sort order */
137
+ orderBy?: OrderBySpec[];
138
+ /** Maximum number of rows to return */
139
+ limit?: number;
140
+ /** Number of rows to skip */
141
+ offset?: number;
142
+ /** Table joins */
143
+ joins?: JoinSpec[];
144
+ /** GROUP BY columns */
145
+ groupBy?: string[];
146
+ /** HAVING clause (for aggregated results) */
147
+ having?: WhereClause;
148
+ /** Return distinct rows only */
149
+ distinct?: boolean;
150
+ }
151
+ /**
152
+ * Options for INSERT operations.
153
+ *
154
+ * @remarks
155
+ * Controls the behavior of INSERT operations including conflict handling
156
+ * and returning inserted data.
157
+ *
158
+ * @public
159
+ */
160
+ interface InsertOptions {
161
+ /** Columns to return after insert (use "*" for all columns) */
162
+ returning?: string[] | "*";
163
+ /** Handle conflicts (unique constraint violations) */
164
+ onConflict?: {
165
+ /** Columns that define the conflict (unique constraint) */
166
+ columns: string[];
167
+ /** Action to take on conflict */
168
+ action: "ignore" | "update";
169
+ /** Columns to update on conflict (required if action is "update") */
170
+ updateColumns?: string[];
171
+ };
172
+ }
173
+ /**
174
+ * Options for UPDATE operations.
175
+ *
176
+ * @remarks
177
+ * Controls what data is returned after an update operation.
178
+ *
179
+ * @public
180
+ */
181
+ interface UpdateOptions {
182
+ /** Columns to return after update (use "*" for all columns) */
183
+ returning?: string[] | "*";
184
+ }
185
+ /**
186
+ * Options for DELETE operations.
187
+ *
188
+ * @remarks
189
+ * Controls what data is returned after a delete operation.
190
+ *
191
+ * @public
192
+ */
193
+ interface DeleteOptions {
194
+ /** Columns to return after delete (use "*" for all columns) */
195
+ returning?: string[] | "*";
196
+ }
197
+ /**
198
+ * Options for UPSERT operations (INSERT or UPDATE).
199
+ *
200
+ * @remarks
201
+ * Combines INSERT and UPDATE behavior. If a row with the specified
202
+ * conflict columns exists, it will be updated; otherwise, a new row
203
+ * will be inserted.
204
+ *
205
+ * @public
206
+ */
207
+ interface UpsertOptions {
208
+ /** Columns that define uniqueness for conflict detection */
209
+ conflictColumns: string[];
210
+ /** Columns to update if conflict occurs (default: all provided columns) */
211
+ updateColumns?: string[];
212
+ /** Columns to return after upsert (use "*" for all columns) */
213
+ returning?: string[] | "*";
214
+ }
215
+
216
+ /**
217
+ * Transaction type definitions for database operations.
218
+ *
219
+ * @packageDocumentation
220
+ */
221
+
222
+ /**
223
+ * Transaction isolation levels.
224
+ *
225
+ * @remarks
226
+ * Controls the visibility of changes between concurrent transactions.
227
+ * Not all levels are supported by all databases:
228
+ * - PostgreSQL: All levels supported
229
+ * - MySQL: All levels supported
230
+ * - SQLite: Serializable only (default)
231
+ *
232
+ * @public
233
+ */
234
+ type TransactionIsolationLevel = "read uncommitted" | "read committed" | "repeatable read" | "serializable";
235
+ /**
236
+ * Options for transaction execution.
237
+ *
238
+ * @remarks
239
+ * Configures transaction behavior including isolation level, read-only mode,
240
+ * timeouts, and retry logic.
241
+ *
242
+ * @public
243
+ */
244
+ interface TransactionOptions {
245
+ /** Transaction isolation level */
246
+ isolationLevel?: TransactionIsolationLevel;
247
+ /** Read-only transaction (optimization hint) */
248
+ readOnly?: boolean;
249
+ /** Per-transaction statement timeout in milliseconds */
250
+ timeoutMs?: number;
251
+ /** Number of retry attempts on serialization failures (default: 0) */
252
+ retryCount?: number;
253
+ /** Delay between retry attempts in milliseconds (default: 100) */
254
+ retryDelayMs?: number;
255
+ }
256
+ /**
257
+ * Transaction context for executing operations within a transaction.
258
+ *
259
+ * @remarks
260
+ * All operations executed through this context are part of the same
261
+ * database transaction. The transaction is automatically committed on
262
+ * success or rolled back on error.
263
+ *
264
+ * Savepoint methods are optional and only available on databases that
265
+ * support them (PostgreSQL, SQLite).
266
+ *
267
+ * @public
268
+ */
269
+ interface TransactionContext {
270
+ /**
271
+ * Execute raw SQL within the transaction.
272
+ *
273
+ * @param sql - SQL statement to execute
274
+ * @param params - Optional parameters for the statement
275
+ * @returns Array of result rows
276
+ */
277
+ execute<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
278
+ /**
279
+ * Insert a single record.
280
+ *
281
+ * @param table - Table name
282
+ * @param data - Record data to insert
283
+ * @param options - Insert options
284
+ * @returns Inserted record (with RETURNING columns if specified)
285
+ */
286
+ insert<T = unknown>(table: string, data: Record<string, unknown>, options?: InsertOptions): Promise<T>;
287
+ /**
288
+ * Insert multiple records.
289
+ *
290
+ * @param table - Table name
291
+ * @param data - Array of records to insert
292
+ * @param options - Insert options
293
+ * @returns Inserted records (with RETURNING columns if specified)
294
+ */
295
+ insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions): Promise<T[]>;
296
+ /**
297
+ * Select multiple records.
298
+ *
299
+ * @param table - Table name
300
+ * @param options - Select options (filtering, sorting, etc.)
301
+ * @returns Array of matching records
302
+ */
303
+ select<T = unknown>(table: string, options?: SelectOptions): Promise<T[]>;
304
+ /**
305
+ * Select a single record.
306
+ *
307
+ * @param table - Table name
308
+ * @param options - Select options (filtering, sorting, etc.)
309
+ * @returns First matching record or null
310
+ */
311
+ selectOne<T = unknown>(table: string, options?: SelectOptions): Promise<T | null>;
312
+ /**
313
+ * Update records.
314
+ *
315
+ * @param table - Table name
316
+ * @param data - Data to update
317
+ * @param where - Conditions for records to update
318
+ * @param options - Update options
319
+ * @returns Updated records (with RETURNING columns if specified)
320
+ */
321
+ update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions): Promise<T[]>;
322
+ /**
323
+ * Delete records.
324
+ *
325
+ * @param table - Table name
326
+ * @param where - Conditions for records to delete
327
+ * @param options - Delete options
328
+ * @returns Number of deleted records
329
+ */
330
+ delete(table: string, where: WhereClause, options?: DeleteOptions): Promise<number>;
331
+ /**
332
+ * Upsert a record (INSERT or UPDATE).
333
+ *
334
+ * @param table - Table name
335
+ * @param data - Record data
336
+ * @param options - Upsert options (must specify conflict columns)
337
+ * @returns Upserted record (with RETURNING columns if specified)
338
+ */
339
+ upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions): Promise<T>;
340
+ /**
341
+ * Create a savepoint (PostgreSQL, SQLite only).
342
+ *
343
+ * @remarks
344
+ * Savepoints allow partial rollback within a transaction.
345
+ * Not supported on MySQL.
346
+ *
347
+ * @param name - Savepoint name
348
+ */
349
+ savepoint?(name: string): Promise<void>;
350
+ /**
351
+ * Rollback to a savepoint (PostgreSQL, SQLite only).
352
+ *
353
+ * @remarks
354
+ * Discards all changes made after the savepoint was created.
355
+ *
356
+ * @param name - Savepoint name
357
+ */
358
+ rollbackToSavepoint?(name: string): Promise<void>;
359
+ /**
360
+ * Release a savepoint (PostgreSQL, SQLite only).
361
+ *
362
+ * @remarks
363
+ * Commits the savepoint, making its changes permanent within the transaction.
364
+ *
365
+ * @param name - Savepoint name
366
+ */
367
+ releaseSavepoint?(name: string): Promise<void>;
368
+ }
369
+
370
+ /**
371
+ * Database capability type definitions.
372
+ *
373
+ * @packageDocumentation
374
+ */
375
+
376
+ /**
377
+ * Database feature capabilities.
378
+ *
379
+ * @remarks
380
+ * Describes what features are supported by a specific database adapter.
381
+ * Services can check these capabilities to conditionally enable features
382
+ * or implement fallback behavior.
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const capabilities = adapter.getCapabilities();
387
+ * if (capabilities.supportsJsonb) {
388
+ * // Use JSONB-specific features
389
+ * } else if (capabilities.supportsJson) {
390
+ * // Fallback to JSON
391
+ * }
392
+ * ```
393
+ *
394
+ * @public
395
+ */
396
+ interface DatabaseCapabilities {
397
+ /** Database dialect */
398
+ dialect: SupportedDialect;
399
+ /**
400
+ * Native JSONB support (PostgreSQL only).
401
+ *
402
+ * @remarks
403
+ * JSONB provides better performance and indexing than JSON.
404
+ * Other databases will use JSON or emulated JSON.
405
+ */
406
+ supportsJsonb: boolean;
407
+ /**
408
+ * JSON column type support.
409
+ *
410
+ * @remarks
411
+ * All supported databases have some form of JSON support:
412
+ * - PostgreSQL: Native JSON and JSONB
413
+ * - MySQL: Native JSON column type
414
+ * - SQLite: JSON functions (json_extract, json_array, etc.)
415
+ */
416
+ supportsJson: boolean;
417
+ /**
418
+ * Array column type support (PostgreSQL only).
419
+ *
420
+ * @remarks
421
+ * PostgreSQL has native array types. Other databases must use
422
+ * JSON arrays or separate tables.
423
+ */
424
+ supportsArrays: boolean;
425
+ /**
426
+ * Generated/computed columns support.
427
+ *
428
+ * @remarks
429
+ * Support for columns whose values are automatically computed from
430
+ * other columns:
431
+ * - PostgreSQL: GENERATED ALWAYS AS ... STORED
432
+ * - MySQL: Generated columns
433
+ * - SQLite: Generated columns (3.31.0+)
434
+ */
435
+ supportsGeneratedColumns: boolean;
436
+ /**
437
+ * Full-text search support.
438
+ *
439
+ * @remarks
440
+ * Native full-text search capabilities:
441
+ * - PostgreSQL: tsvector/tsquery
442
+ * - MySQL: FULLTEXT indexes (limited)
443
+ * - SQLite: FTS5 extension (not enabled by default)
444
+ */
445
+ supportsFts: boolean;
446
+ /**
447
+ * Case-insensitive ILIKE operator support (PostgreSQL only).
448
+ *
449
+ * @remarks
450
+ * Other databases must emulate with LOWER(column) LIKE LOWER(value).
451
+ */
452
+ supportsIlike: boolean;
453
+ /**
454
+ * RETURNING clause support.
455
+ *
456
+ * @remarks
457
+ * Support for returning data from INSERT/UPDATE/DELETE:
458
+ * - PostgreSQL: Yes
459
+ * - MySQL: No (requires separate SELECT)
460
+ * - SQLite: Yes
461
+ */
462
+ supportsReturning: boolean;
463
+ /**
464
+ * Savepoint support for nested transactions.
465
+ *
466
+ * @remarks
467
+ * - PostgreSQL: Yes
468
+ * - MySQL: No (limited support, not recommended)
469
+ * - SQLite: Yes
470
+ */
471
+ supportsSavepoints: boolean;
472
+ /**
473
+ * ON CONFLICT clause support for upserts.
474
+ *
475
+ * @remarks
476
+ * - PostgreSQL: ON CONFLICT DO NOTHING/UPDATE
477
+ * - MySQL: ON DUPLICATE KEY UPDATE (different syntax)
478
+ * - SQLite: ON CONFLICT (similar to PostgreSQL)
479
+ */
480
+ supportsOnConflict: boolean;
481
+ /**
482
+ * Maximum number of parameters per query.
483
+ *
484
+ * @remarks
485
+ * Database-specific limits:
486
+ * - PostgreSQL: 65,535
487
+ * - MySQL: 65,535
488
+ * - SQLite: 999 (can be increased with SQLITE_MAX_VARIABLE_NUMBER)
489
+ */
490
+ maxParamsPerQuery: number;
491
+ /**
492
+ * Maximum length for table/column identifiers.
493
+ *
494
+ * @remarks
495
+ * - PostgreSQL: 63 bytes
496
+ * - MySQL: 64 characters
497
+ * - SQLite: No limit (practically unlimited)
498
+ */
499
+ maxIdentifierLength: number;
500
+ }
501
+ /**
502
+ * Connection pool statistics.
503
+ *
504
+ * @remarks
505
+ * Provides visibility into connection pool health. Not all adapters
506
+ * provide pool statistics (e.g., SQLite is single-connection).
507
+ *
508
+ * @public
509
+ */
510
+ interface PoolStats {
511
+ /** Total number of connections in the pool */
512
+ total: number;
513
+ /** Number of idle (available) connections */
514
+ idle: number;
515
+ /** Number of clients waiting for a connection */
516
+ waiting: number;
517
+ /** Number of connections currently in use */
518
+ active: number;
519
+ }
520
+
521
+ /**
522
+ * Database migration type definitions.
523
+ *
524
+ * @packageDocumentation
525
+ */
526
+
527
+ /**
528
+ * Migration definition.
529
+ *
530
+ * @remarks
531
+ * Represents a single database migration with up and optional down functions.
532
+ * Migrations can be defined as raw SQL strings or as functions that use the
533
+ * transaction context for more complex operations.
534
+ *
535
+ * @public
536
+ */
537
+ interface Migration {
538
+ /** Unique migration identifier (e.g., "20250104_001_create_users") */
539
+ id: string;
540
+ /** Human-readable migration name */
541
+ name: string;
542
+ /** Unix timestamp when migration was created */
543
+ timestamp: number;
544
+ /** Forward migration (apply changes) */
545
+ up: string | ((tx: TransactionContext) => Promise<void>);
546
+ /** Reverse migration (undo changes) - optional */
547
+ down?: string | ((tx: TransactionContext) => Promise<void>);
548
+ }
549
+ /**
550
+ * Migration record stored in the database.
551
+ *
552
+ * @remarks
553
+ * Tracks which migrations have been applied to the database.
554
+ * The migrations table is automatically created by the adapter.
555
+ *
556
+ * @public
557
+ */
558
+ interface MigrationRecord {
559
+ /** Migration identifier */
560
+ id: string;
561
+ /** Migration name */
562
+ name: string;
563
+ /** When the migration was applied */
564
+ appliedAt: Date;
565
+ /** Optional checksum to detect migration changes */
566
+ checksum?: string;
567
+ }
568
+ /**
569
+ * Migration execution result.
570
+ *
571
+ * @remarks
572
+ * Provides information about migration status including applied and
573
+ * pending migrations.
574
+ *
575
+ * @public
576
+ */
577
+ interface MigrationResult {
578
+ /** Migrations that were applied in this execution */
579
+ applied: MigrationRecord[];
580
+ /** Migrations that are pending (not yet applied) */
581
+ pending: Migration[];
582
+ /** ID of the current (most recent) migration, or null if none applied */
583
+ current: string | null;
584
+ }
585
+ /**
586
+ * Options for migration execution.
587
+ *
588
+ * @public
589
+ */
590
+ interface MigrationOptions {
591
+ /** Target migration to migrate to (default: latest) */
592
+ target?: string;
593
+ /** Dry run mode - don't actually apply migrations */
594
+ dryRun?: boolean;
595
+ /** Run migrations in a single transaction (default: true) */
596
+ useTransaction?: boolean;
597
+ /**
598
+ * Strict checksum validation (default: true).
599
+ * If true, modified migrations will cause an error.
600
+ * If false, modified migrations will generate a warning.
601
+ */
602
+ strictChecksums?: boolean;
603
+ }
604
+ /**
605
+ * Migration status information.
606
+ *
607
+ * @public
608
+ */
609
+ interface MigrationStatus {
610
+ /** Current migration ID (most recently applied) */
611
+ current: string | null;
612
+ /** Total number of applied migrations */
613
+ appliedCount: number;
614
+ /** Total number of pending migrations */
615
+ pendingCount: number;
616
+ /** Applied migration records */
617
+ applied: MigrationRecord[];
618
+ /** Pending migrations */
619
+ pending: Migration[];
620
+ }
621
+
622
+ export type { DatabaseCapabilities as D, InsertOptions as I, JoinSpec as J, MigrationRecord as M, OrderBySpec as O, PoolStats as P, SelectOptions as S, TransactionContext as T, UpdateOptions as U, WhereClause as W, Migration as a, MigrationStatus as b, MigrationOptions as c, MigrationResult as d, TransactionOptions as e, DeleteOptions as f, UpsertOptions as g, TransactionIsolationLevel as h, WhereCondition as i, WhereOperator as j };