@noldova/context.data.sql 0.0.0-stage → 0.0.6
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/LICENSE +21 -0
- package/README.md +51 -2
- package/api/index.d.ts +664 -0
- package/api/index.js +31 -0
- package/api/index.js.map +1 -0
- package/enums/column-type.js +13 -0
- package/enums/column-type.js.map +1 -0
- package/models/operations/create-index-operation.js +19 -0
- package/models/operations/create-index-operation.js.map +1 -0
- package/models/operations/create-table-operation.js +19 -0
- package/models/operations/create-table-operation.js.map +1 -0
- package/models/operations/schema-operation.js +10 -0
- package/models/operations/schema-operation.js.map +1 -0
- package/models/operations/sql-statement-operation.js +22 -0
- package/models/operations/sql-statement-operation.js.map +1 -0
- package/models/schema/column-builder.js +25 -0
- package/models/schema/column-builder.js.map +1 -0
- package/models/schema/column.js +21 -0
- package/models/schema/column.js.map +1 -0
- package/models/schema/columns-builder.js +21 -0
- package/models/schema/columns-builder.js.map +1 -0
- package/models/schema/constraints-builder.js +29 -0
- package/models/schema/constraints-builder.js.map +1 -0
- package/models/schema/foreign-key.js +23 -0
- package/models/schema/foreign-key.js.map +1 -0
- package/models/schema/migration-builder.js +45 -0
- package/models/schema/migration-builder.js.map +1 -0
- package/models/schema/primary-key.js +18 -0
- package/models/schema/primary-key.js.map +1 -0
- package/models/schema/table.js +25 -0
- package/models/schema/table.js.map +1 -0
- package/models/sql-connection.js +46 -0
- package/models/sql-connection.js.map +1 -0
- package/models/sql-migration.js +14 -0
- package/models/sql-migration.js.map +1 -0
- package/models/sql-query.js +22 -0
- package/models/sql-query.js.map +1 -0
- package/models/sql-session.js +10 -0
- package/models/sql-session.js.map +1 -0
- package/models/sql-transaction.js +36 -0
- package/models/sql-transaction.js.map +1 -0
- package/package.json +25 -4
- package/resources.js +58 -0
- package/resources.js.map +1 -0
- package/services/sql-change-feed.js +54 -0
- package/services/sql-change-feed.js.map +1 -0
- package/services/sql-dialect.js +49 -0
- package/services/sql-dialect.js.map +1 -0
- package/services/sql-migration-history.js +32 -0
- package/services/sql-migration-history.js.map +1 -0
- package/services/sql-migrator.js +37 -0
- package/services/sql-migrator.js.map +1 -0
- package/services/sql-provider.js +19 -0
- package/services/sql-provider.js.map +1 -0
- package/types/column-selector.js +9 -0
- package/types/column-selector.js.map +1 -0
package/api/index.d.ts
ADDED
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { NameofSelector } from "@noldova/context.core";
|
|
10
|
+
import { type Change, ChangeFeed, type ChangeOperation, Connection, DataProvider, type DataRecord, type DataSource, type DataValue, type Index, Migration, MigrationHistory, Migrator, Transaction } from "@noldova/context.data";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The storage classes a migration may declare for a column; the dialect spells
|
|
14
|
+
* them for its database.
|
|
15
|
+
*/
|
|
16
|
+
export declare enum ColumnType {
|
|
17
|
+
/**
|
|
18
|
+
* Text; also the class for JSON documents and ISO 8601 timestamps.
|
|
19
|
+
*/
|
|
20
|
+
Text = "Text",
|
|
21
|
+
/**
|
|
22
|
+
* An integer.
|
|
23
|
+
*/
|
|
24
|
+
Integer = "Integer"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Names a column after a property of the model the table stores, as a
|
|
29
|
+
* `nameof` selector: `t => t.conversationId`. The property's name is the
|
|
30
|
+
* column's name.
|
|
31
|
+
*/
|
|
32
|
+
export declare type ColumnSelector<TModel> = (t: NameofSelector<TModel>) => keyof TModel & string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A SQL statement with `?` placeholders and the values bound to them, in
|
|
36
|
+
* order. Renders as its text.
|
|
37
|
+
*/
|
|
38
|
+
export declare class SqlQuery {
|
|
39
|
+
/**
|
|
40
|
+
* The statement text.
|
|
41
|
+
*/
|
|
42
|
+
public readonly text: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The bound values, in placeholder order; a copy.
|
|
46
|
+
*/
|
|
47
|
+
public readonly parameters: readonly DataValue[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Initializes the query. Blank text throws `ArgumentException`.
|
|
51
|
+
*/
|
|
52
|
+
public constructor(text: string, parameters?: readonly DataValue[]);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns the statement text.
|
|
56
|
+
*/
|
|
57
|
+
public toString(): string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* One column of a table as a migration declares it: a name, a storage class,
|
|
62
|
+
* and whether `NULL` is allowed. Keys are constraints of the table, not
|
|
63
|
+
* properties of the column.
|
|
64
|
+
*/
|
|
65
|
+
export declare class Column {
|
|
66
|
+
/**
|
|
67
|
+
* The column's name.
|
|
68
|
+
*/
|
|
69
|
+
public readonly name: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The storage class.
|
|
73
|
+
*/
|
|
74
|
+
public readonly type: ColumnType;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* True when `NULL` is allowed; otherwise the column is `NOT NULL`.
|
|
78
|
+
*/
|
|
79
|
+
public readonly isNullable: boolean;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Initializes the column. A blank name throws `ArgumentException`.
|
|
83
|
+
*/
|
|
84
|
+
public constructor(name: string, type: ColumnType, isNullable: boolean);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The primary key of a table: one column or several, in order.
|
|
89
|
+
*/
|
|
90
|
+
export declare class PrimaryKey {
|
|
91
|
+
/**
|
|
92
|
+
* The key columns, in order; a copy.
|
|
93
|
+
*/
|
|
94
|
+
public readonly columns: readonly string[];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Initializes the key. No columns throws `ArgumentException`.
|
|
98
|
+
*/
|
|
99
|
+
public constructor(columns: readonly string[]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* A reference from a column of a table to a column of a principal table.
|
|
104
|
+
*/
|
|
105
|
+
export declare class ForeignKey {
|
|
106
|
+
/**
|
|
107
|
+
* The referencing column.
|
|
108
|
+
*/
|
|
109
|
+
public readonly column: string;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The referenced table.
|
|
113
|
+
*/
|
|
114
|
+
public readonly principalTable: string;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The referenced column.
|
|
118
|
+
*/
|
|
119
|
+
public readonly principalColumn: string;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Initializes the reference. A blank column, table, or principal column
|
|
123
|
+
* throws `ArgumentException`.
|
|
124
|
+
*/
|
|
125
|
+
public constructor(column: string, principalTable: string, principalColumn: string);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* One table as a migration declares it: a name, its columns in order, its
|
|
130
|
+
* primary key when it has one, and its foreign keys.
|
|
131
|
+
*/
|
|
132
|
+
export declare class Table {
|
|
133
|
+
/**
|
|
134
|
+
* The table's name.
|
|
135
|
+
*/
|
|
136
|
+
public readonly name: string;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The columns in declaration order; a copy.
|
|
140
|
+
*/
|
|
141
|
+
public readonly columns: readonly Column[];
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The primary key, or `null` for a table without one.
|
|
145
|
+
*/
|
|
146
|
+
public readonly primaryKey: PrimaryKey | null;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The foreign keys in declaration order; a copy.
|
|
150
|
+
*/
|
|
151
|
+
public readonly foreignKeys: readonly ForeignKey[];
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Initializes the table. A blank name or no columns throws
|
|
155
|
+
* `ArgumentException`.
|
|
156
|
+
*/
|
|
157
|
+
public constructor(name: string, columns: readonly Column[], primaryKey: PrimaryKey | null, foreignKeys: readonly ForeignKey[]);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* One step of a migration, rendered to a statement by a dialect.
|
|
162
|
+
*/
|
|
163
|
+
export declare abstract class SchemaOperation {
|
|
164
|
+
/**
|
|
165
|
+
* Renders the statement in the dialect.
|
|
166
|
+
*/
|
|
167
|
+
public abstract render(dialect: SqlDialect): string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Creates a table.
|
|
172
|
+
*/
|
|
173
|
+
export declare class CreateTableOperation extends SchemaOperation {
|
|
174
|
+
/**
|
|
175
|
+
* The table to create.
|
|
176
|
+
*/
|
|
177
|
+
public readonly table: Table;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Initializes the operation.
|
|
181
|
+
*/
|
|
182
|
+
public constructor(table: Table);
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Renders the `CREATE TABLE` statement.
|
|
186
|
+
*/
|
|
187
|
+
public override render(dialect: SqlDialect): string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Creates an index.
|
|
192
|
+
*/
|
|
193
|
+
export declare class CreateIndexOperation extends SchemaOperation {
|
|
194
|
+
/**
|
|
195
|
+
* The index to create.
|
|
196
|
+
*/
|
|
197
|
+
public readonly index: Index;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Initializes the operation.
|
|
201
|
+
*/
|
|
202
|
+
public constructor(index: Index);
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Renders the `CREATE INDEX` or `CREATE UNIQUE INDEX` statement.
|
|
206
|
+
*/
|
|
207
|
+
public override render(dialect: SqlDialect): string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Runs one SQL statement as written, such as a data change that a schema
|
|
212
|
+
* operation can't express. The statement is the
|
|
213
|
+
* migration's own and is never built from input.
|
|
214
|
+
*/
|
|
215
|
+
export declare class SqlStatementOperation extends SchemaOperation {
|
|
216
|
+
/**
|
|
217
|
+
* The statement to run.
|
|
218
|
+
*/
|
|
219
|
+
public readonly statement: string;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Initializes the operation. A blank statement throws `ArgumentException`.
|
|
223
|
+
*/
|
|
224
|
+
public constructor(statement: string);
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Returns the statement unchanged, in any dialect.
|
|
228
|
+
*/
|
|
229
|
+
public override render(): string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* How one database spells SQL. The shared rendering of tables, constraints,
|
|
234
|
+
* indexes, and columns lives here, with every identifier quoted, so a
|
|
235
|
+
* mixed-case name such as `entityId` keeps its case in every database;
|
|
236
|
+
* providers supply the parts that differ.
|
|
237
|
+
*/
|
|
238
|
+
export declare abstract class SqlDialect {
|
|
239
|
+
/**
|
|
240
|
+
* Spells the statement that begins a transaction, such as `BEGIN`; a
|
|
241
|
+
* database that would take its write lock only at the first write begins
|
|
242
|
+
* with the form that takes it at once, so concurrent writers wait at the
|
|
243
|
+
* start rather than fail midway.
|
|
244
|
+
*/
|
|
245
|
+
public abstract formatBeginTransaction(): string;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Spells a column's storage class, such as `TEXT`.
|
|
249
|
+
*/
|
|
250
|
+
public abstract formatColumnType(type: ColumnType): string;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Spells the type and constraints of an integer primary key the database
|
|
254
|
+
* generates, such as `INTEGER PRIMARY KEY AUTOINCREMENT`.
|
|
255
|
+
*/
|
|
256
|
+
public abstract formatIdentityColumnType(): string;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Returns the statements that lock a resource, such as `__migrations`,
|
|
260
|
+
* until the transaction they run in ends; none where the database's own
|
|
261
|
+
* write lock already serializes the writers.
|
|
262
|
+
*/
|
|
263
|
+
public abstract formatLock(resource: string): readonly string[];
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Quotes an identifier with double quotes, doubling any it contains.
|
|
267
|
+
*/
|
|
268
|
+
public quoteIdentifier(name: string): string;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Renders `CREATE TABLE` with every column definition, then the primary
|
|
272
|
+
* key and the foreign keys as table constraints.
|
|
273
|
+
*/
|
|
274
|
+
public renderCreateTable(table: Table): string;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Renders `CREATE INDEX` or `CREATE UNIQUE INDEX` over the index's fields.
|
|
278
|
+
*/
|
|
279
|
+
public renderCreateIndex(index: Index): string;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Renders one column definition, such as `"id" TEXT NOT NULL`.
|
|
283
|
+
*/
|
|
284
|
+
public renderColumn(column: Column): string;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Renders the constraint `PRIMARY KEY ("columns")`.
|
|
288
|
+
*/
|
|
289
|
+
public renderPrimaryKey(primaryKey: PrimaryKey): string;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Renders the constraint `FOREIGN KEY ("column") REFERENCES "table" ("column")`.
|
|
293
|
+
*/
|
|
294
|
+
public renderForeignKey(foreignKey: ForeignKey): string;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* One database session's statements, as a provider runs them: no turns and
|
|
299
|
+
* no transaction of its own. A `SqlConnection` runs them in its turn and a
|
|
300
|
+
* `SqlTransaction` inside its own; nothing else calls them. Queries write
|
|
301
|
+
* their parameters as `?`, and a provider whose database spells them
|
|
302
|
+
* otherwise converts them.
|
|
303
|
+
*/
|
|
304
|
+
export declare abstract class SqlSession {
|
|
305
|
+
/**
|
|
306
|
+
* True until the session is closed.
|
|
307
|
+
*/
|
|
308
|
+
public abstract get isOpen(): boolean;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Runs a query that returns no rows and returns the number of rows it
|
|
312
|
+
* changed.
|
|
313
|
+
*/
|
|
314
|
+
public abstract executeAsync(query: SqlQuery): Promise<number>;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Runs an `INSERT` into a table with a generated integer key and returns
|
|
318
|
+
* the key the database assigned.
|
|
319
|
+
*/
|
|
320
|
+
public abstract insertAsync(query: SqlQuery): Promise<number>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Runs a query and returns its rows as records.
|
|
324
|
+
*/
|
|
325
|
+
public abstract queryAsync(query: SqlQuery): Promise<readonly DataRecord[]>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Closes the session; a second call does nothing.
|
|
329
|
+
*/
|
|
330
|
+
public abstract closeAsync(): Promise<void>;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* A transaction over a SQL session: begun by its connection, `COMMIT` or
|
|
335
|
+
* `ROLLBACK` on completion. Inside the action it was given to, every
|
|
336
|
+
* statement runs through it.
|
|
337
|
+
*/
|
|
338
|
+
export declare class SqlTransaction extends Transaction {
|
|
339
|
+
/**
|
|
340
|
+
* Initializes the transaction over a session its connection has already
|
|
341
|
+
* begun it on.
|
|
342
|
+
*/
|
|
343
|
+
public constructor(session: SqlSession);
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Runs a query that returns no rows in the transaction and returns the
|
|
347
|
+
* number of rows it changed. A completed transaction rejects with
|
|
348
|
+
* `DataException`.
|
|
349
|
+
*/
|
|
350
|
+
public executeAsync(query: SqlQuery): Promise<number>;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Runs an `INSERT` in the transaction and returns the generated key. A
|
|
354
|
+
* completed transaction rejects with `DataException`.
|
|
355
|
+
*/
|
|
356
|
+
public insertAsync(query: SqlQuery): Promise<number>;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Runs a query in the transaction and returns its rows as records. A
|
|
360
|
+
* completed transaction rejects with `DataException`.
|
|
361
|
+
*/
|
|
362
|
+
public queryAsync(query: SqlQuery): Promise<readonly DataRecord[]>;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Executes `COMMIT`.
|
|
366
|
+
*/
|
|
367
|
+
protected override commitCoreAsync(): Promise<void>;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Executes `ROLLBACK`.
|
|
371
|
+
*/
|
|
372
|
+
protected override rollbackCoreAsync(): Promise<void>;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* A connection to a SQL database over one session: runs statements in its
|
|
377
|
+
* turn and begins SQL transactions. Providers supply the session and the
|
|
378
|
+
* dialect.
|
|
379
|
+
*/
|
|
380
|
+
export declare abstract class SqlConnection extends Connection<SqlTransaction> {
|
|
381
|
+
/**
|
|
382
|
+
* Initializes the connection over its session.
|
|
383
|
+
*/
|
|
384
|
+
protected constructor(dataSource: DataSource, session: SqlSession);
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The dialect of the database.
|
|
388
|
+
*/
|
|
389
|
+
public abstract get dialect(): SqlDialect;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* True until the session is closed.
|
|
393
|
+
*/
|
|
394
|
+
public override get isOpen(): boolean;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Runs a query that returns no rows, in the connection's turn, and returns
|
|
398
|
+
* the number of rows it changed. A closed connection rejects with
|
|
399
|
+
* `DataException`.
|
|
400
|
+
*
|
|
401
|
+
* Never call the connection inside a transaction's action: use the
|
|
402
|
+
* transaction's own statements. A call on the connection waits for its turn,
|
|
403
|
+
* which comes only after the action ends, so it never settles.
|
|
404
|
+
*/
|
|
405
|
+
public executeAsync(query: SqlQuery): Promise<number>;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Runs an `INSERT`, in the connection's turn, and returns the key the
|
|
409
|
+
* database assigned. A closed connection rejects with `DataException`.
|
|
410
|
+
*
|
|
411
|
+
* Never call the connection inside a transaction's action: use the
|
|
412
|
+
* transaction's own statements. A call on the connection waits for its turn,
|
|
413
|
+
* which comes only after the action ends, so it never settles.
|
|
414
|
+
*/
|
|
415
|
+
public insertAsync(query: SqlQuery): Promise<number>;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Runs a query, in the connection's turn, and returns its rows as records.
|
|
419
|
+
* A closed connection rejects with `DataException`.
|
|
420
|
+
*
|
|
421
|
+
* Never call the connection inside a transaction's action: use the
|
|
422
|
+
* transaction's own statements. A call on the connection waits for its turn,
|
|
423
|
+
* which comes only after the action ends, so it never settles.
|
|
424
|
+
*/
|
|
425
|
+
public queryAsync(query: SqlQuery): Promise<readonly DataRecord[]>;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Executes the dialect's begin statement and returns the `SqlTransaction`.
|
|
429
|
+
*/
|
|
430
|
+
protected override beginTransactionCoreAsync(): Promise<SqlTransaction>;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Closes the session.
|
|
434
|
+
*/
|
|
435
|
+
protected override closeCoreAsync(): Promise<void>;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* The change feed in a framework-owned `__changes` table of the connected
|
|
440
|
+
* database, created with its index on first use. The store assigns the
|
|
441
|
+
* sequence; a record whose operation the feed does not know throws
|
|
442
|
+
* `DataException`. Each operation ensures the table and index exist, so
|
|
443
|
+
* initialization rolled back by a transaction is recreated on the next use.
|
|
444
|
+
* An append runs in the transaction it is given, or in one of its own, and
|
|
445
|
+
* first takes the dialect's lock on `__changes`, so sequences become visible
|
|
446
|
+
* in order.
|
|
447
|
+
*/
|
|
448
|
+
export declare class SqlChangeFeed extends ChangeFeed<SqlTransaction> {
|
|
449
|
+
/**
|
|
450
|
+
* Initializes the feed over the connection.
|
|
451
|
+
*/
|
|
452
|
+
public constructor(connection: SqlConnection);
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Inserts the change under the feed's lock and returns it with the
|
|
456
|
+
* assigned sequence.
|
|
457
|
+
*/
|
|
458
|
+
protected override appendCoreAsync(entity: string, entityId: string, operation: ChangeOperation, payload: string, transaction: SqlTransaction | undefined): Promise<Change>;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Selects the changes after the sequence in order, up to the limit, under
|
|
462
|
+
* the feed's lock, in a transaction of its own when none is given.
|
|
463
|
+
*/
|
|
464
|
+
protected override readAfterCoreAsync(sequence: number, limit: number, transaction: SqlTransaction | undefined): Promise<readonly Change[]>;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* A migration of a SQL schema: declares its tables and indexes on the
|
|
469
|
+
* builder. There is no `down` until a rollback has a present need.
|
|
470
|
+
*/
|
|
471
|
+
export declare abstract class SqlMigration extends Migration {
|
|
472
|
+
/**
|
|
473
|
+
* Initializes the migration with its id.
|
|
474
|
+
*/
|
|
475
|
+
protected constructor(id: string);
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Declares the schema changes.
|
|
479
|
+
*/
|
|
480
|
+
public abstract apply(builder: MigrationBuilder): void;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* One column being declared inside `ColumnsBuilder.column`, fluently;
|
|
485
|
+
* `toColumn` produces the model, which validates the declaration.
|
|
486
|
+
*/
|
|
487
|
+
export declare class ColumnBuilder {
|
|
488
|
+
/**
|
|
489
|
+
* The column's name.
|
|
490
|
+
*/
|
|
491
|
+
public readonly name: string;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* The storage class.
|
|
495
|
+
*/
|
|
496
|
+
public readonly type: ColumnType;
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Initializes the builder for a `NOT NULL` column.
|
|
500
|
+
*/
|
|
501
|
+
public constructor(name: string, type: ColumnType);
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Allows `NULL`.
|
|
505
|
+
*/
|
|
506
|
+
public makeNullable(): this;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Produces the column model; a blank name throws `ArgumentException`.
|
|
510
|
+
*/
|
|
511
|
+
public toColumn(): Column;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* The columns of one table being declared inside
|
|
516
|
+
* `MigrationBuilder.createTable`, named after the model's properties or by
|
|
517
|
+
* text.
|
|
518
|
+
*/
|
|
519
|
+
export declare class ColumnsBuilder<TModel> {
|
|
520
|
+
/**
|
|
521
|
+
* Adds a column with the given name.
|
|
522
|
+
*/
|
|
523
|
+
public addColumn(name: string, type: ColumnType): ColumnBuilder;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Adds a column named after the selected property of the model.
|
|
527
|
+
*/
|
|
528
|
+
public addColumn(selector: ColumnSelector<TModel>, type: ColumnType): ColumnBuilder;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Produces the column models in declaration order.
|
|
532
|
+
*/
|
|
533
|
+
public toColumns(): readonly Column[];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* The constraints of one table being declared inside
|
|
538
|
+
* `MigrationBuilder.createTable`, with columns named after the models'
|
|
539
|
+
* properties.
|
|
540
|
+
*/
|
|
541
|
+
export declare class ConstraintsBuilder<TModel> {
|
|
542
|
+
/**
|
|
543
|
+
* Declares the primary key over the selected properties, in order. No
|
|
544
|
+
* properties throws `ArgumentException`.
|
|
545
|
+
*/
|
|
546
|
+
public addPrimaryKey(...columns: readonly ColumnSelector<TModel>[]): this;
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Declares a foreign key from the selected property to the selected
|
|
550
|
+
* property of the principal model in the principal table.
|
|
551
|
+
*/
|
|
552
|
+
public addForeignKey<TPrincipal>(column: ColumnSelector<TModel>, principalTable: string, principalColumn: ColumnSelector<TPrincipal>): this;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Returns the primary key, or `null` when none was declared.
|
|
556
|
+
*/
|
|
557
|
+
public toPrimaryKey(): PrimaryKey | null;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Returns the foreign keys in declaration order; a copy.
|
|
561
|
+
*/
|
|
562
|
+
public toForeignKeys(): readonly ForeignKey[];
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Collects the operations of one migration in declaration order. Tables and indexes are declared against the model a
|
|
567
|
+
* table stores, so columns are named by `nameof` selectors.
|
|
568
|
+
*/
|
|
569
|
+
export declare class MigrationBuilder {
|
|
570
|
+
/**
|
|
571
|
+
* Adds a table whose columns the first callback declares and whose
|
|
572
|
+
* constraints the second, when given, declares. A blank name or no columns
|
|
573
|
+
* throws `ArgumentException`.
|
|
574
|
+
*/
|
|
575
|
+
public createTable<TModel>(
|
|
576
|
+
name: string,
|
|
577
|
+
columns: (table: ColumnsBuilder<TModel>) => void,
|
|
578
|
+
constraints?: (table: ConstraintsBuilder<TModel>) => void): void;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Adds an index named `IX_<table>_<columns>` over the selected
|
|
582
|
+
* properties. A blank table or no properties throws `ArgumentException`.
|
|
583
|
+
*/
|
|
584
|
+
public createIndex<TModel>(table: string, ...columns: readonly ColumnSelector<TModel>[]): void;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Adds a unique index named `IX_<table>_<columns>` over the selected
|
|
588
|
+
* properties. A blank table or no properties throws `ArgumentException`.
|
|
589
|
+
*/
|
|
590
|
+
public createUniqueIndex<TModel>(table: string, ...columns: readonly ColumnSelector<TModel>[]): void;
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Adds a statement that runs as written, in declaration order with the
|
|
594
|
+
* other operations. A blank statement throws
|
|
595
|
+
* `ArgumentException`.
|
|
596
|
+
*/
|
|
597
|
+
public executeSql(statement: string): void;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Returns the operations in declaration order; a copy.
|
|
601
|
+
*/
|
|
602
|
+
public toOperations(): readonly SchemaOperation[];
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* The migration history in a `__migrations` table of the connected database,
|
|
607
|
+
* created when first read. Each operation runs in the transaction it is
|
|
608
|
+
* given, or in the connection's turn.
|
|
609
|
+
*/
|
|
610
|
+
export declare class SqlMigrationHistory extends MigrationHistory {
|
|
611
|
+
/**
|
|
612
|
+
* Initializes the history over the connection.
|
|
613
|
+
*/
|
|
614
|
+
public constructor(connection: SqlConnection);
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Creates the table when absent and returns the recorded ids in ascending
|
|
618
|
+
* order; without a transaction, it does so in one of its own under the
|
|
619
|
+
* migration lock, and a given transaction's owner holds that lock.
|
|
620
|
+
*/
|
|
621
|
+
public override getAppliedAsync(transaction?: SqlTransaction): Promise<readonly string[]>;
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Inserts the id with the current time.
|
|
625
|
+
*/
|
|
626
|
+
public override recordAsync(id: string, transaction?: SqlTransaction): Promise<void>;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Applies SQL migrations: each one runs in its own transaction, which takes
|
|
631
|
+
* the dialect's lock on `__migrations`, skips the migration when another
|
|
632
|
+
* process has recorded it meanwhile, and otherwise executes its operations,
|
|
633
|
+
* rendered in the connection's dialect, and records it.
|
|
634
|
+
*/
|
|
635
|
+
export declare class SqlMigrator extends Migrator<SqlMigration> {
|
|
636
|
+
/**
|
|
637
|
+
* Initializes the migrator over the connection with its
|
|
638
|
+
* `SqlMigrationHistory`. Migrations out of order throw `DataException`.
|
|
639
|
+
*/
|
|
640
|
+
public constructor(connection: SqlConnection, migrations: readonly SqlMigration[]);
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Applies and records the migration in one locked transaction and returns
|
|
644
|
+
* true, or returns false when the history recorded it before the lock.
|
|
645
|
+
*/
|
|
646
|
+
protected override applyAsync(migration: SqlMigration): Promise<boolean>;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* A provider of one SQL database: opens its connections and creates the
|
|
651
|
+
* `SqlMigrator` and the `SqlChangeFeed` over them. Database packages extend it with `openConnection`
|
|
652
|
+
* and add their `use` method to `DbContextOptionsBuilder`.
|
|
653
|
+
*/
|
|
654
|
+
export declare abstract class SqlProvider extends DataProvider<SqlConnection, SqlMigration> {
|
|
655
|
+
/**
|
|
656
|
+
* Creates a `SqlMigrator` over the connection for the migrations.
|
|
657
|
+
*/
|
|
658
|
+
public override createMigrator(connection: SqlConnection, migrations: readonly SqlMigration[]): Migrator<SqlMigration>;
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Creates a `SqlChangeFeed` over the connection.
|
|
662
|
+
*/
|
|
663
|
+
public override createChangeFeed(connection: SqlConnection): ChangeFeed<SqlTransaction>;
|
|
664
|
+
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export { ColumnType } from "../enums/column-type.js";
|
|
9
|
+
export { CreateIndexOperation } from "../models/operations/create-index-operation.js";
|
|
10
|
+
export { CreateTableOperation } from "../models/operations/create-table-operation.js";
|
|
11
|
+
export { SchemaOperation } from "../models/operations/schema-operation.js";
|
|
12
|
+
export { SqlStatementOperation } from "../models/operations/sql-statement-operation.js";
|
|
13
|
+
export { Column } from "../models/schema/column.js";
|
|
14
|
+
export { ForeignKey } from "../models/schema/foreign-key.js";
|
|
15
|
+
export { PrimaryKey } from "../models/schema/primary-key.js";
|
|
16
|
+
export { Table } from "../models/schema/table.js";
|
|
17
|
+
export { SqlQuery } from "../models/sql-query.js";
|
|
18
|
+
export { ColumnBuilder } from "../models/schema/column-builder.js";
|
|
19
|
+
export { ColumnsBuilder } from "../models/schema/columns-builder.js";
|
|
20
|
+
export { ConstraintsBuilder } from "../models/schema/constraints-builder.js";
|
|
21
|
+
export { MigrationBuilder } from "../models/schema/migration-builder.js";
|
|
22
|
+
export { SqlChangeFeed } from "../services/sql-change-feed.js";
|
|
23
|
+
export { SqlConnection } from "../models/sql-connection.js";
|
|
24
|
+
export { SqlDialect } from "../services/sql-dialect.js";
|
|
25
|
+
export { SqlMigration } from "../models/sql-migration.js";
|
|
26
|
+
export { SqlMigrationHistory } from "../services/sql-migration-history.js";
|
|
27
|
+
export { SqlMigrator } from "../services/sql-migrator.js";
|
|
28
|
+
export { SqlProvider } from "../services/sql-provider.js";
|
|
29
|
+
export { SqlSession } from "../models/sql-session.js";
|
|
30
|
+
export { SqlTransaction } from "../models/sql-transaction.js";
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
package/api/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/data/noldova.context.data.sql/src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export var ColumnType;
|
|
9
|
+
(function (ColumnType) {
|
|
10
|
+
ColumnType["Text"] = "Text";
|
|
11
|
+
ColumnType["Integer"] = "Integer";
|
|
12
|
+
})(ColumnType || (ColumnType = {}));
|
|
13
|
+
//# sourceMappingURL=column-type.js.map
|