@nextlyhq/adapter-drizzle 0.0.2-alpha.7 → 0.0.2-alpha.70
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.
- package/README.md +25 -1
- package/dist/adapter-BypoOEEN.d.cts +1166 -0
- package/dist/adapter-CSP-Ek-L.d.ts +1166 -0
- package/dist/index-BYb6cDli.d.ts +1168 -0
- package/dist/index-C4HJsfwA.d.cts +1168 -0
- package/dist/index.cjs +2302 -1085
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -9
- package/dist/index.d.ts +5 -9
- package/dist/index.mjs +2301 -1083
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.cjs +345 -146
- package/dist/migrations.cjs.map +1 -1
- package/dist/migrations.d.cts +93 -109
- package/dist/migrations.d.ts +93 -109
- package/dist/migrations.mjs +344 -144
- package/dist/migrations.mjs.map +1 -1
- package/dist/schema/index.cjs +21 -6
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +5 -116
- package/dist/schema/index.d.ts +5 -116
- package/dist/schema/index.mjs +20 -4
- package/dist/schema/index.mjs.map +1 -1
- package/dist/schema-Bkkr3JMC.d.cts +264 -0
- package/dist/schema-Bkkr3JMC.d.ts +264 -0
- package/dist/schema-name.cjs +42 -0
- package/dist/schema-name.cjs.map +1 -0
- package/dist/schema-name.d.cts +12 -0
- package/dist/schema-name.d.ts +12 -0
- package/dist/schema-name.mjs +40 -0
- package/dist/schema-name.mjs.map +1 -0
- package/dist/text-match.cjs +50 -0
- package/dist/text-match.cjs.map +1 -0
- package/dist/text-match.d.cts +32 -0
- package/dist/text-match.d.ts +32 -0
- package/dist/text-match.mjs +48 -0
- package/dist/text-match.mjs.map +1 -0
- package/dist/types/index.cjs +8 -24
- package/dist/types/index.d.cts +3 -210
- package/dist/types/index.d.ts +3 -210
- package/dist/types/index.mjs +1 -21
- package/dist/types-CNyA1oIm.cjs +185 -0
- package/dist/types-CNyA1oIm.cjs.map +1 -0
- package/dist/types-CaF_5jNk.mjs +150 -0
- package/dist/types-CaF_5jNk.mjs.map +1 -0
- package/dist/version-check.cjs +119 -127
- package/dist/version-check.cjs.map +1 -1
- package/dist/version-check.d.cts +54 -39
- package/dist/version-check.d.ts +54 -39
- package/dist/version-check.mjs +117 -125
- package/dist/version-check.mjs.map +1 -1
- package/package.json +23 -17
- package/dist/adapter-BxJVtttb.d.ts +0 -592
- package/dist/adapter-nvlxFkF-.d.cts +0 -592
- package/dist/core-CVO7WYDj.d.cts +0 -74
- package/dist/core-CVO7WYDj.d.ts +0 -74
- package/dist/error-um1d_3Uo.d.cts +0 -105
- package/dist/error-um1d_3Uo.d.ts +0 -105
- package/dist/migration-BbO5meEV.d.cts +0 -622
- package/dist/migration-Qe70wDOC.d.ts +0 -622
- package/dist/schema-BDn8WfSL.d.cts +0 -200
- package/dist/schema-BIQ0YQZ_.d.ts +0 -200
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.mjs.map +0 -1
|
@@ -0,0 +1,1168 @@
|
|
|
1
|
+
import { f as SqlParam, p as SupportedDialect } from "./schema-Bkkr3JMC.js";
|
|
2
|
+
import { AnyRelations, SQL } from "drizzle-orm";
|
|
3
|
+
/**
|
|
4
|
+
* Every WHERE clause operator this package DECLARES, as a value.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Declared, not guaranteed executable. Membership here means a `WhereCondition`
|
|
8
|
+
* carrying the operator type-checks — it does NOT mean the adapter can run it.
|
|
9
|
+
* `OVERLAPS` is declared and unimplemented, and throws at build time, so a
|
|
10
|
+
* validator written against this list will admit input the query layer then
|
|
11
|
+
* rejects. Validate against it to catch a misspelled operator; do not read
|
|
12
|
+
* acceptance here as a capability.
|
|
13
|
+
*
|
|
14
|
+
* - Standard comparison: =, !=, <, >, <=, >=
|
|
15
|
+
* - Set operations: IN, NOT IN
|
|
16
|
+
* - Pattern matching: LIKE, ILIKE (case-insensitive, PostgreSQL/emulated)
|
|
17
|
+
* - NULL checks: IS NULL, IS NOT NULL
|
|
18
|
+
* - Range: BETWEEN, NOT BETWEEN
|
|
19
|
+
* - Substring: CONTAINS — a LITERAL match on a TEXT column; see below
|
|
20
|
+
* - Declared but NOT implemented: OVERLAPS, which throws
|
|
21
|
+
*
|
|
22
|
+
* This list is the source of truth and {@link WhereOperator} is derived from it,
|
|
23
|
+
* rather than the two being written out separately. A guard that has to enumerate
|
|
24
|
+
* the operators — a validator over caller input, or a test asserting the builder
|
|
25
|
+
* handles or refuses each one — can only do that from a runtime value, and a
|
|
26
|
+
* hand-kept copy of the union would agree with it on the day it was written and
|
|
27
|
+
* silently stop agreeing the next time a member is added.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
declare const WHERE_OPERATORS: readonly ["=", "!=", "<", ">", "<=", ">=", "IN", "NOT IN", "LIKE", "ILIKE", "IS NULL", "IS NOT NULL", "BETWEEN", "NOT BETWEEN", "CONTAINS", "ICONTAINS", "OVERLAPS"];
|
|
32
|
+
/**
|
|
33
|
+
* Every WHERE clause operator this package declares. Derived from
|
|
34
|
+
* {@link WHERE_OPERATORS}, and carrying the same caveat: a value of this type
|
|
35
|
+
* type-checks, which is not the same as the adapter being able to execute it.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
type WhereOperator = (typeof WHERE_OPERATORS)[number];
|
|
40
|
+
/**
|
|
41
|
+
* Individual WHERE condition.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* Represents a single condition in a WHERE clause. For IS NULL and IS NOT NULL
|
|
45
|
+
* operators, the value field is optional.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
interface WhereCondition {
|
|
50
|
+
/** Column name to filter on */
|
|
51
|
+
column: string;
|
|
52
|
+
/** Comparison operator */
|
|
53
|
+
op: WhereOperator;
|
|
54
|
+
/** Value(s) to compare against (optional for IS NULL/IS NOT NULL) */
|
|
55
|
+
value?: SqlParam | SqlParam[];
|
|
56
|
+
/** Second value for BETWEEN operator */
|
|
57
|
+
valueTo?: SqlParam;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Complex WHERE clause with logical operators.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Supports nested conditions with AND, OR, and NOT logical operators.
|
|
64
|
+
* Can be recursively nested for complex queries.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const where: WhereClause = {
|
|
69
|
+
* and: [
|
|
70
|
+
* { column: "status", op: "=", value: "published" },
|
|
71
|
+
* {
|
|
72
|
+
* or: [
|
|
73
|
+
* { column: "author", op: "=", value: "john" },
|
|
74
|
+
* { column: "author", op: "=", value: "jane" }
|
|
75
|
+
* ]
|
|
76
|
+
* }
|
|
77
|
+
* ]
|
|
78
|
+
* };
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
interface WhereClause {
|
|
84
|
+
/** All conditions must be true (AND) */
|
|
85
|
+
and?: (WhereCondition | WhereClause)[];
|
|
86
|
+
/** At least one condition must be true (OR) */
|
|
87
|
+
or?: (WhereCondition | WhereClause)[];
|
|
88
|
+
/** Negate a condition (NOT) */
|
|
89
|
+
not?: WhereCondition | WhereClause;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* ORDER BY specification for query results.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* Controls the sorting of query results. NULL handling varies by database
|
|
96
|
+
* but can be explicitly controlled with the nulls field.
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
interface OrderBySpec {
|
|
101
|
+
/** Column name to sort by */
|
|
102
|
+
column: string;
|
|
103
|
+
/** Sort direction (default: asc) */
|
|
104
|
+
direction?: "asc" | "desc";
|
|
105
|
+
/** NULL value ordering (database-specific defaults vary) */
|
|
106
|
+
nulls?: "first" | "last";
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* JOIN specification for table joins.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* Supports different types of JOINs. Note that complex joins may require
|
|
113
|
+
* dialect-specific handling.
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
interface JoinSpec {
|
|
118
|
+
/** Type of join */
|
|
119
|
+
type: "inner" | "left" | "right" | "full";
|
|
120
|
+
/** Table name to join */
|
|
121
|
+
table: string;
|
|
122
|
+
/** Join condition */
|
|
123
|
+
on: {
|
|
124
|
+
/** Column from the left table */
|
|
125
|
+
leftColumn: string;
|
|
126
|
+
/** Column from the right table */
|
|
127
|
+
rightColumn: string;
|
|
128
|
+
};
|
|
129
|
+
/** Optional alias for the joined table */
|
|
130
|
+
alias?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Options for SELECT queries.
|
|
134
|
+
*
|
|
135
|
+
* @remarks
|
|
136
|
+
* Provides a database-agnostic way to build SELECT queries with filtering,
|
|
137
|
+
* sorting, pagination, and joins.
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
/**
|
|
142
|
+
* What a COUNT asks for.
|
|
143
|
+
*
|
|
144
|
+
* 🔴 `distinctOn` is a column LIST rather than a boolean, and the difference is
|
|
145
|
+
* the whole reason this option exists: counting rows and counting the things
|
|
146
|
+
* those rows are about are different questions whenever a thing can own more
|
|
147
|
+
* than one row. A document holding a pending edit in three languages is one
|
|
148
|
+
* document and three version rows.
|
|
149
|
+
*/
|
|
150
|
+
interface CountOptions {
|
|
151
|
+
/** Filter conditions, the same vocabulary `select` takes. */
|
|
152
|
+
where?: WhereClause;
|
|
153
|
+
/**
|
|
154
|
+
* Count DISTINCT combinations of these columns instead of rows.
|
|
155
|
+
*
|
|
156
|
+
* Compiled as `COUNT(*)` over a `SELECT DISTINCT` subquery rather than as
|
|
157
|
+
* `COUNT(DISTINCT a, b)`, because the latter is not portable: MySQL accepts
|
|
158
|
+
* it, PostgreSQL requires a row constructor, and SQLite rejects it outright
|
|
159
|
+
* with "wrong number of arguments to function count()". The subquery is the
|
|
160
|
+
* one form all three engines agree on, and it is what this compiles to on
|
|
161
|
+
* every dialect so the number cannot differ by engine.
|
|
162
|
+
*/
|
|
163
|
+
distinctOn?: string[];
|
|
164
|
+
}
|
|
165
|
+
interface SelectOptions {
|
|
166
|
+
/** Specific columns to select (default: all columns) */
|
|
167
|
+
columns?: string[];
|
|
168
|
+
/** Filter conditions */
|
|
169
|
+
where?: WhereClause;
|
|
170
|
+
/** Sort order */
|
|
171
|
+
orderBy?: OrderBySpec[];
|
|
172
|
+
/** Maximum number of rows to return */
|
|
173
|
+
limit?: number;
|
|
174
|
+
/** Number of rows to skip */
|
|
175
|
+
offset?: number;
|
|
176
|
+
/** Table joins */
|
|
177
|
+
joins?: JoinSpec[];
|
|
178
|
+
/** GROUP BY columns */
|
|
179
|
+
groupBy?: string[];
|
|
180
|
+
/** HAVING clause (for aggregated results) */
|
|
181
|
+
having?: WhereClause;
|
|
182
|
+
/** Return distinct rows only */
|
|
183
|
+
distinct?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Take a `FOR UPDATE` row lock on the selected rows for the rest of the
|
|
186
|
+
* transaction, and read the latest committed values rather than the
|
|
187
|
+
* transaction's snapshot. Use for read-modify-write sequences that must not
|
|
188
|
+
* interleave (e.g. re-reading a status under the lock the write will take).
|
|
189
|
+
*
|
|
190
|
+
* Requires a transaction executor. No-ops on SQLite, which has no `FOR UPDATE`
|
|
191
|
+
* and needs none — its transactions open with `BEGIN IMMEDIATE`, already
|
|
192
|
+
* serializing writers.
|
|
193
|
+
*/
|
|
194
|
+
forUpdate?: boolean;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Options for INSERT operations.
|
|
198
|
+
*
|
|
199
|
+
* @remarks
|
|
200
|
+
* Controls the behavior of INSERT operations including conflict handling
|
|
201
|
+
* and returning inserted data.
|
|
202
|
+
*
|
|
203
|
+
* @public
|
|
204
|
+
*/
|
|
205
|
+
interface InsertOptions {
|
|
206
|
+
/** Columns to return after insert (use "*" for all columns) */
|
|
207
|
+
returning?: string[] | "*";
|
|
208
|
+
/** Handle conflicts (unique constraint violations) */
|
|
209
|
+
onConflict?: {
|
|
210
|
+
/** Columns that define the conflict (unique constraint) */
|
|
211
|
+
columns: string[];
|
|
212
|
+
/** Action to take on conflict */
|
|
213
|
+
action: "ignore" | "update";
|
|
214
|
+
/** Columns to update on conflict (required if action is "update") */
|
|
215
|
+
updateColumns?: string[];
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Options for UPDATE operations.
|
|
220
|
+
*
|
|
221
|
+
* @remarks
|
|
222
|
+
* Controls what data is returned after an update operation.
|
|
223
|
+
*
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
interface UpdateOptions {
|
|
227
|
+
/** Columns to return after update (use "*" for all columns) */
|
|
228
|
+
returning?: string[] | "*";
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Options for DELETE operations.
|
|
232
|
+
*
|
|
233
|
+
* @remarks
|
|
234
|
+
* Controls what data is returned after a delete operation.
|
|
235
|
+
*
|
|
236
|
+
* @public
|
|
237
|
+
*/
|
|
238
|
+
interface DeleteOptions {
|
|
239
|
+
/** Columns to return after delete (use "*" for all columns) */
|
|
240
|
+
returning?: string[] | "*";
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Options for UPSERT operations (INSERT or UPDATE).
|
|
244
|
+
*
|
|
245
|
+
* @remarks
|
|
246
|
+
* Combines INSERT and UPDATE behavior. If a row with the specified
|
|
247
|
+
* conflict columns exists, it will be updated; otherwise, a new row
|
|
248
|
+
* will be inserted.
|
|
249
|
+
*
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
interface UpsertOptions {
|
|
253
|
+
/** Columns that define uniqueness for conflict detection */
|
|
254
|
+
conflictColumns: string[];
|
|
255
|
+
/**
|
|
256
|
+
* Columns to update if conflict occurs (default: all provided columns).
|
|
257
|
+
*
|
|
258
|
+
* Empty means "insert, or keep the row that stands". The kept row is read
|
|
259
|
+
* back after the statement, so on PostgreSQL and SQLite a row another
|
|
260
|
+
* writer deletes between the two cannot be returned, and the call resolves
|
|
261
|
+
* to `null`. Whether THIS call created the row is told by the id it
|
|
262
|
+
* returns: send a fresh id, and only a call whose own insert ran gets it
|
|
263
|
+
* back — a read-back can only return another writer's row.
|
|
264
|
+
*/
|
|
265
|
+
updateColumns?: string[];
|
|
266
|
+
/** Columns to return after upsert (use "*" for all columns) */
|
|
267
|
+
returning?: string[] | "*";
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Transaction isolation levels.
|
|
271
|
+
*
|
|
272
|
+
* @remarks
|
|
273
|
+
* Controls the visibility of changes between concurrent transactions.
|
|
274
|
+
* Not all levels are supported by all databases:
|
|
275
|
+
* - PostgreSQL: All levels supported
|
|
276
|
+
* - MySQL: All levels supported
|
|
277
|
+
* - SQLite: Serializable only (default)
|
|
278
|
+
*
|
|
279
|
+
* @public
|
|
280
|
+
*/
|
|
281
|
+
type TransactionIsolationLevel = "read uncommitted" | "read committed" | "repeatable read" | "serializable";
|
|
282
|
+
/**
|
|
283
|
+
* Options for transaction execution.
|
|
284
|
+
*
|
|
285
|
+
* @remarks
|
|
286
|
+
* Configures transaction behavior including isolation level, read-only mode,
|
|
287
|
+
* timeouts, and retry logic.
|
|
288
|
+
*
|
|
289
|
+
* @public
|
|
290
|
+
*/
|
|
291
|
+
interface TransactionOptions {
|
|
292
|
+
/** Transaction isolation level */
|
|
293
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
294
|
+
/** Read-only transaction (optimization hint) */
|
|
295
|
+
readOnly?: boolean;
|
|
296
|
+
/** Per-transaction statement timeout in milliseconds */
|
|
297
|
+
timeoutMs?: number;
|
|
298
|
+
/** Number of retry attempts on serialization failures (default: 0) */
|
|
299
|
+
retryCount?: number;
|
|
300
|
+
/** Delay between retry attempts in milliseconds (default: 100) */
|
|
301
|
+
retryDelayMs?: number;
|
|
302
|
+
/**
|
|
303
|
+
* MySQL only: run the transaction in strict mode, so a statement that would
|
|
304
|
+
* cut a string to its column's length or clamp a number to its range fails
|
|
305
|
+
* rather than applying with a warning. The session's own mode is restored
|
|
306
|
+
* before the connection returns to the pool. PostgreSQL and SQLite ignore
|
|
307
|
+
* it: PostgreSQL refuses such values already, and SQLite enforces no
|
|
308
|
+
* declared length.
|
|
309
|
+
*/
|
|
310
|
+
strictSqlMode?: boolean;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Transaction context for executing operations within a transaction.
|
|
314
|
+
*
|
|
315
|
+
* @remarks
|
|
316
|
+
* All operations executed through this context are part of the same
|
|
317
|
+
* database transaction. The transaction is automatically committed on
|
|
318
|
+
* success or rolled back on error.
|
|
319
|
+
*
|
|
320
|
+
* Savepoint methods are optional and only available on databases that
|
|
321
|
+
* support them (PostgreSQL, SQLite).
|
|
322
|
+
*
|
|
323
|
+
* @public
|
|
324
|
+
*/
|
|
325
|
+
interface TransactionContext {
|
|
326
|
+
/**
|
|
327
|
+
* Execute raw SQL within the transaction.
|
|
328
|
+
*
|
|
329
|
+
* @param sql - SQL statement to execute
|
|
330
|
+
* @param params - Optional parameters for the statement
|
|
331
|
+
* @returns Array of result rows
|
|
332
|
+
*/
|
|
333
|
+
execute<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
|
|
334
|
+
/**
|
|
335
|
+
* An instance bound to the SAME transaction client with the relational
|
|
336
|
+
* query API (`db.query.*`) enabled — the transaction's counterpart of
|
|
337
|
+
* `getDrizzle(relations)`.
|
|
338
|
+
*
|
|
339
|
+
* The `getDrizzle()` instance has an empty `query` namespace, so a
|
|
340
|
+
* relational read inside the transaction needs this one; the pooled
|
|
341
|
+
* `getDrizzle(relations)` would read on a different connection and miss the
|
|
342
|
+
* transaction's uncommitted writes. Memoized per relations object, as
|
|
343
|
+
* `getDrizzle` is, so repeated calls with an unchanged config share one
|
|
344
|
+
* instance.
|
|
345
|
+
*
|
|
346
|
+
* @param relations - drizzle v1 relations config (defineRelations output)
|
|
347
|
+
*/
|
|
348
|
+
drizzleWithRelations<T = unknown>(relations: AnyRelations): T;
|
|
349
|
+
/**
|
|
350
|
+
* Run a Drizzle-built statement within the transaction, for its effect.
|
|
351
|
+
*
|
|
352
|
+
* @remarks
|
|
353
|
+
* The typed CRUD methods below resolve their table through the schema
|
|
354
|
+
* registry and reject any name it does not declare. That leaves no way to
|
|
355
|
+
* write to a table addressed under a name the ORM does not know — a table
|
|
356
|
+
* mid-rename, most of all — other than assembling SQL by hand, which also
|
|
357
|
+
* means hand-picking each driver's placeholder syntax.
|
|
358
|
+
*
|
|
359
|
+
* This accepts Drizzle's `sql` template instead, so identifier quoting and
|
|
360
|
+
* parameter binding are generated for the dialect in use. Implemented per
|
|
361
|
+
* adapter because the underlying call is not uniform: node-postgres and
|
|
362
|
+
* mysql2 expose `execute`, while better-sqlite3 needs `run` and throws on a
|
|
363
|
+
* statement that returns no rows.
|
|
364
|
+
*
|
|
365
|
+
* Returns nothing: this is for statements run to change data, not to read it.
|
|
366
|
+
*
|
|
367
|
+
* @param statement - Drizzle `sql` template to run
|
|
368
|
+
*/
|
|
369
|
+
runStatement(statement: SQL): Promise<void>;
|
|
370
|
+
/**
|
|
371
|
+
* Run a Drizzle-built statement within the transaction and return its rows.
|
|
372
|
+
*
|
|
373
|
+
* @remarks
|
|
374
|
+
* The reading half of `runStatement`, for the same reason: a table the schema
|
|
375
|
+
* registry does not declare cannot be reached through the typed CRUD methods,
|
|
376
|
+
* which reject the name outright. Implemented per adapter because the drivers
|
|
377
|
+
* disagree about both the call and the result — node-postgres answers
|
|
378
|
+
* `{ rows }`, mysql2 a `[rows, fields]` tuple, and better-sqlite3 needs `all`.
|
|
379
|
+
*
|
|
380
|
+
* @param statement - Drizzle `sql` template to run
|
|
381
|
+
* @returns Rows the statement produced
|
|
382
|
+
*/
|
|
383
|
+
queryStatement<T = Record<string, unknown>>(statement: SQL): Promise<T[]>;
|
|
384
|
+
/**
|
|
385
|
+
* Take an exclusive lock on a single row for the rest of this transaction.
|
|
386
|
+
*
|
|
387
|
+
* @remarks
|
|
388
|
+
* For read-modify-write sequences that must not interleave: without a lock
|
|
389
|
+
* another transaction can commit between the read and the write, leaving the
|
|
390
|
+
* caller's view of the prior state inconsistent with what its own write
|
|
391
|
+
* applied on top of.
|
|
392
|
+
*
|
|
393
|
+
* No-ops on dialects without row-level locking. SQLite is the case that
|
|
394
|
+
* matters and needs nothing — its transactions open with `BEGIN IMMEDIATE`,
|
|
395
|
+
* which already serializes writers.
|
|
396
|
+
*
|
|
397
|
+
* @param table - Table name
|
|
398
|
+
* @param id - Primary-key value of the row to lock
|
|
399
|
+
*/
|
|
400
|
+
lockRow(table: string, id: SqlParam): Promise<void>;
|
|
401
|
+
/**
|
|
402
|
+
* Insert a single record.
|
|
403
|
+
*
|
|
404
|
+
* @param table - Table name
|
|
405
|
+
* @param data - Record data to insert
|
|
406
|
+
* @param options - Insert options
|
|
407
|
+
* @returns Inserted record (with RETURNING columns if specified)
|
|
408
|
+
*/
|
|
409
|
+
insert<T = unknown>(table: string, data: Record<string, unknown>, options?: InsertOptions): Promise<T>;
|
|
410
|
+
/**
|
|
411
|
+
* Insert multiple records.
|
|
412
|
+
*
|
|
413
|
+
* @param table - Table name
|
|
414
|
+
* @param data - Array of records to insert
|
|
415
|
+
* @param options - Insert options
|
|
416
|
+
* @returns Inserted records (with RETURNING columns if specified)
|
|
417
|
+
*/
|
|
418
|
+
insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions): Promise<T[]>;
|
|
419
|
+
/**
|
|
420
|
+
* Select multiple records.
|
|
421
|
+
*
|
|
422
|
+
* @param table - Table name
|
|
423
|
+
* @param options - Select options (filtering, sorting, etc.)
|
|
424
|
+
* @returns Array of matching records
|
|
425
|
+
*/
|
|
426
|
+
select<T = unknown>(table: string, options?: SelectOptions): Promise<T[]>;
|
|
427
|
+
/**
|
|
428
|
+
* Select a single record.
|
|
429
|
+
*
|
|
430
|
+
* @param table - Table name
|
|
431
|
+
* @param options - Select options (filtering, sorting, etc.)
|
|
432
|
+
* @returns First matching record or null
|
|
433
|
+
*/
|
|
434
|
+
selectOne<T = unknown>(table: string, options?: SelectOptions): Promise<T | null>;
|
|
435
|
+
/**
|
|
436
|
+
* Update records.
|
|
437
|
+
*
|
|
438
|
+
* @remarks
|
|
439
|
+
* Built by the adapter rather than by the Drizzle query builder, as `insert`
|
|
440
|
+
* is: the statement writes the columns the PHYSICAL table has, where the
|
|
441
|
+
* pooled `update` writes the ones the runtime model declares. A column the
|
|
442
|
+
* model declares binds through its own encoder, exactly as the query builder
|
|
443
|
+
* binds it; one it does not declare binds the way this adapter's
|
|
444
|
+
* transactional insert binds every value; a key naming no column on the
|
|
445
|
+
* table is a database error rather than a silent drop. A key whose value is
|
|
446
|
+
* `undefined` is not written, `null` is, and an update naming nothing to
|
|
447
|
+
* write is refused.
|
|
448
|
+
*
|
|
449
|
+
* When `options.returning` asks for rows, they come from a read on this
|
|
450
|
+
* transaction, decoded as every read is — the model's view of the row,
|
|
451
|
+
* whatever columns were named. On PostgreSQL and SQLite that read is by the
|
|
452
|
+
* identities the statement reported through RETURNING, so it is exactly the
|
|
453
|
+
* rows this update changed. MySQL has no RETURNING, so there the read
|
|
454
|
+
* re-runs `where`, as it always has on that dialect: an update whose own
|
|
455
|
+
* write falsifies its `where` reads back nothing, and a row another
|
|
456
|
+
* transaction adds under the predicate meanwhile is included. A fenced
|
|
457
|
+
* compare-and-set wants `updateCount` on every dialect.
|
|
458
|
+
*
|
|
459
|
+
* @param table - Table name
|
|
460
|
+
* @param data - Data to update, keyed by SQL column name; Drizzle property
|
|
461
|
+
* names are accepted as well
|
|
462
|
+
* @param where - Conditions for records to update
|
|
463
|
+
* @param options - Update options
|
|
464
|
+
* @returns The updated rows when `returning` asked for them, else `[]`
|
|
465
|
+
*/
|
|
466
|
+
update<T = unknown>(table: string, data: Record<string, unknown>, where: WhereClause, options?: UpdateOptions): Promise<T[]>;
|
|
467
|
+
/**
|
|
468
|
+
* Update records and report how many rows the statement affected.
|
|
469
|
+
*
|
|
470
|
+
* @remarks
|
|
471
|
+
* The transactional half of the adapter's `updateCount`, and the only way to
|
|
472
|
+
* perform a fenced compare-and-set inside a transaction. `update` cannot
|
|
473
|
+
* answer this: without `returning` it discards the driver's count, and WITH
|
|
474
|
+
* `returning` on a dialect that lacks RETURNING it re-SELECTs using the same
|
|
475
|
+
* WHERE — so a conditional update whose own write falsifies its predicate
|
|
476
|
+
* reads back zero rows, and a write that landed reports as unmatched.
|
|
477
|
+
*
|
|
478
|
+
* 🔴 Inherits the adapter's MySQL caveat: MySQL counts CHANGED rows rather
|
|
479
|
+
* than matched ones, so a caller using this as a compare-and-set must write
|
|
480
|
+
* at least one column the update always moves — a state transition, a version
|
|
481
|
+
* bump, a timestamp of sufficient resolution. Postgres (`rowCount`) and
|
|
482
|
+
* SQLite (`changes`) count matched rows and do not need the precaution, which
|
|
483
|
+
* is exactly why it cannot be dropped: the dialect where the distinction
|
|
484
|
+
* exists is the one with no RETURNING to fall back on.
|
|
485
|
+
*
|
|
486
|
+
* @param table - Table name
|
|
487
|
+
* @param data - Column values to write
|
|
488
|
+
* @param where - Conditions the update must match
|
|
489
|
+
* @returns Number of rows the statement affected
|
|
490
|
+
*/
|
|
491
|
+
updateCount(table: string, data: Record<string, unknown>, where: WhereClause): Promise<number>;
|
|
492
|
+
/**
|
|
493
|
+
* Delete records.
|
|
494
|
+
*
|
|
495
|
+
* @param table - Table name
|
|
496
|
+
* @param where - Conditions for records to delete
|
|
497
|
+
* @param options - Delete options
|
|
498
|
+
* @returns Number of deleted records
|
|
499
|
+
*/
|
|
500
|
+
delete(table: string, where: WhereClause, options?: DeleteOptions): Promise<number>;
|
|
501
|
+
/**
|
|
502
|
+
* Upsert a record (INSERT or UPDATE).
|
|
503
|
+
*
|
|
504
|
+
* @param table - Table name
|
|
505
|
+
* @param data - Record data
|
|
506
|
+
* @param options - Upsert options (must specify conflict columns)
|
|
507
|
+
* @returns Upserted record (with RETURNING columns if specified)
|
|
508
|
+
*/
|
|
509
|
+
upsert<T = unknown>(table: string, data: Record<string, unknown>, options: UpsertOptions): Promise<T>;
|
|
510
|
+
/**
|
|
511
|
+
* Create a savepoint (PostgreSQL, SQLite only).
|
|
512
|
+
*
|
|
513
|
+
* @remarks
|
|
514
|
+
* Savepoints allow partial rollback within a transaction.
|
|
515
|
+
* Not supported on MySQL.
|
|
516
|
+
*
|
|
517
|
+
* @param name - Savepoint name
|
|
518
|
+
*/
|
|
519
|
+
savepoint?(name: string): Promise<void>;
|
|
520
|
+
/**
|
|
521
|
+
* Rollback to a savepoint (PostgreSQL, SQLite only).
|
|
522
|
+
*
|
|
523
|
+
* @remarks
|
|
524
|
+
* Discards all changes made after the savepoint was created.
|
|
525
|
+
*
|
|
526
|
+
* @param name - Savepoint name
|
|
527
|
+
*/
|
|
528
|
+
rollbackToSavepoint?(name: string): Promise<void>;
|
|
529
|
+
/**
|
|
530
|
+
* Release a savepoint (PostgreSQL, SQLite only).
|
|
531
|
+
*
|
|
532
|
+
* @remarks
|
|
533
|
+
* Commits the savepoint, making its changes permanent within the transaction.
|
|
534
|
+
*
|
|
535
|
+
* @param name - Savepoint name
|
|
536
|
+
*/
|
|
537
|
+
releaseSavepoint?(name: string): Promise<void>;
|
|
538
|
+
/**
|
|
539
|
+
* Return the Drizzle ORM instance bound to THIS transaction's connection.
|
|
540
|
+
*
|
|
541
|
+
* @remarks
|
|
542
|
+
* Runs Drizzle `sql` templates / fluent queries inside the caller's
|
|
543
|
+
* transaction (same client the delegated CRUD methods use), so services
|
|
544
|
+
* that drop to Drizzle raw SQL (e.g. junction-table writes) can participate
|
|
545
|
+
* in the transaction instead of running on the pooled connection. Required
|
|
546
|
+
* so callers never silently fall back to the pooled connection (which would
|
|
547
|
+
* run a write outside the transaction); every adapter must implement it.
|
|
548
|
+
* Generic return so callers narrow to the dialect Drizzle type they need
|
|
549
|
+
* without an `any` cast.
|
|
550
|
+
*/
|
|
551
|
+
getDrizzle<T = unknown>(): T;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Database feature capabilities.
|
|
555
|
+
*
|
|
556
|
+
* @remarks
|
|
557
|
+
* Describes what features are supported by a specific database adapter.
|
|
558
|
+
* Services can check these capabilities to conditionally enable features
|
|
559
|
+
* or implement fallback behavior.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```typescript
|
|
563
|
+
* const capabilities = adapter.getCapabilities();
|
|
564
|
+
* if (capabilities.supportsJsonb) {
|
|
565
|
+
* // Use JSONB-specific features
|
|
566
|
+
* } else if (capabilities.supportsJson) {
|
|
567
|
+
* // Fallback to JSON
|
|
568
|
+
* }
|
|
569
|
+
* ```
|
|
570
|
+
*
|
|
571
|
+
* @public
|
|
572
|
+
*/
|
|
573
|
+
interface DatabaseCapabilities {
|
|
574
|
+
/** Database dialect */
|
|
575
|
+
dialect: SupportedDialect;
|
|
576
|
+
/**
|
|
577
|
+
* Native JSONB support (PostgreSQL only).
|
|
578
|
+
*
|
|
579
|
+
* @remarks
|
|
580
|
+
* JSONB provides better performance and indexing than JSON.
|
|
581
|
+
* Other databases will use JSON or emulated JSON.
|
|
582
|
+
*/
|
|
583
|
+
supportsJsonb: boolean;
|
|
584
|
+
/**
|
|
585
|
+
* JSON column type support.
|
|
586
|
+
*
|
|
587
|
+
* @remarks
|
|
588
|
+
* All supported databases have some form of JSON support:
|
|
589
|
+
* - PostgreSQL: Native JSON and JSONB
|
|
590
|
+
* - MySQL: Native JSON column type
|
|
591
|
+
* - SQLite: JSON functions (json_extract, json_array, etc.)
|
|
592
|
+
*/
|
|
593
|
+
supportsJson: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* Array column type support (PostgreSQL only).
|
|
596
|
+
*
|
|
597
|
+
* @remarks
|
|
598
|
+
* PostgreSQL has native array types. Other databases must use
|
|
599
|
+
* JSON arrays or separate tables.
|
|
600
|
+
*/
|
|
601
|
+
supportsArrays: boolean;
|
|
602
|
+
/**
|
|
603
|
+
* Generated/computed columns support.
|
|
604
|
+
*
|
|
605
|
+
* @remarks
|
|
606
|
+
* Support for columns whose values are automatically computed from
|
|
607
|
+
* other columns:
|
|
608
|
+
* - PostgreSQL: GENERATED ALWAYS AS ... STORED
|
|
609
|
+
* - MySQL: Generated columns
|
|
610
|
+
* - SQLite: Generated columns (3.31.0+)
|
|
611
|
+
*/
|
|
612
|
+
supportsGeneratedColumns: boolean;
|
|
613
|
+
/**
|
|
614
|
+
* Full-text search support.
|
|
615
|
+
*
|
|
616
|
+
* @remarks
|
|
617
|
+
* Native full-text search capabilities:
|
|
618
|
+
* - PostgreSQL: tsvector/tsquery
|
|
619
|
+
* - MySQL: FULLTEXT indexes (limited)
|
|
620
|
+
* - SQLite: FTS5 extension (not enabled by default)
|
|
621
|
+
*/
|
|
622
|
+
supportsFts: boolean;
|
|
623
|
+
/**
|
|
624
|
+
* Case-insensitive ILIKE operator support (PostgreSQL only).
|
|
625
|
+
*
|
|
626
|
+
* @remarks
|
|
627
|
+
* Other databases must emulate with LOWER(column) LIKE LOWER(value).
|
|
628
|
+
*/
|
|
629
|
+
supportsIlike: boolean;
|
|
630
|
+
/**
|
|
631
|
+
* RETURNING clause support.
|
|
632
|
+
*
|
|
633
|
+
* @remarks
|
|
634
|
+
* Support for returning data from INSERT/UPDATE/DELETE:
|
|
635
|
+
* - PostgreSQL: Yes
|
|
636
|
+
* - MySQL: No (requires separate SELECT)
|
|
637
|
+
* - SQLite: Yes
|
|
638
|
+
*/
|
|
639
|
+
supportsReturning: boolean;
|
|
640
|
+
/**
|
|
641
|
+
* Savepoint support for nested transactions.
|
|
642
|
+
*
|
|
643
|
+
* @remarks
|
|
644
|
+
* - PostgreSQL: Yes
|
|
645
|
+
* - MySQL: No (limited support, not recommended)
|
|
646
|
+
* - SQLite: Yes
|
|
647
|
+
*/
|
|
648
|
+
supportsSavepoints: boolean;
|
|
649
|
+
/**
|
|
650
|
+
* ON CONFLICT clause support for upserts.
|
|
651
|
+
*
|
|
652
|
+
* @remarks
|
|
653
|
+
* - PostgreSQL: ON CONFLICT DO NOTHING/UPDATE
|
|
654
|
+
* - MySQL: ON DUPLICATE KEY UPDATE (different syntax)
|
|
655
|
+
* - SQLite: ON CONFLICT (similar to PostgreSQL)
|
|
656
|
+
*/
|
|
657
|
+
supportsOnConflict: boolean;
|
|
658
|
+
/**
|
|
659
|
+
* Maximum number of parameters per query.
|
|
660
|
+
*
|
|
661
|
+
* @remarks
|
|
662
|
+
* Database-specific limits:
|
|
663
|
+
* - PostgreSQL: 65,535
|
|
664
|
+
* - MySQL: 65,535
|
|
665
|
+
* - SQLite: 999 (can be increased with SQLITE_MAX_VARIABLE_NUMBER)
|
|
666
|
+
*/
|
|
667
|
+
maxParamsPerQuery: number;
|
|
668
|
+
/**
|
|
669
|
+
* Maximum length for table/column identifiers.
|
|
670
|
+
*
|
|
671
|
+
* @remarks
|
|
672
|
+
* - PostgreSQL: 63 bytes
|
|
673
|
+
* - MySQL: 64 characters
|
|
674
|
+
* - SQLite: No limit (practically unlimited)
|
|
675
|
+
*/
|
|
676
|
+
maxIdentifierLength: number;
|
|
677
|
+
/**
|
|
678
|
+
* Whether the server accepts `SELECT ... FOR SHARE`.
|
|
679
|
+
*
|
|
680
|
+
* @remarks
|
|
681
|
+
* Reported by the MySQL adapter once it has connected and read the server's
|
|
682
|
+
* version: MySQL 8, Aurora MySQL and Vitess/PlanetScale accept it, MariaDB
|
|
683
|
+
* and TiDB reject it as a syntax error. PostgreSQL always accepts it and
|
|
684
|
+
* SQLite has no row locks, so their adapters leave it unset. Unset means
|
|
685
|
+
* not known; a caller then takes a lock every server accepts.
|
|
686
|
+
*
|
|
687
|
+
* @experimental
|
|
688
|
+
*/
|
|
689
|
+
sharedRowLock?: boolean;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Connection pool statistics.
|
|
693
|
+
*
|
|
694
|
+
* @remarks
|
|
695
|
+
* Provides visibility into connection pool health. Not all adapters
|
|
696
|
+
* provide pool statistics (e.g., SQLite is single-connection).
|
|
697
|
+
*
|
|
698
|
+
* @public
|
|
699
|
+
*/
|
|
700
|
+
interface PoolStats {
|
|
701
|
+
/** Total number of connections in the pool */
|
|
702
|
+
total: number;
|
|
703
|
+
/** Number of idle (available) connections */
|
|
704
|
+
idle: number;
|
|
705
|
+
/** Number of clients waiting for a connection */
|
|
706
|
+
waiting: number;
|
|
707
|
+
/** Number of connections currently in use */
|
|
708
|
+
active: number;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Migration definition.
|
|
712
|
+
*
|
|
713
|
+
* @remarks
|
|
714
|
+
* Represents a single database migration with up and optional down functions.
|
|
715
|
+
* Migrations can be defined as raw SQL strings or as functions that use the
|
|
716
|
+
* transaction context for more complex operations.
|
|
717
|
+
*
|
|
718
|
+
* @public
|
|
719
|
+
*/
|
|
720
|
+
interface Migration {
|
|
721
|
+
/** Unique migration identifier (e.g., "20250104_001_create_users") */
|
|
722
|
+
id: string;
|
|
723
|
+
/** Human-readable migration name */
|
|
724
|
+
name: string;
|
|
725
|
+
/** Unix timestamp when migration was created */
|
|
726
|
+
timestamp: number;
|
|
727
|
+
/** Forward migration (apply changes) */
|
|
728
|
+
up: string | ((tx: TransactionContext) => Promise<void>);
|
|
729
|
+
/** Reverse migration (undo changes) - optional */
|
|
730
|
+
down?: string | ((tx: TransactionContext) => Promise<void>);
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Migration record stored in the database.
|
|
734
|
+
*
|
|
735
|
+
* @remarks
|
|
736
|
+
* Tracks which migrations have been applied to the database.
|
|
737
|
+
* The migrations table is automatically created by the adapter.
|
|
738
|
+
*
|
|
739
|
+
* @public
|
|
740
|
+
*/
|
|
741
|
+
interface MigrationRecord {
|
|
742
|
+
/** Migration identifier */
|
|
743
|
+
id: string;
|
|
744
|
+
/** Migration name */
|
|
745
|
+
name: string;
|
|
746
|
+
/** When the migration was applied */
|
|
747
|
+
appliedAt: Date;
|
|
748
|
+
/** Optional checksum to detect migration changes */
|
|
749
|
+
checksum?: string;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Migration execution result.
|
|
753
|
+
*
|
|
754
|
+
* @remarks
|
|
755
|
+
* Provides information about migration status including applied and
|
|
756
|
+
* pending migrations.
|
|
757
|
+
*
|
|
758
|
+
* @public
|
|
759
|
+
*/
|
|
760
|
+
interface MigrationResult {
|
|
761
|
+
/** Migrations that were applied in this execution */
|
|
762
|
+
applied: MigrationRecord[];
|
|
763
|
+
/** Migrations that are pending (not yet applied) */
|
|
764
|
+
pending: Migration[];
|
|
765
|
+
/** ID of the current (most recent) migration, or null if none applied */
|
|
766
|
+
current: string | null;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Options for migration execution.
|
|
770
|
+
*
|
|
771
|
+
* @public
|
|
772
|
+
*/
|
|
773
|
+
interface MigrationOptions {
|
|
774
|
+
/** Target migration to migrate to (default: latest) */
|
|
775
|
+
target?: string;
|
|
776
|
+
/** Dry run mode - don't actually apply migrations */
|
|
777
|
+
dryRun?: boolean;
|
|
778
|
+
/** Run migrations in a single transaction (default: true) */
|
|
779
|
+
useTransaction?: boolean;
|
|
780
|
+
/**
|
|
781
|
+
* Strict checksum validation (default: true).
|
|
782
|
+
* If true, modified migrations will cause an error.
|
|
783
|
+
* If false, modified migrations will generate a warning.
|
|
784
|
+
*/
|
|
785
|
+
strictChecksums?: boolean;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Migration status information.
|
|
789
|
+
*
|
|
790
|
+
* @public
|
|
791
|
+
*/
|
|
792
|
+
interface MigrationStatus {
|
|
793
|
+
/** Current migration ID (most recently applied) */
|
|
794
|
+
current: string | null;
|
|
795
|
+
/** Total number of applied migrations */
|
|
796
|
+
appliedCount: number;
|
|
797
|
+
/** Total number of pending migrations */
|
|
798
|
+
pendingCount: number;
|
|
799
|
+
/** Applied migration records */
|
|
800
|
+
applied: MigrationRecord[];
|
|
801
|
+
/** Pending migrations */
|
|
802
|
+
pending: Migration[];
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Database error type definitions.
|
|
806
|
+
*
|
|
807
|
+
* @packageDocumentation
|
|
808
|
+
*/
|
|
809
|
+
/**
|
|
810
|
+
* Database error classification.
|
|
811
|
+
*
|
|
812
|
+
* @remarks
|
|
813
|
+
* Categorizes database errors for consistent error handling across adapters.
|
|
814
|
+
* Each adapter translates database-specific error codes to these kinds.
|
|
815
|
+
*
|
|
816
|
+
* @public
|
|
817
|
+
*/
|
|
818
|
+
type DatabaseErrorKind = "connection" | "query" | "constraint" | "unique_violation" | "foreign_key_violation" | "check_violation" | "not_null_violation" | "deadlock" | "timeout" | "serialization_failure" | "unsupported_version" | "unknown";
|
|
819
|
+
/**
|
|
820
|
+
* Enhanced database error interface.
|
|
821
|
+
*
|
|
822
|
+
* @remarks
|
|
823
|
+
* Extends the standard Error interface with database-specific context.
|
|
824
|
+
* Adapters should throw errors implementing this interface for consistent
|
|
825
|
+
* error handling.
|
|
826
|
+
*
|
|
827
|
+
* @example
|
|
828
|
+
* ```typescript
|
|
829
|
+
* try {
|
|
830
|
+
* await adapter.insert('users', { email: 'duplicate@example.com' });
|
|
831
|
+
* } catch (error) {
|
|
832
|
+
* if (isDatabaseError(error) && error.kind === 'unique_violation') {
|
|
833
|
+
* console.log(`Duplicate ${error.column} in ${error.table}`);
|
|
834
|
+
* }
|
|
835
|
+
* }
|
|
836
|
+
* ```
|
|
837
|
+
*
|
|
838
|
+
* @public
|
|
839
|
+
*/
|
|
840
|
+
interface DatabaseError extends Error {
|
|
841
|
+
/** Error classification */
|
|
842
|
+
kind: DatabaseErrorKind;
|
|
843
|
+
/** Database-specific error code (e.g., "23505" for PostgreSQL unique violation) */
|
|
844
|
+
code?: string;
|
|
845
|
+
/** Constraint name that was violated (if applicable) */
|
|
846
|
+
constraint?: string;
|
|
847
|
+
/** Table name involved in the error */
|
|
848
|
+
table?: string;
|
|
849
|
+
/** Column name involved in the error */
|
|
850
|
+
column?: string;
|
|
851
|
+
/** Detailed error description from the database */
|
|
852
|
+
detail?: string;
|
|
853
|
+
/** Hint for resolving the error */
|
|
854
|
+
hint?: string;
|
|
855
|
+
/** Original error from the database driver */
|
|
856
|
+
cause?: Error;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Type guard for DatabaseError.
|
|
860
|
+
*
|
|
861
|
+
* @remarks
|
|
862
|
+
* Checks if an error is a DatabaseError with proper typing.
|
|
863
|
+
*
|
|
864
|
+
* @param error - Error to check
|
|
865
|
+
* @returns True if error is a DatabaseError
|
|
866
|
+
*
|
|
867
|
+
* @public
|
|
868
|
+
*/
|
|
869
|
+
declare function isDatabaseError(error: unknown): error is DatabaseError;
|
|
870
|
+
/**
|
|
871
|
+
* Whether an error is the application's verdict rather than the database's
|
|
872
|
+
* failure.
|
|
873
|
+
*
|
|
874
|
+
* Work running inside a transaction may throw to roll the write back — a
|
|
875
|
+
* refused value, a permission denial — and such an error is not something the
|
|
876
|
+
* driver produced. Classifying it as a database error replaces its code and its
|
|
877
|
+
* payload with a generic one, so a caller that asked for a refusal is handed an
|
|
878
|
+
* unexplained failure instead, and per-field validation detail is lost on the
|
|
879
|
+
* way out.
|
|
880
|
+
*
|
|
881
|
+
* @param error - Error to check
|
|
882
|
+
* @returns True if the error was raised by application code
|
|
883
|
+
*
|
|
884
|
+
* @public
|
|
885
|
+
*/
|
|
886
|
+
declare function isApplicationError(error: unknown): boolean;
|
|
887
|
+
/**
|
|
888
|
+
* Database error constructor options.
|
|
889
|
+
*
|
|
890
|
+
* @public
|
|
891
|
+
*/
|
|
892
|
+
interface DatabaseErrorOptions {
|
|
893
|
+
/** Error classification */
|
|
894
|
+
kind: DatabaseErrorKind;
|
|
895
|
+
/** Error message */
|
|
896
|
+
message: string;
|
|
897
|
+
/** Database-specific error code */
|
|
898
|
+
code?: string;
|
|
899
|
+
/** Constraint name */
|
|
900
|
+
constraint?: string;
|
|
901
|
+
/** Table name */
|
|
902
|
+
table?: string;
|
|
903
|
+
/** Column name */
|
|
904
|
+
column?: string;
|
|
905
|
+
/** Detailed description */
|
|
906
|
+
detail?: string;
|
|
907
|
+
/** Resolution hint */
|
|
908
|
+
hint?: string;
|
|
909
|
+
/** Original error */
|
|
910
|
+
cause?: Error;
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Create a DatabaseError instance.
|
|
914
|
+
*
|
|
915
|
+
* @remarks
|
|
916
|
+
* Helper function to create properly structured DatabaseError objects.
|
|
917
|
+
*
|
|
918
|
+
* @param options - Error options
|
|
919
|
+
* @returns DatabaseError instance
|
|
920
|
+
*
|
|
921
|
+
* @public
|
|
922
|
+
*/
|
|
923
|
+
declare function createDatabaseError(options: DatabaseErrorOptions): DatabaseError;
|
|
924
|
+
/**
|
|
925
|
+
* The code an adapter gives the error it raises when a request has waited
|
|
926
|
+
* longer than `pool.connectionTimeoutMs` for a database connection.
|
|
927
|
+
*
|
|
928
|
+
* A code of the adapters' own rather than the driver's wording, because the
|
|
929
|
+
* drivers disagree: pg-pool raises a plain `Error` with no code, mysql2 has no
|
|
930
|
+
* such wait to time out, and better-sqlite3 has no pool. Core reads this one
|
|
931
|
+
* code to answer with its retryable "database busy" error.
|
|
932
|
+
*
|
|
933
|
+
* @public
|
|
934
|
+
*/
|
|
935
|
+
declare const POOL_WAIT_TIMEOUT_CODE = "NEXTLY_POOL_WAIT_TIMEOUT";
|
|
936
|
+
/**
|
|
937
|
+
* The error for a request that waited `boundMs` for a database connection and
|
|
938
|
+
* was given none.
|
|
939
|
+
*
|
|
940
|
+
* @param boundMs - The bound it waited, `pool.connectionTimeoutMs`
|
|
941
|
+
* @param cause - The driver's own error, when the driver raised one
|
|
942
|
+
*
|
|
943
|
+
* @public
|
|
944
|
+
*/
|
|
945
|
+
declare function poolWaitTimeoutError(boundMs: number, cause?: Error): DatabaseError;
|
|
946
|
+
/**
|
|
947
|
+
* Logger interface for adapter operations.
|
|
948
|
+
*
|
|
949
|
+
* @remarks
|
|
950
|
+
* Adapters use this interface to log queries, errors, and performance metrics.
|
|
951
|
+
*
|
|
952
|
+
* @public
|
|
953
|
+
*/
|
|
954
|
+
interface AdapterLogger {
|
|
955
|
+
/**
|
|
956
|
+
* Log a query execution.
|
|
957
|
+
*
|
|
958
|
+
* @param sql - SQL statement
|
|
959
|
+
* @param params - Query parameters
|
|
960
|
+
* @param durationMs - Query execution time in milliseconds
|
|
961
|
+
*/
|
|
962
|
+
query?: (sql: string, params?: SqlParam[], durationMs?: number) => void;
|
|
963
|
+
/**
|
|
964
|
+
* Log an error.
|
|
965
|
+
*
|
|
966
|
+
* @param error - Error object
|
|
967
|
+
* @param context - Additional context about the error
|
|
968
|
+
*/
|
|
969
|
+
error?: (error: Error, context?: Record<string, unknown>) => void;
|
|
970
|
+
/**
|
|
971
|
+
* Log a debug message.
|
|
972
|
+
*
|
|
973
|
+
* @param message - Debug message
|
|
974
|
+
* @param context - Additional context
|
|
975
|
+
*/
|
|
976
|
+
debug?: (message: string, context?: Record<string, unknown>) => void;
|
|
977
|
+
/**
|
|
978
|
+
* Log a warning.
|
|
979
|
+
*
|
|
980
|
+
* @param message - Warning message
|
|
981
|
+
* @param context - Additional context
|
|
982
|
+
*/
|
|
983
|
+
warn?: (message: string, context?: Record<string, unknown>) => void;
|
|
984
|
+
/**
|
|
985
|
+
* Log an info message.
|
|
986
|
+
*
|
|
987
|
+
* @param message - Info message
|
|
988
|
+
* @param context - Additional context
|
|
989
|
+
*/
|
|
990
|
+
info?: (message: string, context?: Record<string, unknown>) => void;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Connection pool configuration.
|
|
994
|
+
*
|
|
995
|
+
* @remarks
|
|
996
|
+
* Controls connection pooling behavior. SQLite adapters ignore these
|
|
997
|
+
* settings as SQLite uses a single connection, except
|
|
998
|
+
* `connectionTimeoutMs`, which bounds the wait for that one connection.
|
|
999
|
+
*
|
|
1000
|
+
* @public
|
|
1001
|
+
*/
|
|
1002
|
+
interface PoolConfig {
|
|
1003
|
+
/** Minimum number of connections in the pool */
|
|
1004
|
+
min?: number;
|
|
1005
|
+
/** Maximum number of connections in the pool */
|
|
1006
|
+
max?: number;
|
|
1007
|
+
/** Time (ms) before an idle connection is closed */
|
|
1008
|
+
idleTimeoutMs?: number;
|
|
1009
|
+
/**
|
|
1010
|
+
* Time (ms) a request waits for a connection before it fails as
|
|
1011
|
+
* "database busy" (code `NEXTLY_POOL_WAIT_TIMEOUT` from the adapter,
|
|
1012
|
+
* `DATABASE_BUSY` from Nextly), the same on every dialect. On PostgreSQL
|
|
1013
|
+
* and MySQL it is the wait for a connection already in the pool; it is also
|
|
1014
|
+
* the time a new one gets to open, and one that cannot open in time is a
|
|
1015
|
+
* connection error rather than busy. On SQLite, the wait for the one
|
|
1016
|
+
* connection behind the transactions ahead. `0` waits without limit.
|
|
1017
|
+
*
|
|
1018
|
+
* @default 15000 (a PostgreSQL provider may set its own: Neon's is 20000)
|
|
1019
|
+
*/
|
|
1020
|
+
connectionTimeoutMs?: number;
|
|
1021
|
+
/** Time (ms) before considering an unused connection stale */
|
|
1022
|
+
maxLifetimeMs?: number;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* SSL/TLS configuration for database connections.
|
|
1026
|
+
*
|
|
1027
|
+
* @remarks
|
|
1028
|
+
* Relevant for PostgreSQL and MySQL. SQLite doesn't use network connections.
|
|
1029
|
+
*
|
|
1030
|
+
* @public
|
|
1031
|
+
*/
|
|
1032
|
+
interface SslConfig {
|
|
1033
|
+
/** Reject unauthorized certificates (default: true for production) */
|
|
1034
|
+
rejectUnauthorized?: boolean;
|
|
1035
|
+
/** Path to CA certificate file */
|
|
1036
|
+
ca?: string;
|
|
1037
|
+
/** Path to client certificate file */
|
|
1038
|
+
cert?: string;
|
|
1039
|
+
/** Path to client private key file */
|
|
1040
|
+
key?: string;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Base adapter configuration.
|
|
1044
|
+
*
|
|
1045
|
+
* @remarks
|
|
1046
|
+
* Common configuration options for all database adapters. Dialect-specific
|
|
1047
|
+
* adapters may extend this interface with additional options.
|
|
1048
|
+
*
|
|
1049
|
+
* @public
|
|
1050
|
+
*/
|
|
1051
|
+
interface BaseAdapterConfig {
|
|
1052
|
+
/**
|
|
1053
|
+
* Database connection URL.
|
|
1054
|
+
*
|
|
1055
|
+
* @remarks
|
|
1056
|
+
* Examples:
|
|
1057
|
+
* - PostgreSQL: `postgres://user:pass@localhost:5432/dbname`
|
|
1058
|
+
* - MySQL: `mysql://user:pass@localhost:3306/dbname`
|
|
1059
|
+
* - SQLite: `file:./data/app.db` or `file::memory:`
|
|
1060
|
+
*/
|
|
1061
|
+
url?: string;
|
|
1062
|
+
/** Database host (alternative to URL) */
|
|
1063
|
+
host?: string;
|
|
1064
|
+
/** Database port (alternative to URL) */
|
|
1065
|
+
port?: number;
|
|
1066
|
+
/** Database name (alternative to URL) */
|
|
1067
|
+
database?: string;
|
|
1068
|
+
/** Database user (alternative to URL) */
|
|
1069
|
+
user?: string;
|
|
1070
|
+
/** Database password (alternative to URL) */
|
|
1071
|
+
password?: string;
|
|
1072
|
+
/** Connection pool configuration */
|
|
1073
|
+
pool?: PoolConfig;
|
|
1074
|
+
/** Logger instance for queries and errors */
|
|
1075
|
+
logger?: AdapterLogger;
|
|
1076
|
+
/**
|
|
1077
|
+
* Schema name (PostgreSQL only).
|
|
1078
|
+
*
|
|
1079
|
+
* Applied as `search_path` in the pool's startup options, which is the
|
|
1080
|
+
* pooled-safe way to set it: a `SET search_path` issued as a query belongs
|
|
1081
|
+
* to whichever pooled connection happened to run it, so the next checkout
|
|
1082
|
+
* would see the default again.
|
|
1083
|
+
*
|
|
1084
|
+
* The adapter creates the schema if it is missing, because `search_path`
|
|
1085
|
+
* naming a schema that does not exist does not fail — it falls through, and
|
|
1086
|
+
* the tables land somewhere else.
|
|
1087
|
+
*
|
|
1088
|
+
* Declared here since the first release and read by nothing until now, which
|
|
1089
|
+
* is why setting it appeared to work and changed nothing.
|
|
1090
|
+
*/
|
|
1091
|
+
schema?: string;
|
|
1092
|
+
/** SSL/TLS configuration */
|
|
1093
|
+
ssl?: SslConfig | boolean;
|
|
1094
|
+
/**
|
|
1095
|
+
* Default query timeout in milliseconds.
|
|
1096
|
+
*
|
|
1097
|
+
* @remarks
|
|
1098
|
+
* Queries exceeding this limit will be aborted and throw a DatabaseError
|
|
1099
|
+
* with kind 'timeout'. This prevents runaway queries from blocking the
|
|
1100
|
+
* system indefinitely.
|
|
1101
|
+
*
|
|
1102
|
+
* Can be overridden per-transaction via TransactionOptions.timeoutMs.
|
|
1103
|
+
*
|
|
1104
|
+
* Set to 0 or undefined to disable timeout (not recommended for production).
|
|
1105
|
+
*
|
|
1106
|
+
* @default 15000 (15 seconds)
|
|
1107
|
+
*
|
|
1108
|
+
* @example
|
|
1109
|
+
* ```typescript
|
|
1110
|
+
* const adapter = createPostgresAdapter({
|
|
1111
|
+
* url: 'postgres://localhost/mydb',
|
|
1112
|
+
* queryTimeoutMs: 30000, // 30 seconds
|
|
1113
|
+
* });
|
|
1114
|
+
* ```
|
|
1115
|
+
*/
|
|
1116
|
+
queryTimeoutMs?: number;
|
|
1117
|
+
/** Additional connection options (driver-specific) */
|
|
1118
|
+
options?: Record<string, unknown>;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* PostgreSQL-specific adapter configuration.
|
|
1122
|
+
*
|
|
1123
|
+
* @public
|
|
1124
|
+
*/
|
|
1125
|
+
interface PostgresAdapterConfig extends BaseAdapterConfig {
|
|
1126
|
+
/** Application name for connection tracking */
|
|
1127
|
+
applicationName?: string;
|
|
1128
|
+
/** Statement timeout in milliseconds */
|
|
1129
|
+
statementTimeout?: number;
|
|
1130
|
+
/** Query timeout in milliseconds */
|
|
1131
|
+
queryTimeout?: number;
|
|
1132
|
+
/** Enable prepared statements (default: true) */
|
|
1133
|
+
preparedStatements?: boolean;
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* MySQL-specific adapter configuration.
|
|
1137
|
+
*
|
|
1138
|
+
* @public
|
|
1139
|
+
*/
|
|
1140
|
+
interface MySqlAdapterConfig extends BaseAdapterConfig {
|
|
1141
|
+
/** Character set (default: utf8mb4) */
|
|
1142
|
+
charset?: string;
|
|
1143
|
+
/** Timezone (default: 'local') */
|
|
1144
|
+
timezone?: string;
|
|
1145
|
+
/** Enable multiple statements per query (default: false, security risk) */
|
|
1146
|
+
multipleStatements?: boolean;
|
|
1147
|
+
/** Date strings instead of Date objects (default: false) */
|
|
1148
|
+
dateStrings?: boolean;
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* SQLite-specific adapter configuration.
|
|
1152
|
+
*
|
|
1153
|
+
* @public
|
|
1154
|
+
*/
|
|
1155
|
+
interface SqliteAdapterConfig extends BaseAdapterConfig {
|
|
1156
|
+
/** Enable WAL mode (default: true) */
|
|
1157
|
+
wal?: boolean;
|
|
1158
|
+
/** Busy timeout in milliseconds (default: 5000) */
|
|
1159
|
+
busyTimeout?: number;
|
|
1160
|
+
/** Enable foreign keys (default: true) */
|
|
1161
|
+
foreignKeys?: boolean;
|
|
1162
|
+
/** Memory-only database (overrides url) */
|
|
1163
|
+
memory?: boolean;
|
|
1164
|
+
/** Read-only mode (default: false) */
|
|
1165
|
+
readonly?: boolean;
|
|
1166
|
+
}
|
|
1167
|
+
export { UpdateOptions as A, TransactionContext as C, DeleteOptions as D, CountOptions as E, WhereClause as F, WhereCondition as I, WhereOperator as L, JoinSpec as M, OrderBySpec as N, InsertOptions as O, WHERE_OPERATORS as P, PoolStats as S, TransactionOptions as T, MigrationOptions as _, PostgresAdapterConfig as a, MigrationStatus as b, DatabaseError as c, POOL_WAIT_TIMEOUT_CODE as d, createDatabaseError as f, Migration as g, poolWaitTimeoutError as h, PoolConfig as i, UpsertOptions as j, SelectOptions as k, DatabaseErrorKind as l, isDatabaseError as m, BaseAdapterConfig as n, SqliteAdapterConfig as o, isApplicationError as p, MySqlAdapterConfig as r, SslConfig as s, AdapterLogger as t, DatabaseErrorOptions as u, MigrationRecord as v, TransactionIsolationLevel as w, DatabaseCapabilities as x, MigrationResult as y };
|
|
1168
|
+
//# sourceMappingURL=index-BYb6cDli.d.ts.map
|