@remix-run/data-table 0.3.0 → 0.4.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 +205 -79
- package/dist/cli.d.ts +54 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +53 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/lib/column.d.ts +1 -1
- package/dist/lib/column.d.ts.map +1 -1
- package/dist/lib/database/execution-context.d.ts +5 -5
- package/dist/lib/database/execution-context.d.ts.map +1 -1
- package/dist/lib/database/execution-context.js +1 -0
- package/dist/lib/database/helpers.js +6 -6
- package/dist/lib/database/query-execution.d.ts.map +1 -1
- package/dist/lib/database/query-execution.js +17 -17
- package/dist/lib/database/relations.js +5 -5
- package/dist/lib/database/write-lifecycle.d.ts +2 -2
- package/dist/lib/database/write-lifecycle.d.ts.map +1 -1
- package/dist/lib/database/write-lifecycle.js +5 -5
- package/dist/lib/database.d.ts +74 -59
- package/dist/lib/database.d.ts.map +1 -1
- package/dist/lib/database.js +176 -83
- package/dist/lib/{adapter.d.ts → driver.d.ts} +46 -48
- package/dist/lib/driver.d.ts.map +1 -0
- package/dist/lib/errors.d.ts +2 -2
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +4 -4
- package/dist/lib/migrations/journal-store.d.ts +6 -6
- package/dist/lib/migrations/journal-store.d.ts.map +1 -1
- package/dist/lib/migrations/journal-store.js +20 -11
- package/dist/lib/migrations/runner.d.ts +12 -19
- package/dist/lib/migrations/runner.d.ts.map +1 -1
- package/dist/lib/migrations/runner.js +151 -129
- package/dist/lib/migrations-node.d.ts +19 -1
- package/dist/lib/migrations-node.d.ts.map +1 -1
- package/dist/lib/migrations-node.js +22 -1
- package/dist/lib/migrations.d.ts +55 -20
- package/dist/lib/migrations.d.ts.map +1 -1
- package/dist/lib/operators.d.ts +1 -1
- package/dist/lib/operators.js +1 -1
- package/dist/lib/query.d.ts +1 -1
- package/dist/lib/query.d.ts.map +1 -1
- package/dist/lib/query.js +4 -4
- package/dist/lib/sql-helpers.d.ts +1 -1
- package/dist/lib/sql-helpers.d.ts.map +1 -1
- package/dist/lib/sql.d.ts +1 -1
- package/dist/lib/sql.js +1 -1
- package/dist/lib/table.d.ts +1 -1
- package/dist/lib/table.d.ts.map +1 -1
- package/dist/lib/table.js +5 -5
- package/dist/migrations/node.d.ts +1 -1
- package/dist/migrations/node.d.ts.map +1 -1
- package/dist/migrations/node.js +1 -1
- package/dist/migrations.d.ts +1 -2
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +2 -3
- package/dist/operators.js +1 -1
- package/dist/sql-helpers.js +1 -1
- package/package.json +13 -9
- package/src/cli.ts +120 -0
- package/src/index.ts +19 -20
- package/src/lib/column.ts +1 -1
- package/src/lib/database/execution-context.ts +10 -6
- package/src/lib/database/helpers.ts +1 -1
- package/src/lib/database/query-execution.ts +15 -11
- package/src/lib/database/write-lifecycle.ts +4 -4
- package/src/lib/database.ts +223 -96
- package/src/lib/{adapter.ts → driver.ts} +48 -48
- package/src/lib/errors.ts +4 -4
- package/src/lib/migrations/journal-store.ts +21 -11
- package/src/lib/migrations/runner.ts +200 -147
- package/src/lib/migrations-node.ts +23 -1
- package/src/lib/migrations.ts +58 -19
- package/src/lib/operators.ts +1 -1
- package/src/lib/query.ts +1 -1
- package/src/lib/sql-helpers.ts +1 -1
- package/src/lib/sql.ts +1 -1
- package/src/lib/table.ts +1 -1
- package/src/migrations/node.ts +1 -1
- package/src/migrations.ts +3 -4
- package/dist/lib/adapter.d.ts.map +0 -1
- /package/dist/lib/{adapter.js → driver.js} +0 -0
package/dist/lib/database.js
CHANGED
|
@@ -1,35 +1,145 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { executeOperation } from
|
|
3
|
-
import { asQueryTableInput, getPrimaryKeyWhere, getPrimaryKeyWhereFromRow, normalizeOrderByInput, resolveCreateRowWhere, toWriteResult, } from
|
|
4
|
-
import { executeQuery } from
|
|
5
|
-
import { bindQueryRuntime, query as createQuery } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { DataTableDatabaseError, DataTableQueryError } from './errors.js';
|
|
2
|
+
import { executeOperation, runInTransaction, } from './database/execution-context.js';
|
|
3
|
+
import { asQueryTableInput, getPrimaryKeyWhere, getPrimaryKeyWhereFromRow, normalizeOrderByInput, resolveCreateRowWhere, toWriteResult, } from './database/helpers.js';
|
|
4
|
+
import { executeQuery } from './database/query-execution.js';
|
|
5
|
+
import { bindQueryRuntime, query as createQuery } from './query.js';
|
|
6
|
+
import { createMigrationRunner } from './migrations/runner.js';
|
|
7
|
+
import { isSqlStatement, rawSql } from './sql.js';
|
|
8
|
+
import { getTableName } from './table.js';
|
|
9
9
|
/**
|
|
10
|
-
* High-level database runtime used to
|
|
10
|
+
* High-level database runtime used to query and manage a database.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Database dialects extend this class and provide a {@link DatabaseDriver} to the constructor.
|
|
13
|
+
* The driver owns SQL execution, transactions, and connection lifecycle while this class provides
|
|
14
|
+
* the shared query, persistence, and migration APIs.
|
|
14
15
|
*/
|
|
15
16
|
export class Database {
|
|
16
|
-
#
|
|
17
|
+
#driver;
|
|
18
|
+
#executionContext;
|
|
17
19
|
#token;
|
|
18
20
|
#now;
|
|
19
21
|
#savepointCounter;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Creates a database backed by a driver.
|
|
24
|
+
* @param driver Low-level database engine integration.
|
|
25
|
+
* @param options Database runtime options.
|
|
26
|
+
*/
|
|
27
|
+
constructor(driver, options) {
|
|
28
|
+
this.#driver = driver;
|
|
22
29
|
this.#now = options?.now ?? defaultNow;
|
|
23
30
|
this.#savepointCounter = { value: 0 };
|
|
31
|
+
let database = this;
|
|
32
|
+
this.#executionContext = {
|
|
33
|
+
get capabilities() {
|
|
34
|
+
return database.capabilities;
|
|
35
|
+
},
|
|
36
|
+
now() {
|
|
37
|
+
return database.now();
|
|
38
|
+
},
|
|
39
|
+
[executeOperation](operation) {
|
|
40
|
+
return database.#executeOperation(operation);
|
|
41
|
+
},
|
|
42
|
+
[runInTransaction](callback, transactionOptions) {
|
|
43
|
+
return database.#runInTransaction((transactionDatabase) => callback(transactionDatabase.#executionContext), transactionOptions);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
24
46
|
}
|
|
25
|
-
static
|
|
26
|
-
let database = new Database(
|
|
47
|
+
static #createInternalDatabase(driver, options, internal) {
|
|
48
|
+
let database = new Database(driver, options);
|
|
27
49
|
database.#token = internal.token;
|
|
28
50
|
database.#savepointCounter = internal.savepointCounter;
|
|
29
51
|
return database;
|
|
30
52
|
}
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
/** Stable identifier for the SQL dialect. */
|
|
54
|
+
get dialect() {
|
|
55
|
+
return this.#driver.dialect;
|
|
56
|
+
}
|
|
57
|
+
/** Immutable feature flags used by shared query and migration behavior. */
|
|
58
|
+
get capabilities() {
|
|
59
|
+
return this.#driver.capabilities;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Executes a migration or raw multi-statement SQL script.
|
|
63
|
+
* @param sql SQL script to execute.
|
|
64
|
+
* @returns A promise that resolves when execution completes.
|
|
65
|
+
*/
|
|
66
|
+
executeScript(sql) {
|
|
67
|
+
return this.#driver.executeScript(sql, this.#token);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reports whether a table exists.
|
|
71
|
+
* @param table Table to inspect.
|
|
72
|
+
* @returns A promise that resolves to `true` when the table exists.
|
|
73
|
+
*/
|
|
74
|
+
hasTable(table) {
|
|
75
|
+
return this.#driver.hasTable(table, this.#token);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reports whether a column exists on a table.
|
|
79
|
+
* @param table Table to inspect.
|
|
80
|
+
* @param column Column name to inspect.
|
|
81
|
+
* @returns A promise that resolves to `true` when the column exists.
|
|
82
|
+
*/
|
|
83
|
+
hasColumn(table, column) {
|
|
84
|
+
return this.#driver.hasColumn(table, column, this.#token);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Closes resources owned by this database.
|
|
88
|
+
* @returns A promise that resolves when owned resources have been released.
|
|
89
|
+
*/
|
|
90
|
+
async close() {
|
|
91
|
+
this.#assertLifecycleOperationAllowed('close');
|
|
92
|
+
await this.#driver.close();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Destructively recreates the configured database.
|
|
96
|
+
* @returns A promise that resolves when the database is ready for use.
|
|
97
|
+
*/
|
|
98
|
+
async wipe() {
|
|
99
|
+
this.#assertLifecycleOperationAllowed('wipe');
|
|
100
|
+
await this.#driver.wipe();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Applies or reverts migrations in order.
|
|
104
|
+
*
|
|
105
|
+
* @param migrations Migration descriptors or registry to apply.
|
|
106
|
+
* @param options Migration direction, bound, dry-run, and journal configuration.
|
|
107
|
+
* @returns The migrations applied or reverted by this run and their SQL scripts.
|
|
108
|
+
*/
|
|
109
|
+
async migrate(migrations, options) {
|
|
110
|
+
this.#assertLifecycleOperationAllowed('migrate');
|
|
111
|
+
let { direction = 'up', journalTable, ...migrateOptions } = options ?? {};
|
|
112
|
+
let runner = createMigrationRunner(this.#driver, migrations, { journalTable });
|
|
113
|
+
return direction === 'up' ? runner.up(migrateOptions) : runner.down(migrateOptions);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Reports the current state of the provided migrations.
|
|
117
|
+
*
|
|
118
|
+
* @param migrations Migration descriptors or registry to inspect.
|
|
119
|
+
* @param options Migration journal configuration.
|
|
120
|
+
* @returns Status entries for the provided migrations.
|
|
121
|
+
*/
|
|
122
|
+
async migrationStatus(migrations, options = {}) {
|
|
123
|
+
this.#assertLifecycleOperationAllowed('migrationStatus');
|
|
124
|
+
let runner = createMigrationRunner(this.#driver, migrations, options);
|
|
125
|
+
return runner.status();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Wipes the database, applies migrations, and optionally seeds data.
|
|
129
|
+
*
|
|
130
|
+
* @param options Migrations and optional seed function used to rebuild the database.
|
|
131
|
+
* @returns A promise that resolves when the database has been rebuilt.
|
|
132
|
+
*/
|
|
133
|
+
async reset(options) {
|
|
134
|
+
this.#assertLifecycleOperationAllowed('reset');
|
|
135
|
+
await this.wipe();
|
|
136
|
+
await this.migrate(options.migrations, { journalTable: options.journalTable });
|
|
137
|
+
await options.seed?.(this);
|
|
138
|
+
}
|
|
139
|
+
#assertLifecycleOperationAllowed(method) {
|
|
140
|
+
if (this.#token) {
|
|
141
|
+
throw new DataTableQueryError('Cannot call ' + method + '() from a transaction-scoped database');
|
|
142
|
+
}
|
|
33
143
|
}
|
|
34
144
|
now() {
|
|
35
145
|
return this.#now();
|
|
@@ -44,7 +154,7 @@ export class Database {
|
|
|
44
154
|
let result = await query.insert(values, { touch });
|
|
45
155
|
return toWriteResult(result);
|
|
46
156
|
}
|
|
47
|
-
if (this
|
|
157
|
+
if (this.capabilities.returning) {
|
|
48
158
|
let result = (await query.insert(values, {
|
|
49
159
|
returning: '*',
|
|
50
160
|
touch,
|
|
@@ -80,8 +190,8 @@ export class Database {
|
|
|
80
190
|
async createMany(table, values, options) {
|
|
81
191
|
let query = this.query(asQueryTableInput(table));
|
|
82
192
|
if (options?.returnRows === true) {
|
|
83
|
-
if (!this
|
|
84
|
-
throw new DataTableQueryError('createMany({ returnRows: true }) is not supported by this
|
|
193
|
+
if (!this.capabilities.returning) {
|
|
194
|
+
throw new DataTableQueryError('createMany({ returnRows: true }) is not supported by this database');
|
|
85
195
|
}
|
|
86
196
|
let result = (await query.insertMany(values, {
|
|
87
197
|
returning: '*',
|
|
@@ -144,7 +254,7 @@ export class Database {
|
|
|
144
254
|
}
|
|
145
255
|
async update(table, value, changes, options) {
|
|
146
256
|
let where = getPrimaryKeyWhere(table, value);
|
|
147
|
-
if (this
|
|
257
|
+
if (this.capabilities.returning) {
|
|
148
258
|
let updateResult = (await this.query(asQueryTableInput(table)).where(where).update(changes, {
|
|
149
259
|
touch: options?.touch,
|
|
150
260
|
returning: '*',
|
|
@@ -214,106 +324,89 @@ export class Database {
|
|
|
214
324
|
let sqlStatement = isSqlStatement(statementOrInput)
|
|
215
325
|
? statementOrInput
|
|
216
326
|
: rawSql(statementOrInput, values);
|
|
217
|
-
return this
|
|
327
|
+
return this.#executeOperation({
|
|
218
328
|
kind: 'raw',
|
|
219
329
|
sql: sqlStatement,
|
|
220
330
|
});
|
|
221
331
|
}
|
|
222
|
-
return executeQuery(this, statementOrInput);
|
|
332
|
+
return executeQuery(this.#executionContext, statementOrInput);
|
|
223
333
|
}
|
|
224
334
|
async transaction(callback, options) {
|
|
335
|
+
return this.#runInTransaction(callback, options);
|
|
336
|
+
}
|
|
337
|
+
async #runInTransaction(callback, options) {
|
|
225
338
|
if (!this.#token) {
|
|
226
|
-
let token = await this.#
|
|
227
|
-
let tx = Database
|
|
339
|
+
let token = await this.#driver.beginTransaction(options);
|
|
340
|
+
let tx = Database.#createInternalDatabase(this.#driver, { now: this.#now }, {
|
|
228
341
|
token,
|
|
229
342
|
savepointCounter: this.#savepointCounter,
|
|
230
343
|
});
|
|
344
|
+
let result;
|
|
231
345
|
try {
|
|
232
|
-
|
|
233
|
-
await this.#adapter.commitTransaction(token);
|
|
234
|
-
return result;
|
|
346
|
+
result = await callback(tx);
|
|
235
347
|
}
|
|
236
348
|
catch (error) {
|
|
237
|
-
|
|
349
|
+
try {
|
|
350
|
+
await this.#driver.rollbackTransaction(token);
|
|
351
|
+
}
|
|
352
|
+
catch (rollbackError) {
|
|
353
|
+
throw new AggregateError([error, rollbackError], 'Database transaction and rollback both failed', { cause: error });
|
|
354
|
+
}
|
|
238
355
|
throw error;
|
|
239
356
|
}
|
|
357
|
+
await this.#driver.commitTransaction(token);
|
|
358
|
+
return result;
|
|
240
359
|
}
|
|
241
|
-
if (!this
|
|
242
|
-
throw new DataTableQueryError('Nested transactions require
|
|
360
|
+
if (!this.capabilities.savepoints) {
|
|
361
|
+
throw new DataTableQueryError('Nested transactions require database savepoint support');
|
|
243
362
|
}
|
|
244
363
|
let savepointName = 'sp_' + String(this.#savepointCounter.value);
|
|
245
364
|
this.#savepointCounter.value += 1;
|
|
246
|
-
await this.#
|
|
365
|
+
await this.#driver.createSavepoint(this.#token, savepointName);
|
|
366
|
+
let result;
|
|
247
367
|
try {
|
|
248
|
-
|
|
249
|
-
await this.#adapter.releaseSavepoint(this.#token, savepointName);
|
|
250
|
-
return result;
|
|
368
|
+
result = await callback(this);
|
|
251
369
|
}
|
|
252
370
|
catch (error) {
|
|
253
|
-
|
|
254
|
-
|
|
371
|
+
let failures = [error];
|
|
372
|
+
try {
|
|
373
|
+
await this.#driver.rollbackToSavepoint(this.#token, savepointName);
|
|
374
|
+
}
|
|
375
|
+
catch (rollbackError) {
|
|
376
|
+
failures.push(rollbackError);
|
|
377
|
+
}
|
|
378
|
+
try {
|
|
379
|
+
await this.#driver.releaseSavepoint(this.#token, savepointName);
|
|
380
|
+
}
|
|
381
|
+
catch (releaseError) {
|
|
382
|
+
failures.push(releaseError);
|
|
383
|
+
}
|
|
384
|
+
if (failures.length > 1) {
|
|
385
|
+
throw new AggregateError(failures, 'Nested transaction cleanup failed', { cause: error });
|
|
386
|
+
}
|
|
255
387
|
throw error;
|
|
256
388
|
}
|
|
389
|
+
await this.#driver.releaseSavepoint(this.#token, savepointName);
|
|
390
|
+
return result;
|
|
257
391
|
}
|
|
258
|
-
async
|
|
392
|
+
async #executeOperation(operation) {
|
|
259
393
|
try {
|
|
260
|
-
return await this.#
|
|
394
|
+
return await this.#driver.execute({
|
|
261
395
|
operation,
|
|
262
396
|
transaction: this.#token,
|
|
263
397
|
});
|
|
264
398
|
}
|
|
265
399
|
catch (error) {
|
|
266
|
-
throw new
|
|
400
|
+
throw new DataTableDatabaseError('Database execution failed', {
|
|
267
401
|
cause: error,
|
|
268
402
|
metadata: {
|
|
269
|
-
dialect: this
|
|
403
|
+
dialect: this.dialect,
|
|
270
404
|
operationKind: operation.kind,
|
|
271
405
|
},
|
|
272
406
|
});
|
|
273
407
|
}
|
|
274
408
|
}
|
|
275
409
|
}
|
|
276
|
-
/**
|
|
277
|
-
* Creates a database runtime from an adapter.
|
|
278
|
-
* Thin wrapper around `new Database(adapter, options)`.
|
|
279
|
-
* @param adapter Adapter implementation responsible for SQL execution.
|
|
280
|
-
* @param options Optional runtime options.
|
|
281
|
-
* @param options.now Clock function used for auto-managed timestamps.
|
|
282
|
-
* @returns A {@link Database} API instance.
|
|
283
|
-
* @example
|
|
284
|
-
* ```ts
|
|
285
|
-
* import { column as c, createDatabase, table } from 'remix/data-table'
|
|
286
|
-
*
|
|
287
|
-
* let users = table({
|
|
288
|
-
* name: 'users',
|
|
289
|
-
* columns: {
|
|
290
|
-
* id: c.integer(),
|
|
291
|
-
* email: c.varchar(255),
|
|
292
|
-
* },
|
|
293
|
-
* })
|
|
294
|
-
*
|
|
295
|
-
* let db = createDatabase(adapter)
|
|
296
|
-
* let rows = await db.query(users).where({ id: 1 }).all()
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
export function createDatabase(adapter, options) {
|
|
300
|
-
return new Database(adapter, options);
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Creates a database runtime bound to an existing adapter transaction token.
|
|
304
|
-
* This is an internal helper used by the migration runner.
|
|
305
|
-
* @param adapter Adapter implementation responsible for SQL execution.
|
|
306
|
-
* @param token Active adapter transaction token.
|
|
307
|
-
* @param options Optional runtime options.
|
|
308
|
-
* @param options.now Clock function used for auto-managed timestamps.
|
|
309
|
-
* @returns A {@link Database} API instance bound to the provided transaction.
|
|
310
|
-
*/
|
|
311
|
-
export function createDatabaseWithTransaction(adapter, token, options) {
|
|
312
|
-
return Database[createInternalDatabase](adapter, options, {
|
|
313
|
-
token,
|
|
314
|
-
savepointCounter: { value: 0 },
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
410
|
function defaultNow() {
|
|
318
411
|
return new Date();
|
|
319
412
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { AnyTable, OrderByClause } from './table.ts';
|
|
2
2
|
import type { Predicate } from './operators.ts';
|
|
3
3
|
import type { SqlStatement } from './sql.ts';
|
|
4
|
-
import type { Pretty } from './types.ts';
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* SQL join kinds supported by database drivers.
|
|
7
6
|
*/
|
|
8
7
|
export type JoinType = 'inner' | 'left' | 'right';
|
|
9
8
|
/**
|
|
@@ -26,7 +25,7 @@ export type SelectColumn = {
|
|
|
26
25
|
*/
|
|
27
26
|
export type ReturningSelection = '*' | string[];
|
|
28
27
|
/**
|
|
29
|
-
* Canonical select statement shape consumed by
|
|
28
|
+
* Canonical select statement shape consumed by drivers.
|
|
30
29
|
*/
|
|
31
30
|
export type SelectOperation<table extends AnyTable = AnyTable> = {
|
|
32
31
|
kind: 'select';
|
|
@@ -42,7 +41,7 @@ export type SelectOperation<table extends AnyTable = AnyTable> = {
|
|
|
42
41
|
offset?: number;
|
|
43
42
|
};
|
|
44
43
|
/**
|
|
45
|
-
* Canonical count statement shape consumed by
|
|
44
|
+
* Canonical count statement shape consumed by drivers.
|
|
46
45
|
*/
|
|
47
46
|
export type CountOperation<table extends AnyTable = AnyTable> = {
|
|
48
47
|
kind: 'count';
|
|
@@ -53,7 +52,7 @@ export type CountOperation<table extends AnyTable = AnyTable> = {
|
|
|
53
52
|
having: Predicate[];
|
|
54
53
|
};
|
|
55
54
|
/**
|
|
56
|
-
* Canonical exists statement shape consumed by
|
|
55
|
+
* Canonical exists statement shape consumed by drivers.
|
|
57
56
|
*/
|
|
58
57
|
export type ExistsOperation<table extends AnyTable = AnyTable> = {
|
|
59
58
|
kind: 'exists';
|
|
@@ -64,7 +63,7 @@ export type ExistsOperation<table extends AnyTable = AnyTable> = {
|
|
|
64
63
|
having: Predicate[];
|
|
65
64
|
};
|
|
66
65
|
/**
|
|
67
|
-
* Canonical insert statement shape consumed by
|
|
66
|
+
* Canonical insert statement shape consumed by drivers.
|
|
68
67
|
*/
|
|
69
68
|
export type InsertOperation<table extends AnyTable = AnyTable> = {
|
|
70
69
|
kind: 'insert';
|
|
@@ -73,7 +72,7 @@ export type InsertOperation<table extends AnyTable = AnyTable> = {
|
|
|
73
72
|
returning?: ReturningSelection;
|
|
74
73
|
};
|
|
75
74
|
/**
|
|
76
|
-
* Canonical bulk-insert statement shape consumed by
|
|
75
|
+
* Canonical bulk-insert statement shape consumed by drivers.
|
|
77
76
|
*/
|
|
78
77
|
export type InsertManyOperation<table extends AnyTable = AnyTable> = {
|
|
79
78
|
kind: 'insertMany';
|
|
@@ -82,7 +81,7 @@ export type InsertManyOperation<table extends AnyTable = AnyTable> = {
|
|
|
82
81
|
returning?: ReturningSelection;
|
|
83
82
|
};
|
|
84
83
|
/**
|
|
85
|
-
* Canonical update statement shape consumed by
|
|
84
|
+
* Canonical update statement shape consumed by drivers.
|
|
86
85
|
*/
|
|
87
86
|
export type UpdateOperation<table extends AnyTable = AnyTable> = {
|
|
88
87
|
kind: 'update';
|
|
@@ -92,7 +91,7 @@ export type UpdateOperation<table extends AnyTable = AnyTable> = {
|
|
|
92
91
|
returning?: ReturningSelection;
|
|
93
92
|
};
|
|
94
93
|
/**
|
|
95
|
-
* Canonical delete statement shape consumed by
|
|
94
|
+
* Canonical delete statement shape consumed by drivers.
|
|
96
95
|
*/
|
|
97
96
|
export type DeleteOperation<table extends AnyTable = AnyTable> = {
|
|
98
97
|
kind: 'delete';
|
|
@@ -101,7 +100,7 @@ export type DeleteOperation<table extends AnyTable = AnyTable> = {
|
|
|
101
100
|
returning?: ReturningSelection;
|
|
102
101
|
};
|
|
103
102
|
/**
|
|
104
|
-
* Canonical upsert statement shape consumed by
|
|
103
|
+
* Canonical upsert statement shape consumed by drivers.
|
|
105
104
|
*/
|
|
106
105
|
export type UpsertOperation<table extends AnyTable = AnyTable> = {
|
|
107
106
|
kind: 'upsert';
|
|
@@ -204,28 +203,28 @@ export type ColumnDefinition = {
|
|
|
204
203
|
charset?: string;
|
|
205
204
|
};
|
|
206
205
|
/**
|
|
207
|
-
* Opaque transaction handle supplied by
|
|
206
|
+
* Opaque transaction handle supplied by database drivers.
|
|
208
207
|
*/
|
|
209
208
|
export type TransactionToken = {
|
|
210
209
|
id: string;
|
|
211
210
|
metadata?: Record<string, unknown>;
|
|
212
211
|
};
|
|
213
212
|
/**
|
|
214
|
-
* Transaction hints that
|
|
213
|
+
* Transaction hints that database drivers may apply when supported by the dialect.
|
|
215
214
|
*/
|
|
216
215
|
export type TransactionOptions = {
|
|
217
216
|
isolationLevel?: 'read uncommitted' | 'read committed' | 'repeatable read' | 'serializable';
|
|
218
217
|
readOnly?: boolean;
|
|
219
218
|
};
|
|
220
219
|
/**
|
|
221
|
-
*
|
|
220
|
+
* Database driver execution request payload.
|
|
222
221
|
*/
|
|
223
222
|
export type DataManipulationRequest = {
|
|
224
223
|
operation: DataManipulationOperation;
|
|
225
224
|
transaction?: TransactionToken;
|
|
226
225
|
};
|
|
227
226
|
/**
|
|
228
|
-
*
|
|
227
|
+
* Database data-manipulation result payload.
|
|
229
228
|
*/
|
|
230
229
|
export type DataManipulationResult = {
|
|
231
230
|
rows?: Record<string, unknown>[];
|
|
@@ -233,57 +232,56 @@ export type DataManipulationResult = {
|
|
|
233
232
|
insertId?: unknown;
|
|
234
233
|
};
|
|
235
234
|
/**
|
|
236
|
-
* Declares
|
|
235
|
+
* Declares database feature support.
|
|
237
236
|
*/
|
|
238
|
-
export type
|
|
239
|
-
returning: boolean;
|
|
240
|
-
savepoints: boolean;
|
|
241
|
-
upsert: boolean;
|
|
242
|
-
transactionalDdl: boolean;
|
|
243
|
-
migrationLock: boolean;
|
|
237
|
+
export type DatabaseCapabilities = {
|
|
238
|
+
readonly returning: boolean;
|
|
239
|
+
readonly savepoints: boolean;
|
|
240
|
+
readonly upsert: boolean;
|
|
241
|
+
readonly transactionalDdl: boolean;
|
|
242
|
+
readonly migrationLock: boolean;
|
|
244
243
|
};
|
|
245
244
|
/**
|
|
246
|
-
*
|
|
245
|
+
* Low-level contract that connects a `Database` to a database engine.
|
|
247
246
|
*/
|
|
248
|
-
export
|
|
249
|
-
/**
|
|
250
|
-
|
|
251
|
-
*/
|
|
252
|
-
|
|
253
|
-
/** Database dialect name exposed by the adapter. */
|
|
254
|
-
dialect: string;
|
|
255
|
-
/** Feature flags describing the adapter's supported behaviors. */
|
|
256
|
-
capabilities: AdapterCapabilities;
|
|
257
|
-
/** Compiles a data-manipulation operation into executable SQL statements. */
|
|
258
|
-
compileSql(operation: DataManipulationOperation): SqlStatement[];
|
|
247
|
+
export interface DatabaseDriver<dialect extends string = string> {
|
|
248
|
+
/** Stable identifier for the SQL dialect. */
|
|
249
|
+
readonly dialect: dialect;
|
|
250
|
+
/** Immutable feature flags used by shared query and migration behavior. */
|
|
251
|
+
readonly capabilities: DatabaseCapabilities;
|
|
259
252
|
/** Executes a data-manipulation request. */
|
|
260
253
|
execute(request: DataManipulationRequest): Promise<DataManipulationResult>;
|
|
261
|
-
/**
|
|
262
|
-
* Executes a raw SQL script that may contain multiple statements.
|
|
263
|
-
*
|
|
264
|
-
* Drivers must be configured to accept multi-statement scripts where required
|
|
265
|
-
* (for example, mysql2 needs `multipleStatements: true`).
|
|
266
|
-
*/
|
|
254
|
+
/** Executes a raw SQL script that may contain multiple statements. */
|
|
267
255
|
executeScript(sql: string, transaction?: TransactionToken): Promise<void>;
|
|
268
|
-
/** Checks whether a table exists. */
|
|
269
|
-
hasTable(table: TableRef, transaction?: TransactionToken): Promise<boolean>;
|
|
270
|
-
/** Checks whether a column exists on a table. */
|
|
271
|
-
hasColumn(table: TableRef, column: string, transaction?: TransactionToken): Promise<boolean>;
|
|
272
256
|
/** Starts a new database transaction. */
|
|
273
257
|
beginTransaction(options?: TransactionOptions): Promise<TransactionToken>;
|
|
274
258
|
/** Commits an open transaction. */
|
|
275
259
|
commitTransaction(token: TransactionToken): Promise<void>;
|
|
276
260
|
/** Rolls back an open transaction. */
|
|
277
261
|
rollbackTransaction(token: TransactionToken): Promise<void>;
|
|
262
|
+
/** Checks whether a table exists. */
|
|
263
|
+
hasTable(table: TableRef, transaction?: TransactionToken): Promise<boolean>;
|
|
264
|
+
/** Checks whether a column exists on a table. */
|
|
265
|
+
hasColumn(table: TableRef, column: string, transaction?: TransactionToken): Promise<boolean>;
|
|
278
266
|
/** Creates a savepoint inside an open transaction. */
|
|
279
267
|
createSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
280
268
|
/** Rolls back to a previously created savepoint. */
|
|
281
269
|
rollbackToSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
282
270
|
/** Releases a previously created savepoint. */
|
|
283
271
|
releaseSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
284
|
-
/**
|
|
285
|
-
|
|
286
|
-
/** Releases the
|
|
287
|
-
|
|
272
|
+
/** Destructively recreates the configured database. */
|
|
273
|
+
wipe(): Promise<void>;
|
|
274
|
+
/** Releases connection handles owned by the driver. Must be safe to call repeatedly. */
|
|
275
|
+
close(): void | Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Runs migration work while holding a driver-specific lock.
|
|
278
|
+
*
|
|
279
|
+
* The callback receives a driver bound to the connection that owns the lock. Drivers must
|
|
280
|
+
* release the lock when the callback rejects as well as when it resolves.
|
|
281
|
+
* @param name Logical migration lock name.
|
|
282
|
+
* @param run Migration work to run with the connection-bound driver.
|
|
283
|
+
* @returns The callback result.
|
|
284
|
+
*/
|
|
285
|
+
withMigrationLock?<result>(name: string, run: (driver: DatabaseDriver<dialect>) => Promise<result>): Promise<result>;
|
|
288
286
|
}
|
|
289
|
-
//# sourceMappingURL=
|
|
287
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/lib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O,CAAC,IAAI,CAAC,CAAA;IACrE,oDAAoD;IACpD,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzE,+CAA+C;IAC/C,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtE,uDAAuD;IACvD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACrB,wFAAwF;IACxF,KAAK,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B;;;;;;;;OAQG;IACH,iBAAiB,CAAC,CAAC,MAAM,EACvB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,GACxD,OAAO,CAAC,MAAM,CAAC,CAAA;CACnB"}
|
package/dist/lib/errors.d.ts
CHANGED
|
@@ -39,9 +39,9 @@ export declare class DataTableQueryError extends DataTableError {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* Thrown when
|
|
42
|
+
* Thrown when database execution fails.
|
|
43
43
|
*/
|
|
44
|
-
export declare class
|
|
44
|
+
export declare class DataTableDatabaseError extends DataTableError {
|
|
45
45
|
constructor(message: string, options?: {
|
|
46
46
|
cause?: unknown;
|
|
47
47
|
metadata?: Record<string, unknown>;
|
package/dist/lib/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;I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qBAAa,wBAAyB,SAAQ,cAAc;IAC1D;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IAE9B,YACE,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAA;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KACnC,EAUF;CACF;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,YACE,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAA;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KACnC,EASF;CACF;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,cAAc;IACxD,YACE,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAA;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KACnC,EASF;CACF;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,cAAc;IAC1D,YACE,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAA;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KACnC,EASF;CACF"}
|
package/dist/lib/errors.js
CHANGED
|
@@ -49,16 +49,16 @@ export class DataTableQueryError extends DataTableError {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Thrown when
|
|
52
|
+
* Thrown when database execution fails.
|
|
53
53
|
*/
|
|
54
|
-
export class
|
|
54
|
+
export class DataTableDatabaseError extends DataTableError {
|
|
55
55
|
constructor(message, options) {
|
|
56
56
|
super(message, {
|
|
57
|
-
code: '
|
|
57
|
+
code: 'DATA_TABLE_DATABASE_ERROR',
|
|
58
58
|
cause: options?.cause,
|
|
59
59
|
metadata: options?.metadata,
|
|
60
60
|
});
|
|
61
|
-
this.name = '
|
|
61
|
+
this.name = 'DataTableDatabaseError';
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DatabaseDriver, TransactionToken } from '../driver.ts';
|
|
2
2
|
import type { MigrationDescriptor, MigrationJournalRow } from '../migrations.ts';
|
|
3
3
|
export declare function computeChecksum(migration: MigrationDescriptor): Promise<string>;
|
|
4
|
-
export declare function ensureMigrationJournal(
|
|
5
|
-
export declare function hasMigrationJournal(
|
|
6
|
-
export declare function loadJournalRows(
|
|
7
|
-
export declare function insertJournalRow(
|
|
4
|
+
export declare function ensureMigrationJournal(driver: DatabaseDriver, tableName: string): Promise<void>;
|
|
5
|
+
export declare function hasMigrationJournal(driver: DatabaseDriver, tableName: string): Promise<boolean>;
|
|
6
|
+
export declare function loadJournalRows(driver: DatabaseDriver, tableName: string): Promise<MigrationJournalRow[]>;
|
|
7
|
+
export declare function insertJournalRow(driver: DatabaseDriver, tableName: string, row: {
|
|
8
8
|
id: string;
|
|
9
9
|
name: string;
|
|
10
10
|
checksum: string;
|
|
11
11
|
batch: number;
|
|
12
12
|
}, transaction?: TransactionToken): Promise<void>;
|
|
13
|
-
export declare function deleteJournalRow(
|
|
13
|
+
export declare function deleteJournalRow(driver: DatabaseDriver, tableName: string, id: string, transaction?: TransactionToken): Promise<void>;
|
|
14
14
|
export declare function getBatch(rows: MigrationJournalRow[]): number;
|
|
15
15
|
//# sourceMappingURL=journal-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"journal-store.d.ts","sourceRoot":"","sources":["../../../src/lib/migrations/journal-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"journal-store.d.ts","sourceRoot":"","sources":["../../../src/lib/migrations/journal-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAEhF,wBAAsB,eAAe,CAAC,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAGrF;AAYD,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAYf;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CAuBlB;AAED,wBAAsB,eAAe,CACnC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAmBhC;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE;IACH,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;CACd,EACD,WAAW,CAAC,EAAE,gBAAgB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAaf;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,WAAW,CAAC,EAAE,gBAAgB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAQf;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAO5D"}
|