@remix-run/data-table 0.1.0 → 0.2.0
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 +306 -55
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/lib/adapter.d.ts +386 -16
- package/dist/lib/adapter.d.ts.map +1 -1
- package/dist/lib/column.d.ts +193 -0
- package/dist/lib/column.d.ts.map +1 -0
- package/dist/lib/column.js +302 -0
- package/dist/lib/database/execution-context.d.ts +10 -0
- package/dist/lib/database/execution-context.d.ts.map +1 -0
- package/dist/lib/database/execution-context.js +1 -0
- package/dist/lib/database/helpers.d.ts +26 -0
- package/dist/lib/database/helpers.d.ts.map +1 -0
- package/dist/lib/database/helpers.js +116 -0
- package/dist/lib/database/query-execution.d.ts +7 -0
- package/dist/lib/database/query-execution.d.ts.map +1 -0
- package/dist/lib/database/query-execution.js +401 -0
- package/dist/lib/database/relations.d.ts +4 -0
- package/dist/lib/database/relations.d.ts.map +1 -0
- package/dist/lib/database/relations.js +207 -0
- package/dist/lib/database/write-lifecycle.d.ts +13 -0
- package/dist/lib/database/write-lifecycle.d.ts.map +1 -0
- package/dist/lib/database/write-lifecycle.js +279 -0
- package/dist/lib/database.d.ts +141 -238
- package/dist/lib/database.d.ts.map +1 -1
- package/dist/lib/database.js +73 -1122
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +9 -0
- package/dist/lib/migrations/filename.d.ts +12 -0
- package/dist/lib/migrations/filename.d.ts.map +1 -0
- package/dist/lib/migrations/filename.js +20 -0
- package/dist/lib/migrations/helpers.d.ts +11 -0
- package/dist/lib/migrations/helpers.d.ts.map +1 -0
- package/dist/lib/migrations/helpers.js +77 -0
- package/dist/lib/migrations/journal-store.d.ts +15 -0
- package/dist/lib/migrations/journal-store.d.ts.map +1 -0
- package/dist/lib/migrations/journal-store.js +83 -0
- package/dist/lib/migrations/registry.d.ts +27 -0
- package/dist/lib/migrations/registry.d.ts.map +1 -0
- package/dist/lib/migrations/registry.js +51 -0
- package/dist/lib/migrations/runner.d.ts +20 -0
- package/dist/lib/migrations/runner.d.ts.map +1 -0
- package/dist/lib/migrations/runner.js +273 -0
- package/dist/lib/migrations/schema-api.d.ts +7 -0
- package/dist/lib/migrations/schema-api.d.ts.map +1 -0
- package/dist/lib/migrations/schema-api.js +326 -0
- package/dist/lib/migrations-node.d.ts +17 -0
- package/dist/lib/migrations-node.d.ts.map +1 -0
- package/dist/lib/migrations-node.js +65 -0
- package/dist/lib/migrations.d.ts +292 -0
- package/dist/lib/migrations.d.ts.map +1 -0
- package/dist/lib/migrations.js +38 -0
- package/dist/lib/operators.d.ts +3 -0
- package/dist/lib/operators.d.ts.map +1 -1
- package/dist/lib/query.d.ts +159 -0
- package/dist/lib/query.d.ts.map +1 -0
- package/dist/lib/query.js +401 -0
- package/dist/lib/references.d.ts +0 -1
- package/dist/lib/references.d.ts.map +1 -1
- package/dist/lib/sql-helpers.d.ts +50 -0
- package/dist/lib/sql-helpers.d.ts.map +1 -0
- package/dist/lib/sql-helpers.js +111 -0
- package/dist/lib/sql.d.ts +23 -6
- package/dist/lib/sql.d.ts.map +1 -1
- package/dist/lib/sql.js +19 -5
- package/dist/lib/table.d.ts +355 -40
- package/dist/lib/table.d.ts.map +1 -1
- package/dist/lib/table.js +113 -90
- package/dist/migrations/node.d.ts +2 -0
- package/dist/migrations/node.d.ts.map +1 -0
- package/dist/migrations/node.js +1 -0
- package/dist/migrations.d.ts +8 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +5 -0
- package/dist/operators.d.ts +3 -0
- package/dist/operators.d.ts.map +1 -0
- package/dist/operators.js +1 -0
- package/dist/sql-helpers.d.ts +3 -0
- package/dist/sql-helpers.d.ts.map +1 -0
- package/dist/sql-helpers.js +1 -0
- package/package.json +23 -8
- package/src/index.ts +93 -10
- package/src/lib/adapter.ts +469 -25
- package/src/lib/column.ts +384 -0
- package/src/lib/database/execution-context.ts +15 -0
- package/src/lib/database/helpers.ts +216 -0
- package/src/lib/database/query-execution.ts +638 -0
- package/src/lib/database/relations.ts +332 -0
- package/src/lib/database/write-lifecycle.ts +487 -0
- package/src/lib/database.ts +246 -1848
- package/src/lib/errors.ts +10 -0
- package/src/lib/migrations/filename.ts +25 -0
- package/src/lib/migrations/helpers.ts +108 -0
- package/src/lib/migrations/journal-store.ts +122 -0
- package/src/lib/migrations/registry.ts +62 -0
- package/src/lib/migrations/runner.ts +374 -0
- package/src/lib/migrations/schema-api.ts +417 -0
- package/src/lib/migrations-node.ts +71 -0
- package/src/lib/migrations.ts +328 -0
- package/src/lib/operators.ts +3 -0
- package/src/lib/query.ts +958 -0
- package/src/lib/references.ts +0 -1
- package/src/lib/sql-helpers.ts +146 -0
- package/src/lib/sql.ts +23 -6
- package/src/lib/table.ts +484 -156
- package/src/migrations/node.ts +1 -0
- package/src/migrations.ts +26 -0
- package/src/operators.ts +18 -0
- package/src/sql-helpers.ts +9 -0
package/src/lib/adapter.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type ReturningSelection = '*' | string[]
|
|
|
33
33
|
/**
|
|
34
34
|
* Canonical select statement shape consumed by adapters.
|
|
35
35
|
*/
|
|
36
|
-
export type
|
|
36
|
+
export type SelectOperation<table extends AnyTable = AnyTable> = {
|
|
37
37
|
kind: 'select'
|
|
38
38
|
table: table
|
|
39
39
|
select: '*' | SelectColumn[]
|
|
@@ -50,7 +50,7 @@ export type SelectStatement<table extends AnyTable = AnyTable> = {
|
|
|
50
50
|
/**
|
|
51
51
|
* Canonical count statement shape consumed by adapters.
|
|
52
52
|
*/
|
|
53
|
-
export type
|
|
53
|
+
export type CountOperation<table extends AnyTable = AnyTable> = {
|
|
54
54
|
kind: 'count'
|
|
55
55
|
table: table
|
|
56
56
|
joins: JoinClause[]
|
|
@@ -62,7 +62,7 @@ export type CountStatement<table extends AnyTable = AnyTable> = {
|
|
|
62
62
|
/**
|
|
63
63
|
* Canonical exists statement shape consumed by adapters.
|
|
64
64
|
*/
|
|
65
|
-
export type
|
|
65
|
+
export type ExistsOperation<table extends AnyTable = AnyTable> = {
|
|
66
66
|
kind: 'exists'
|
|
67
67
|
table: table
|
|
68
68
|
joins: JoinClause[]
|
|
@@ -74,7 +74,7 @@ export type ExistsStatement<table extends AnyTable = AnyTable> = {
|
|
|
74
74
|
/**
|
|
75
75
|
* Canonical insert statement shape consumed by adapters.
|
|
76
76
|
*/
|
|
77
|
-
export type
|
|
77
|
+
export type InsertOperation<table extends AnyTable = AnyTable> = {
|
|
78
78
|
kind: 'insert'
|
|
79
79
|
table: table
|
|
80
80
|
values: Record<string, unknown>
|
|
@@ -84,7 +84,7 @@ export type InsertStatement<table extends AnyTable = AnyTable> = {
|
|
|
84
84
|
/**
|
|
85
85
|
* Canonical bulk-insert statement shape consumed by adapters.
|
|
86
86
|
*/
|
|
87
|
-
export type
|
|
87
|
+
export type InsertManyOperation<table extends AnyTable = AnyTable> = {
|
|
88
88
|
kind: 'insertMany'
|
|
89
89
|
table: table
|
|
90
90
|
values: Record<string, unknown>[]
|
|
@@ -94,7 +94,7 @@ export type InsertManyStatement<table extends AnyTable = AnyTable> = {
|
|
|
94
94
|
/**
|
|
95
95
|
* Canonical update statement shape consumed by adapters.
|
|
96
96
|
*/
|
|
97
|
-
export type
|
|
97
|
+
export type UpdateOperation<table extends AnyTable = AnyTable> = {
|
|
98
98
|
kind: 'update'
|
|
99
99
|
table: table
|
|
100
100
|
changes: Record<string, unknown>
|
|
@@ -105,7 +105,7 @@ export type UpdateStatement<table extends AnyTable = AnyTable> = {
|
|
|
105
105
|
/**
|
|
106
106
|
* Canonical delete statement shape consumed by adapters.
|
|
107
107
|
*/
|
|
108
|
-
export type
|
|
108
|
+
export type DeleteOperation<table extends AnyTable = AnyTable> = {
|
|
109
109
|
kind: 'delete'
|
|
110
110
|
table: table
|
|
111
111
|
where: Predicate[]
|
|
@@ -115,7 +115,7 @@ export type DeleteStatement<table extends AnyTable = AnyTable> = {
|
|
|
115
115
|
/**
|
|
116
116
|
* Canonical upsert statement shape consumed by adapters.
|
|
117
117
|
*/
|
|
118
|
-
export type
|
|
118
|
+
export type UpsertOperation<table extends AnyTable = AnyTable> = {
|
|
119
119
|
kind: 'upsert'
|
|
120
120
|
table: table
|
|
121
121
|
values: Record<string, unknown>
|
|
@@ -127,24 +127,427 @@ export type UpsertStatement<table extends AnyTable = AnyTable> = {
|
|
|
127
127
|
/**
|
|
128
128
|
* Raw SQL statement execution descriptor.
|
|
129
129
|
*/
|
|
130
|
-
export type
|
|
130
|
+
export type RawOperation = {
|
|
131
131
|
kind: 'raw'
|
|
132
132
|
sql: SqlStatement
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
|
-
* Union of all
|
|
136
|
+
* Union of all data-manipulation statement shapes.
|
|
137
137
|
*/
|
|
138
|
-
export type
|
|
139
|
-
|
|
|
140
|
-
|
|
|
141
|
-
|
|
|
142
|
-
|
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
138
|
+
export type DataManipulationOperation =
|
|
139
|
+
| SelectOperation
|
|
140
|
+
| CountOperation
|
|
141
|
+
| ExistsOperation
|
|
142
|
+
| InsertOperation
|
|
143
|
+
| InsertManyOperation
|
|
144
|
+
| UpdateOperation
|
|
145
|
+
| DeleteOperation
|
|
146
|
+
| UpsertOperation
|
|
147
|
+
| RawOperation
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Qualified table reference used in migration operations.
|
|
151
|
+
*/
|
|
152
|
+
export type TableRef = {
|
|
153
|
+
name: string
|
|
154
|
+
schema?: string
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Referential actions supported by foreign key constraints.
|
|
159
|
+
*/
|
|
160
|
+
export type ForeignKeyAction = 'cascade' | 'restrict' | 'set null' | 'set default' | 'no action'
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Logical column type names used by schema definitions.
|
|
164
|
+
*/
|
|
165
|
+
export type ColumnTypeName =
|
|
166
|
+
| 'varchar'
|
|
167
|
+
| 'text'
|
|
168
|
+
| 'integer'
|
|
169
|
+
| 'bigint'
|
|
170
|
+
| 'decimal'
|
|
171
|
+
| 'boolean'
|
|
172
|
+
| 'uuid'
|
|
173
|
+
| 'date'
|
|
174
|
+
| 'time'
|
|
175
|
+
| 'timestamp'
|
|
176
|
+
| 'json'
|
|
177
|
+
| 'binary'
|
|
178
|
+
| 'enum'
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Default value definition for a column.
|
|
182
|
+
*/
|
|
183
|
+
export type ColumnDefault =
|
|
184
|
+
| { kind: 'literal'; value: unknown }
|
|
185
|
+
| { kind: 'now' }
|
|
186
|
+
| { kind: 'sql'; expression: string }
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Definition for a computed or generated column.
|
|
190
|
+
*/
|
|
191
|
+
export type ColumnComputed = {
|
|
192
|
+
expression: string
|
|
193
|
+
stored: boolean
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Options for configuring identity column generation. */
|
|
197
|
+
export type IdentityOptions = {
|
|
198
|
+
always?: boolean
|
|
199
|
+
start?: number
|
|
200
|
+
increment?: number
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Foreign-key reference metadata declared on a column. */
|
|
204
|
+
export type ColumnReference = {
|
|
205
|
+
table: TableRef
|
|
206
|
+
columns: string[]
|
|
207
|
+
name: string
|
|
208
|
+
onDelete?: ForeignKeyAction
|
|
209
|
+
onUpdate?: ForeignKeyAction
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Check constraint declared on a column definition.
|
|
214
|
+
*/
|
|
215
|
+
export type ColumnCheck = {
|
|
216
|
+
expression: string
|
|
217
|
+
name: string
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Normalized column definition used in schema operations.
|
|
222
|
+
*/
|
|
223
|
+
export type ColumnDefinition = {
|
|
224
|
+
type: ColumnTypeName
|
|
225
|
+
nullable?: boolean
|
|
226
|
+
primaryKey?: boolean
|
|
227
|
+
unique?: boolean | { name?: string }
|
|
228
|
+
default?: ColumnDefault
|
|
229
|
+
computed?: ColumnComputed
|
|
230
|
+
references?: ColumnReference
|
|
231
|
+
checks?: ColumnCheck[]
|
|
232
|
+
comment?: string
|
|
233
|
+
length?: number
|
|
234
|
+
precision?: number
|
|
235
|
+
scale?: number
|
|
236
|
+
unsigned?: boolean
|
|
237
|
+
withTimezone?: boolean
|
|
238
|
+
enumValues?: string[]
|
|
239
|
+
autoIncrement?: boolean
|
|
240
|
+
identity?: IdentityOptions
|
|
241
|
+
collate?: string
|
|
242
|
+
charset?: string
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Primary key constraint definition.
|
|
247
|
+
*/
|
|
248
|
+
export type PrimaryKeyConstraint = {
|
|
249
|
+
columns: string[]
|
|
250
|
+
name: string
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Unique constraint definition.
|
|
255
|
+
*/
|
|
256
|
+
export type UniqueConstraint = {
|
|
257
|
+
columns: string[]
|
|
258
|
+
name: string
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Check constraint definition.
|
|
263
|
+
*/
|
|
264
|
+
export type CheckConstraint = {
|
|
265
|
+
expression: string
|
|
266
|
+
name: string
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Foreign key constraint definition.
|
|
271
|
+
*/
|
|
272
|
+
export type ForeignKeyConstraint = {
|
|
273
|
+
columns: string[]
|
|
274
|
+
references: {
|
|
275
|
+
table: TableRef
|
|
276
|
+
columns: string[]
|
|
277
|
+
}
|
|
278
|
+
name: string
|
|
279
|
+
onDelete?: ForeignKeyAction
|
|
280
|
+
onUpdate?: ForeignKeyAction
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Index method used when creating an index.
|
|
285
|
+
*/
|
|
286
|
+
export type IndexMethod = 'btree' | 'hash' | 'gin' | 'gist' | 'fulltext' | (string & {})
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Index definition used in schema operations.
|
|
290
|
+
*/
|
|
291
|
+
export type IndexDefinition = {
|
|
292
|
+
table: TableRef
|
|
293
|
+
name: string
|
|
294
|
+
columns: string[]
|
|
295
|
+
unique?: boolean
|
|
296
|
+
where?: string
|
|
297
|
+
using?: IndexMethod
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Operation that creates a new table.
|
|
302
|
+
*/
|
|
303
|
+
export type CreateTableOperation = {
|
|
304
|
+
kind: 'createTable'
|
|
305
|
+
table: TableRef
|
|
306
|
+
ifNotExists?: boolean
|
|
307
|
+
columns: Record<string, ColumnDefinition>
|
|
308
|
+
primaryKey?: PrimaryKeyConstraint
|
|
309
|
+
uniques?: UniqueConstraint[]
|
|
310
|
+
checks?: CheckConstraint[]
|
|
311
|
+
foreignKeys?: ForeignKeyConstraint[]
|
|
312
|
+
comment?: string
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Alter-table change that adds a column.
|
|
317
|
+
*/
|
|
318
|
+
export type AddColumnChange = {
|
|
319
|
+
kind: 'addColumn'
|
|
320
|
+
column: string
|
|
321
|
+
definition: ColumnDefinition
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Alter-table change that replaces a column definition.
|
|
326
|
+
*/
|
|
327
|
+
export type ChangeColumnChange = {
|
|
328
|
+
kind: 'changeColumn'
|
|
329
|
+
column: string
|
|
330
|
+
definition: ColumnDefinition
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Alter-table change that renames a column.
|
|
335
|
+
*/
|
|
336
|
+
export type RenameColumnChange = {
|
|
337
|
+
kind: 'renameColumn'
|
|
338
|
+
from: string
|
|
339
|
+
to: string
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Alter-table change that drops a column.
|
|
344
|
+
*/
|
|
345
|
+
export type DropColumnChange = {
|
|
346
|
+
kind: 'dropColumn'
|
|
347
|
+
column: string
|
|
348
|
+
ifExists?: boolean
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Alter-table change that adds a primary key.
|
|
353
|
+
*/
|
|
354
|
+
export type AddPrimaryKeyChange = {
|
|
355
|
+
kind: 'addPrimaryKey'
|
|
356
|
+
constraint: PrimaryKeyConstraint
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Alter-table change that drops a primary key.
|
|
361
|
+
*/
|
|
362
|
+
export type DropPrimaryKeyChange = {
|
|
363
|
+
kind: 'dropPrimaryKey'
|
|
364
|
+
name: string
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Alter-table change that adds a unique constraint.
|
|
369
|
+
*/
|
|
370
|
+
export type AddUniqueChange = {
|
|
371
|
+
kind: 'addUnique'
|
|
372
|
+
constraint: UniqueConstraint
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Alter-table change that drops a unique constraint.
|
|
377
|
+
*/
|
|
378
|
+
export type DropUniqueChange = {
|
|
379
|
+
kind: 'dropUnique'
|
|
380
|
+
name: string
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Alter-table change that adds a foreign key constraint.
|
|
385
|
+
*/
|
|
386
|
+
export type AddForeignKeyChange = {
|
|
387
|
+
kind: 'addForeignKey'
|
|
388
|
+
constraint: ForeignKeyConstraint
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Alter-table change that drops a foreign key constraint.
|
|
393
|
+
*/
|
|
394
|
+
export type DropForeignKeyChange = {
|
|
395
|
+
kind: 'dropForeignKey'
|
|
396
|
+
name: string
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Alter-table change that adds a check constraint.
|
|
401
|
+
*/
|
|
402
|
+
export type AddCheckChange = {
|
|
403
|
+
kind: 'addCheck'
|
|
404
|
+
constraint: CheckConstraint
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Alter-table change that drops a check constraint.
|
|
409
|
+
*/
|
|
410
|
+
export type DropCheckChange = {
|
|
411
|
+
kind: 'dropCheck'
|
|
412
|
+
name: string
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Alter-table change that updates a table comment.
|
|
417
|
+
*/
|
|
418
|
+
export type SetTableCommentChange = {
|
|
419
|
+
kind: 'setTableComment'
|
|
420
|
+
comment: string
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Union of supported `alterTable` changes.
|
|
425
|
+
*/
|
|
426
|
+
export type AlterTableChange =
|
|
427
|
+
| AddColumnChange
|
|
428
|
+
| ChangeColumnChange
|
|
429
|
+
| RenameColumnChange
|
|
430
|
+
| DropColumnChange
|
|
431
|
+
| AddPrimaryKeyChange
|
|
432
|
+
| DropPrimaryKeyChange
|
|
433
|
+
| AddUniqueChange
|
|
434
|
+
| DropUniqueChange
|
|
435
|
+
| AddForeignKeyChange
|
|
436
|
+
| DropForeignKeyChange
|
|
437
|
+
| AddCheckChange
|
|
438
|
+
| DropCheckChange
|
|
439
|
+
| SetTableCommentChange
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Operation that applies one or more table changes.
|
|
443
|
+
*/
|
|
444
|
+
export type AlterTableOperation = {
|
|
445
|
+
kind: 'alterTable'
|
|
446
|
+
table: TableRef
|
|
447
|
+
changes: AlterTableChange[]
|
|
448
|
+
ifExists?: boolean
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Operation that renames a table.
|
|
453
|
+
*/
|
|
454
|
+
export type RenameTableOperation = {
|
|
455
|
+
kind: 'renameTable'
|
|
456
|
+
from: TableRef
|
|
457
|
+
to: TableRef
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Operation that drops a table.
|
|
462
|
+
*/
|
|
463
|
+
export type DropTableOperation = {
|
|
464
|
+
kind: 'dropTable'
|
|
465
|
+
table: TableRef
|
|
466
|
+
ifExists?: boolean
|
|
467
|
+
cascade?: boolean
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Operation that creates an index.
|
|
472
|
+
*/
|
|
473
|
+
export type CreateIndexOperation = {
|
|
474
|
+
kind: 'createIndex'
|
|
475
|
+
index: IndexDefinition
|
|
476
|
+
ifNotExists?: boolean
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Operation that drops an index.
|
|
481
|
+
*/
|
|
482
|
+
export type DropIndexOperation = {
|
|
483
|
+
kind: 'dropIndex'
|
|
484
|
+
table: TableRef
|
|
485
|
+
name: string
|
|
486
|
+
ifExists?: boolean
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Operation that renames an index.
|
|
491
|
+
*/
|
|
492
|
+
export type RenameIndexOperation = {
|
|
493
|
+
kind: 'renameIndex'
|
|
494
|
+
table: TableRef
|
|
495
|
+
from: string
|
|
496
|
+
to: string
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Operation that adds a table-level foreign key.
|
|
501
|
+
*/
|
|
502
|
+
export type AddForeignKeyOperation = {
|
|
503
|
+
kind: 'addForeignKey'
|
|
504
|
+
table: TableRef
|
|
505
|
+
constraint: ForeignKeyConstraint
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Operation that drops a table-level foreign key.
|
|
510
|
+
*/
|
|
511
|
+
export type DropForeignKeyOperation = {
|
|
512
|
+
kind: 'dropForeignKey'
|
|
513
|
+
table: TableRef
|
|
514
|
+
name: string
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Operation that adds a table-level check constraint.
|
|
519
|
+
*/
|
|
520
|
+
export type AddCheckOperation = {
|
|
521
|
+
kind: 'addCheck'
|
|
522
|
+
table: TableRef
|
|
523
|
+
constraint: CheckConstraint
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Operation that drops a table-level check constraint.
|
|
528
|
+
*/
|
|
529
|
+
export type DropCheckOperation = {
|
|
530
|
+
kind: 'dropCheck'
|
|
531
|
+
table: TableRef
|
|
532
|
+
name: string
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Union of schema and migration operations understood by adapters.
|
|
537
|
+
*/
|
|
538
|
+
export type DataMigrationOperation =
|
|
539
|
+
| CreateTableOperation
|
|
540
|
+
| AlterTableOperation
|
|
541
|
+
| RenameTableOperation
|
|
542
|
+
| DropTableOperation
|
|
543
|
+
| CreateIndexOperation
|
|
544
|
+
| DropIndexOperation
|
|
545
|
+
| RenameIndexOperation
|
|
546
|
+
| AddForeignKeyOperation
|
|
547
|
+
| DropForeignKeyOperation
|
|
548
|
+
| AddCheckOperation
|
|
549
|
+
| DropCheckOperation
|
|
550
|
+
| RawOperation
|
|
148
551
|
|
|
149
552
|
/**
|
|
150
553
|
* Opaque transaction handle supplied by adapters.
|
|
@@ -165,20 +568,38 @@ export type TransactionOptions = {
|
|
|
165
568
|
/**
|
|
166
569
|
* Adapter execution request payload.
|
|
167
570
|
*/
|
|
168
|
-
export type
|
|
169
|
-
|
|
571
|
+
export type DataManipulationRequest = {
|
|
572
|
+
operation: DataManipulationOperation
|
|
573
|
+
transaction?: TransactionToken
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Adapter migration request payload.
|
|
578
|
+
*/
|
|
579
|
+
export type DataMigrationRequest = {
|
|
580
|
+
operation: DataMigrationOperation
|
|
170
581
|
transaction?: TransactionToken
|
|
171
582
|
}
|
|
172
583
|
|
|
173
584
|
/**
|
|
174
|
-
* Adapter
|
|
585
|
+
* Adapter data-manipulation result payload.
|
|
175
586
|
*/
|
|
176
|
-
export type
|
|
587
|
+
export type DataManipulationResult = {
|
|
177
588
|
rows?: Record<string, unknown>[]
|
|
178
589
|
affectedRows?: number
|
|
179
590
|
insertId?: unknown
|
|
180
591
|
}
|
|
181
592
|
|
|
593
|
+
/**
|
|
594
|
+
* Adapter data-migration result payload.
|
|
595
|
+
*/
|
|
596
|
+
export type DataMigrationResult = {
|
|
597
|
+
/**
|
|
598
|
+
* Number of migration operations processed by the adapter call.
|
|
599
|
+
*/
|
|
600
|
+
affectedOperations?: number
|
|
601
|
+
}
|
|
602
|
+
|
|
182
603
|
/**
|
|
183
604
|
* Declares adapter feature support.
|
|
184
605
|
*/
|
|
@@ -186,6 +607,8 @@ export type AdapterCapabilities = {
|
|
|
186
607
|
returning: boolean
|
|
187
608
|
savepoints: boolean
|
|
188
609
|
upsert: boolean
|
|
610
|
+
transactionalDdl: boolean
|
|
611
|
+
migrationLock: boolean
|
|
189
612
|
}
|
|
190
613
|
|
|
191
614
|
/**
|
|
@@ -197,13 +620,34 @@ export type AdapterCapabilityOverrides = Pretty<Partial<AdapterCapabilities>>
|
|
|
197
620
|
* Runtime contract implemented by concrete database adapters.
|
|
198
621
|
*/
|
|
199
622
|
export interface DatabaseAdapter {
|
|
623
|
+
/** Database dialect name exposed by the adapter. */
|
|
200
624
|
dialect: string
|
|
625
|
+
/** Feature flags describing the adapter's supported behaviors. */
|
|
201
626
|
capabilities: AdapterCapabilities
|
|
202
|
-
|
|
627
|
+
/** Compiles a data or migration operation into executable SQL statements. */
|
|
628
|
+
compileSql(operation: DataManipulationOperation | DataMigrationOperation): SqlStatement[]
|
|
629
|
+
/** Executes a data-manipulation request. */
|
|
630
|
+
execute(request: DataManipulationRequest): Promise<DataManipulationResult>
|
|
631
|
+
/** Executes a migration request. */
|
|
632
|
+
migrate(request: DataMigrationRequest): Promise<DataMigrationResult>
|
|
633
|
+
/** Checks whether a table exists. */
|
|
634
|
+
hasTable(table: TableRef, transaction?: TransactionToken): Promise<boolean>
|
|
635
|
+
/** Checks whether a column exists on a table. */
|
|
636
|
+
hasColumn(table: TableRef, column: string, transaction?: TransactionToken): Promise<boolean>
|
|
637
|
+
/** Starts a new database transaction. */
|
|
203
638
|
beginTransaction(options?: TransactionOptions): Promise<TransactionToken>
|
|
639
|
+
/** Commits an open transaction. */
|
|
204
640
|
commitTransaction(token: TransactionToken): Promise<void>
|
|
641
|
+
/** Rolls back an open transaction. */
|
|
205
642
|
rollbackTransaction(token: TransactionToken): Promise<void>
|
|
643
|
+
/** Creates a savepoint inside an open transaction. */
|
|
206
644
|
createSavepoint(token: TransactionToken, name: string): Promise<void>
|
|
645
|
+
/** Rolls back to a previously created savepoint. */
|
|
207
646
|
rollbackToSavepoint(token: TransactionToken, name: string): Promise<void>
|
|
647
|
+
/** Releases a previously created savepoint. */
|
|
208
648
|
releaseSavepoint(token: TransactionToken, name: string): Promise<void>
|
|
649
|
+
/** Acquires the adapter's migration lock when supported. */
|
|
650
|
+
acquireMigrationLock?(): Promise<void>
|
|
651
|
+
/** Releases the adapter's migration lock when supported. */
|
|
652
|
+
releaseMigrationLock?(): Promise<void>
|
|
209
653
|
}
|