@bjnstnkvc/db 0.1.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/LICENSE +21 -0
- package/README.md +1290 -0
- package/dist/main.cjs +4414 -0
- package/dist/main.d.cts +1372 -0
- package/dist/main.d.ts +1372 -0
- package/dist/main.js +4349 -0
- package/package.json +51 -0
package/dist/main.d.cts
ADDED
|
@@ -0,0 +1,1372 @@
|
|
|
1
|
+
type Enumerable = readonly string[] | Record<string, string | number>;
|
|
2
|
+
type ColumnType = 'string' | 'integer' | 'float' | 'boolean' | 'date' | 'datetime' | 'json' | 'decimal' | 'enum';
|
|
3
|
+
interface ColumnSchema {
|
|
4
|
+
name: string;
|
|
5
|
+
type: ColumnType;
|
|
6
|
+
nullable: boolean;
|
|
7
|
+
default: unknown;
|
|
8
|
+
hasDefault: boolean;
|
|
9
|
+
primary: boolean;
|
|
10
|
+
increments: boolean;
|
|
11
|
+
places: number | null;
|
|
12
|
+
values: string[] | null;
|
|
13
|
+
}
|
|
14
|
+
interface IndexSchema {
|
|
15
|
+
name: string;
|
|
16
|
+
columns: string[];
|
|
17
|
+
unique: boolean;
|
|
18
|
+
multiEntry: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface TableSchema {
|
|
21
|
+
table: string;
|
|
22
|
+
key: string | null;
|
|
23
|
+
increments: boolean;
|
|
24
|
+
timestamps: boolean;
|
|
25
|
+
columns: ColumnSchema[];
|
|
26
|
+
indexes: IndexSchema[];
|
|
27
|
+
}
|
|
28
|
+
interface RenamedColumn {
|
|
29
|
+
from: string;
|
|
30
|
+
to: string;
|
|
31
|
+
}
|
|
32
|
+
interface BlueprintOperations {
|
|
33
|
+
added: ColumnSchema[];
|
|
34
|
+
dropped: string[];
|
|
35
|
+
renamed: RenamedColumn[];
|
|
36
|
+
indexed: IndexSchema[];
|
|
37
|
+
unindexed: string[];
|
|
38
|
+
}
|
|
39
|
+
interface RequestedIndex {
|
|
40
|
+
name: string | null;
|
|
41
|
+
unique: boolean;
|
|
42
|
+
multiEntry: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class ColumnDefinition {
|
|
46
|
+
#private;
|
|
47
|
+
/**
|
|
48
|
+
* Create a new column definition.
|
|
49
|
+
*/
|
|
50
|
+
constructor(name: string, type: ColumnType);
|
|
51
|
+
/**
|
|
52
|
+
* Get the name of the column.
|
|
53
|
+
*/
|
|
54
|
+
get name(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Get the declared type of the column.
|
|
57
|
+
*/
|
|
58
|
+
get type(): ColumnType;
|
|
59
|
+
/**
|
|
60
|
+
* Record the scale of a decimal column.
|
|
61
|
+
*/
|
|
62
|
+
scaled(places: number): this;
|
|
63
|
+
/**
|
|
64
|
+
* Record the values an enumerated column accepts.
|
|
65
|
+
*/
|
|
66
|
+
accepts(values: string[]): this;
|
|
67
|
+
/**
|
|
68
|
+
* Allow the column to hold a null value.
|
|
69
|
+
*/
|
|
70
|
+
nullable(value?: boolean): this;
|
|
71
|
+
/**
|
|
72
|
+
* Set the value applied when the column is absent.
|
|
73
|
+
*/
|
|
74
|
+
default(value: unknown): this;
|
|
75
|
+
/**
|
|
76
|
+
* Make the column the key path of its table.
|
|
77
|
+
*/
|
|
78
|
+
primary(): this;
|
|
79
|
+
/**
|
|
80
|
+
* Let the database generate the column value.
|
|
81
|
+
*/
|
|
82
|
+
increments(): this;
|
|
83
|
+
/**
|
|
84
|
+
* Request an index over the column.
|
|
85
|
+
*/
|
|
86
|
+
index(name?: string | null): this;
|
|
87
|
+
/**
|
|
88
|
+
* Request a unique index over the column.
|
|
89
|
+
*/
|
|
90
|
+
unique(name?: string | null): this;
|
|
91
|
+
/**
|
|
92
|
+
* Index each element of the column's array value, requesting an index when none was.
|
|
93
|
+
*/
|
|
94
|
+
multiEntry(): this;
|
|
95
|
+
/**
|
|
96
|
+
* Get the indexes requested for the column.
|
|
97
|
+
*/
|
|
98
|
+
requested(): RequestedIndex[];
|
|
99
|
+
/**
|
|
100
|
+
* Get the schema describing the column.
|
|
101
|
+
*/
|
|
102
|
+
toSchema(): ColumnSchema;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare class Blueprint {
|
|
106
|
+
#private;
|
|
107
|
+
/**
|
|
108
|
+
* Create a new blueprint for a table.
|
|
109
|
+
*/
|
|
110
|
+
constructor(table: string, existing?: TableSchema | null);
|
|
111
|
+
/**
|
|
112
|
+
* Get the name of the table.
|
|
113
|
+
*/
|
|
114
|
+
get table(): string;
|
|
115
|
+
/**
|
|
116
|
+
* Add an auto incrementing primary key column.
|
|
117
|
+
*/
|
|
118
|
+
id(column?: string): ColumnDefinition;
|
|
119
|
+
/**
|
|
120
|
+
* Add a string column holding a universally unique identifier.
|
|
121
|
+
*/
|
|
122
|
+
uuid(column: string): ColumnDefinition;
|
|
123
|
+
/**
|
|
124
|
+
* Add a string column.
|
|
125
|
+
*/
|
|
126
|
+
string(column: string): ColumnDefinition;
|
|
127
|
+
/**
|
|
128
|
+
* Add an integer column.
|
|
129
|
+
*/
|
|
130
|
+
integer(column: string): ColumnDefinition;
|
|
131
|
+
/**
|
|
132
|
+
* Add a floating point column.
|
|
133
|
+
*/
|
|
134
|
+
float(column: string): ColumnDefinition;
|
|
135
|
+
/**
|
|
136
|
+
* Add a boolean column.
|
|
137
|
+
*/
|
|
138
|
+
boolean(column: string): ColumnDefinition;
|
|
139
|
+
/**
|
|
140
|
+
* Add a date column.
|
|
141
|
+
*/
|
|
142
|
+
date(column: string): ColumnDefinition;
|
|
143
|
+
/**
|
|
144
|
+
* Add a date and time column.
|
|
145
|
+
*/
|
|
146
|
+
datetime(column: string): ColumnDefinition;
|
|
147
|
+
/**
|
|
148
|
+
* Add a column holding an arbitrary structure.
|
|
149
|
+
*/
|
|
150
|
+
json(column: string): ColumnDefinition;
|
|
151
|
+
/**
|
|
152
|
+
* Add a fixed point column, stored as an integer number of its smallest unit.
|
|
153
|
+
*/
|
|
154
|
+
decimal(column: string, places?: number): ColumnDefinition;
|
|
155
|
+
/**
|
|
156
|
+
* Add a column accepting only one of the given values.
|
|
157
|
+
*/
|
|
158
|
+
enum(column: string, values: Enumerable): ColumnDefinition;
|
|
159
|
+
/**
|
|
160
|
+
* Add nullable creation and update timestamp columns.
|
|
161
|
+
*/
|
|
162
|
+
timestamps(): void;
|
|
163
|
+
/**
|
|
164
|
+
* Add an index over the given columns.
|
|
165
|
+
*/
|
|
166
|
+
index(columns: string | string[], name?: string | null): IndexSchema;
|
|
167
|
+
/**
|
|
168
|
+
* Add a unique index over the given columns.
|
|
169
|
+
*/
|
|
170
|
+
unique(columns: string | string[], name?: string | null): IndexSchema;
|
|
171
|
+
/**
|
|
172
|
+
* Drop the given columns from the table.
|
|
173
|
+
*/
|
|
174
|
+
dropColumn(...columns: string[]): void;
|
|
175
|
+
/**
|
|
176
|
+
* Rename a column of the table.
|
|
177
|
+
*/
|
|
178
|
+
renameColumn(from: string, to: string): void;
|
|
179
|
+
/**
|
|
180
|
+
* Drop an index from the table.
|
|
181
|
+
*/
|
|
182
|
+
dropIndex(name: string): void;
|
|
183
|
+
/**
|
|
184
|
+
* Get the schema describing the table once the blueprint is applied.
|
|
185
|
+
*/
|
|
186
|
+
toSchema(): TableSchema;
|
|
187
|
+
/**
|
|
188
|
+
* Get the operations the blueprint performs against the existing table.
|
|
189
|
+
*/
|
|
190
|
+
operations(): BlueprintOperations;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type Key<T> = (keyof T & string) | (string & {});
|
|
194
|
+
type Operator = '=' | '==' | '===' | '!=' | '<>' | '!==' | '<' | '>' | '<=' | '>=' | 'like' | 'not like';
|
|
195
|
+
type Conjunction = 'and' | 'or';
|
|
196
|
+
type Direction = 'asc' | 'desc';
|
|
197
|
+
type DatePart = 'year' | 'month' | 'day';
|
|
198
|
+
type Constraint = {
|
|
199
|
+
type: 'basic';
|
|
200
|
+
column: string;
|
|
201
|
+
operator: Operator;
|
|
202
|
+
value: unknown;
|
|
203
|
+
conjunction: Conjunction;
|
|
204
|
+
not: boolean;
|
|
205
|
+
} | {
|
|
206
|
+
type: 'in';
|
|
207
|
+
column: string;
|
|
208
|
+
values: unknown[];
|
|
209
|
+
conjunction: Conjunction;
|
|
210
|
+
not: boolean;
|
|
211
|
+
} | {
|
|
212
|
+
type: 'null';
|
|
213
|
+
column: string;
|
|
214
|
+
conjunction: Conjunction;
|
|
215
|
+
not: boolean;
|
|
216
|
+
} | {
|
|
217
|
+
type: 'between';
|
|
218
|
+
column: string;
|
|
219
|
+
from: unknown;
|
|
220
|
+
to: unknown;
|
|
221
|
+
conjunction: Conjunction;
|
|
222
|
+
not: boolean;
|
|
223
|
+
} | {
|
|
224
|
+
type: 'column';
|
|
225
|
+
column: string;
|
|
226
|
+
operator: Operator;
|
|
227
|
+
other: string;
|
|
228
|
+
conjunction: Conjunction;
|
|
229
|
+
not: boolean;
|
|
230
|
+
} | {
|
|
231
|
+
type: 'part';
|
|
232
|
+
column: string;
|
|
233
|
+
part: DatePart;
|
|
234
|
+
value: number;
|
|
235
|
+
conjunction: Conjunction;
|
|
236
|
+
not: boolean;
|
|
237
|
+
} | {
|
|
238
|
+
type: 'nested';
|
|
239
|
+
constraints: Constraint[];
|
|
240
|
+
conjunction: Conjunction;
|
|
241
|
+
not: boolean;
|
|
242
|
+
};
|
|
243
|
+
interface Order {
|
|
244
|
+
column: string;
|
|
245
|
+
direction: Direction;
|
|
246
|
+
}
|
|
247
|
+
interface Plan {
|
|
248
|
+
source: 'key' | 'index' | 'scan';
|
|
249
|
+
index: string | null;
|
|
250
|
+
range: IDBKeyRange | null;
|
|
251
|
+
values: unknown[] | null;
|
|
252
|
+
direction: IDBCursorDirection;
|
|
253
|
+
ordered: boolean;
|
|
254
|
+
residual: Constraint[];
|
|
255
|
+
}
|
|
256
|
+
type JoinType = 'inner' | 'left' | 'right' | 'cross';
|
|
257
|
+
interface JoinCondition {
|
|
258
|
+
first: string;
|
|
259
|
+
operator: Operator;
|
|
260
|
+
second: string;
|
|
261
|
+
conjunction: Conjunction;
|
|
262
|
+
}
|
|
263
|
+
interface JoinClause {
|
|
264
|
+
table: string;
|
|
265
|
+
type: JoinType;
|
|
266
|
+
conditions: JoinCondition[];
|
|
267
|
+
}
|
|
268
|
+
interface Projection {
|
|
269
|
+
column: string;
|
|
270
|
+
alias: string;
|
|
271
|
+
}
|
|
272
|
+
interface Paginated<T> {
|
|
273
|
+
data: T[];
|
|
274
|
+
total: number;
|
|
275
|
+
perPage: number;
|
|
276
|
+
currentPage: number;
|
|
277
|
+
lastPage: number;
|
|
278
|
+
}
|
|
279
|
+
type Aggregation = {
|
|
280
|
+
count: '*' | (string & {});
|
|
281
|
+
} | {
|
|
282
|
+
sum: string;
|
|
283
|
+
} | {
|
|
284
|
+
avg: string;
|
|
285
|
+
} | {
|
|
286
|
+
min: string;
|
|
287
|
+
} | {
|
|
288
|
+
max: string;
|
|
289
|
+
};
|
|
290
|
+
type Aggregations = Record<string, Aggregation>;
|
|
291
|
+
type Aggregated<A extends Aggregation> = A extends {
|
|
292
|
+
count: unknown;
|
|
293
|
+
} ? number : number | null;
|
|
294
|
+
type Grouped<T, G extends (keyof T & string)[], A extends Aggregations> = {
|
|
295
|
+
[K in G[number]]: T[K];
|
|
296
|
+
} & {
|
|
297
|
+
[K in keyof A]: Aggregated<A[K]>;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
declare class Join {
|
|
301
|
+
#private;
|
|
302
|
+
/**
|
|
303
|
+
* Join on a pair of columns.
|
|
304
|
+
*/
|
|
305
|
+
on(first: string, operator: Operator | string, second?: string): this;
|
|
306
|
+
/**
|
|
307
|
+
* Join on a pair of columns, disjunctively.
|
|
308
|
+
*/
|
|
309
|
+
orOn(first: string, operator: Operator | string, second?: string): this;
|
|
310
|
+
/**
|
|
311
|
+
* Get the conditions the tables are joined on.
|
|
312
|
+
*/
|
|
313
|
+
conditions(): JoinCondition[];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
type Records = () => Promise<Record<string, unknown>[]>;
|
|
317
|
+
declare class Grouping<T, G extends (keyof T & string)[], A extends Aggregations = Record<string, never>> {
|
|
318
|
+
#private;
|
|
319
|
+
/**
|
|
320
|
+
* Create a new grouping.
|
|
321
|
+
*/
|
|
322
|
+
constructor(records: Records, columns: G);
|
|
323
|
+
/**
|
|
324
|
+
* Compute the given aggregations for each group.
|
|
325
|
+
*/
|
|
326
|
+
aggregate<N extends Aggregations>(aggregations: N): Grouping<T, G, N>;
|
|
327
|
+
/**
|
|
328
|
+
* Constrain the groups the query returns.
|
|
329
|
+
*/
|
|
330
|
+
having(column: Key<Grouped<T, G, A>>, operator?: Operator | unknown, value?: unknown): this;
|
|
331
|
+
/**
|
|
332
|
+
* Add a disjunctive constraint on the groups the query returns.
|
|
333
|
+
*/
|
|
334
|
+
orHaving(column: Key<Grouped<T, G, A>>, operator?: Operator | unknown, value?: unknown): this;
|
|
335
|
+
/**
|
|
336
|
+
* Sort the groups by a column or an aggregate.
|
|
337
|
+
*/
|
|
338
|
+
orderBy(column: Key<Grouped<T, G, A>>, direction?: Direction): this;
|
|
339
|
+
/**
|
|
340
|
+
* Limit the number of groups the query returns.
|
|
341
|
+
*/
|
|
342
|
+
limit(value: number): this;
|
|
343
|
+
/**
|
|
344
|
+
* Skip the given number of groups.
|
|
345
|
+
*/
|
|
346
|
+
offset(value: number): this;
|
|
347
|
+
/**
|
|
348
|
+
* Get every group matching the query.
|
|
349
|
+
*/
|
|
350
|
+
get(): Promise<Grouped<T, G, A>[]>;
|
|
351
|
+
/**
|
|
352
|
+
* Get the first group matching the query.
|
|
353
|
+
*/
|
|
354
|
+
first(): Promise<Grouped<T, G, A> | null>;
|
|
355
|
+
/**
|
|
356
|
+
* Count the groups matching the query.
|
|
357
|
+
*/
|
|
358
|
+
count(): Promise<number>;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
declare class Transaction {
|
|
362
|
+
#private;
|
|
363
|
+
/**
|
|
364
|
+
* Create a new transaction.
|
|
365
|
+
*/
|
|
366
|
+
constructor(connection: Connection, transaction: IDBTransaction);
|
|
367
|
+
/**
|
|
368
|
+
* Get the names of the tables the transaction is scoped to.
|
|
369
|
+
*/
|
|
370
|
+
get tables(): string[];
|
|
371
|
+
/**
|
|
372
|
+
* Begin a query against a table inside the transaction.
|
|
373
|
+
*/
|
|
374
|
+
table<T = Record<string, unknown>>(name: string): Builder<T>;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
declare abstract class Migration {
|
|
378
|
+
/**
|
|
379
|
+
* Run the migration.
|
|
380
|
+
*/
|
|
381
|
+
abstract up(): void | Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Get the name of the migration.
|
|
384
|
+
*/
|
|
385
|
+
name(): string;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
type MigrationConstructor = new () => Migration;
|
|
389
|
+
interface MigrationStatus {
|
|
390
|
+
migration: string;
|
|
391
|
+
ran: boolean;
|
|
392
|
+
at: string | null;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
declare abstract class Seeder {
|
|
396
|
+
/**
|
|
397
|
+
* Seed the database.
|
|
398
|
+
*/
|
|
399
|
+
abstract run(): void | Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* Get the name of the seeder.
|
|
402
|
+
*/
|
|
403
|
+
name(): string;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
type SeederConstructor = new () => Seeder;
|
|
407
|
+
|
|
408
|
+
interface ConnectionConfig {
|
|
409
|
+
database: string;
|
|
410
|
+
migrations?: MigrationConstructor[];
|
|
411
|
+
seeders?: SeederConstructor[];
|
|
412
|
+
strict?: boolean;
|
|
413
|
+
}
|
|
414
|
+
interface FreshOptions {
|
|
415
|
+
seed?: boolean;
|
|
416
|
+
}
|
|
417
|
+
interface DatabaseConfig {
|
|
418
|
+
default: string;
|
|
419
|
+
connections: Record<string, ConnectionConfig>;
|
|
420
|
+
}
|
|
421
|
+
interface TransactionOptions {
|
|
422
|
+
tables?: string[];
|
|
423
|
+
}
|
|
424
|
+
interface QueryLogEntry {
|
|
425
|
+
connection: string;
|
|
426
|
+
table: string;
|
|
427
|
+
plan: string;
|
|
428
|
+
duration: number;
|
|
429
|
+
records: number;
|
|
430
|
+
}
|
|
431
|
+
interface ListenOptions {
|
|
432
|
+
once?: boolean;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
declare class Connection {
|
|
436
|
+
#private;
|
|
437
|
+
/**
|
|
438
|
+
* Create a new connection.
|
|
439
|
+
*/
|
|
440
|
+
constructor(name: string, config: ConnectionConfig);
|
|
441
|
+
/**
|
|
442
|
+
* Get the name of the connection.
|
|
443
|
+
*/
|
|
444
|
+
get name(): string;
|
|
445
|
+
/**
|
|
446
|
+
* Get the name of the underlying database.
|
|
447
|
+
*/
|
|
448
|
+
get database(): string;
|
|
449
|
+
/**
|
|
450
|
+
* Determine whether the connection enforces its column declarations.
|
|
451
|
+
*/
|
|
452
|
+
get strict(): boolean;
|
|
453
|
+
/**
|
|
454
|
+
* Get the migrations registered on the connection.
|
|
455
|
+
*/
|
|
456
|
+
get migrations(): MigrationConstructor[];
|
|
457
|
+
/**
|
|
458
|
+
* Get the seeders registered on the connection.
|
|
459
|
+
*/
|
|
460
|
+
get seeders(): SeederConstructor[];
|
|
461
|
+
/**
|
|
462
|
+
* Open the underlying database, running any pending migrations.
|
|
463
|
+
*/
|
|
464
|
+
open(): Promise<IDBDatabase>;
|
|
465
|
+
/**
|
|
466
|
+
* Run any pending migrations, returning the names of those this call ran.
|
|
467
|
+
*/
|
|
468
|
+
migrate(): Promise<string[]>;
|
|
469
|
+
/**
|
|
470
|
+
* Run every registered seeder, returning their names.
|
|
471
|
+
*/
|
|
472
|
+
seed(): Promise<string[]>;
|
|
473
|
+
/**
|
|
474
|
+
* Delete the database and replay every migration.
|
|
475
|
+
*/
|
|
476
|
+
fresh(options?: FreshOptions): Promise<string[]>;
|
|
477
|
+
/**
|
|
478
|
+
* Get the state of every registered migration, without running any of them.
|
|
479
|
+
*/
|
|
480
|
+
status(): Promise<MigrationStatus[]>;
|
|
481
|
+
/**
|
|
482
|
+
* Begin a query against a table.
|
|
483
|
+
*/
|
|
484
|
+
table<T = Record<string, unknown>>(table: string, transaction?: IDBTransaction | null): Builder<T>;
|
|
485
|
+
/**
|
|
486
|
+
* Run the callback inside a transaction, committing when it resolves.
|
|
487
|
+
*/
|
|
488
|
+
transaction<R>(callback: (transaction: Transaction) => R | Promise<R>, options?: TransactionOptions): Promise<R>;
|
|
489
|
+
/**
|
|
490
|
+
* Get the schema of a table.
|
|
491
|
+
*/
|
|
492
|
+
schema(table: string): Promise<TableSchema>;
|
|
493
|
+
/**
|
|
494
|
+
* Get the names of every table.
|
|
495
|
+
*/
|
|
496
|
+
tables(): Promise<string[]>;
|
|
497
|
+
/**
|
|
498
|
+
* Determine whether a table exists.
|
|
499
|
+
*/
|
|
500
|
+
hasTable(table: string): Promise<boolean>;
|
|
501
|
+
/**
|
|
502
|
+
* Determine whether a table has a column.
|
|
503
|
+
*/
|
|
504
|
+
hasColumn(table: string, column: string): Promise<boolean>;
|
|
505
|
+
/**
|
|
506
|
+
* Get the columns of a table.
|
|
507
|
+
*/
|
|
508
|
+
getColumns(table: string): Promise<ColumnSchema[]>;
|
|
509
|
+
/**
|
|
510
|
+
* Get the indexes of a table.
|
|
511
|
+
*/
|
|
512
|
+
getIndexes(table: string): Promise<IndexSchema[]>;
|
|
513
|
+
/**
|
|
514
|
+
* Close the underlying database.
|
|
515
|
+
*/
|
|
516
|
+
disconnect(): void;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
type Nested<T> = (query: Builder<T>) => void;
|
|
520
|
+
type Joining = (join: Join) => void;
|
|
521
|
+
type Column<T> = Key<T> | Partial<T> | Nested<T>;
|
|
522
|
+
declare class Builder<T = Record<string, unknown>> {
|
|
523
|
+
#private;
|
|
524
|
+
/**
|
|
525
|
+
* Create a new query builder.
|
|
526
|
+
*/
|
|
527
|
+
constructor(connection: Connection, table: string, transaction?: IDBTransaction | null);
|
|
528
|
+
/**
|
|
529
|
+
* Get the name of the table the query runs against.
|
|
530
|
+
*/
|
|
531
|
+
get table(): string;
|
|
532
|
+
/**
|
|
533
|
+
* Add a constraint to the query.
|
|
534
|
+
*/
|
|
535
|
+
where(column: Column<T>, operator?: Operator | unknown, value?: unknown): this;
|
|
536
|
+
/**
|
|
537
|
+
* Add a disjunctive constraint to the query.
|
|
538
|
+
*/
|
|
539
|
+
orWhere(column: Column<T>, operator?: Operator | unknown, value?: unknown): this;
|
|
540
|
+
/**
|
|
541
|
+
* Add a negated constraint to the query.
|
|
542
|
+
*/
|
|
543
|
+
whereNot(column: Column<T>, operator?: Operator | unknown, value?: unknown): this;
|
|
544
|
+
/**
|
|
545
|
+
* Constrain a column to one of the given values.
|
|
546
|
+
*/
|
|
547
|
+
whereIn(column: Key<T>, values: unknown[]): this;
|
|
548
|
+
/**
|
|
549
|
+
* Constrain a column to one of the given values, disjunctively.
|
|
550
|
+
*/
|
|
551
|
+
orWhereIn(column: Key<T>, values: unknown[]): this;
|
|
552
|
+
/**
|
|
553
|
+
* Constrain a column to none of the given values.
|
|
554
|
+
*/
|
|
555
|
+
whereNotIn(column: Key<T>, values: unknown[]): this;
|
|
556
|
+
/**
|
|
557
|
+
* Constrain a column to none of the given values, disjunctively.
|
|
558
|
+
*/
|
|
559
|
+
orWhereNotIn(column: Key<T>, values: unknown[]): this;
|
|
560
|
+
/**
|
|
561
|
+
* Constrain a column to be null.
|
|
562
|
+
*/
|
|
563
|
+
whereNull(column: Key<T>): this;
|
|
564
|
+
/**
|
|
565
|
+
* Constrain a column to be null, disjunctively.
|
|
566
|
+
*/
|
|
567
|
+
orWhereNull(column: Key<T>): this;
|
|
568
|
+
/**
|
|
569
|
+
* Constrain a column to not be null.
|
|
570
|
+
*/
|
|
571
|
+
whereNotNull(column: Key<T>): this;
|
|
572
|
+
/**
|
|
573
|
+
* Constrain a column to not be null, disjunctively.
|
|
574
|
+
*/
|
|
575
|
+
orWhereNotNull(column: Key<T>): this;
|
|
576
|
+
/**
|
|
577
|
+
* Constrain a column to fall between two values, inclusive.
|
|
578
|
+
*/
|
|
579
|
+
whereBetween(column: Key<T>, values: [unknown, unknown]): this;
|
|
580
|
+
/**
|
|
581
|
+
* Constrain a column to fall between two values, disjunctively.
|
|
582
|
+
*/
|
|
583
|
+
orWhereBetween(column: Key<T>, values: [unknown, unknown]): this;
|
|
584
|
+
/**
|
|
585
|
+
* Constrain a column to fall outside two values.
|
|
586
|
+
*/
|
|
587
|
+
whereNotBetween(column: Key<T>, values: [unknown, unknown]): this;
|
|
588
|
+
/**
|
|
589
|
+
* Constrain a column to fall outside two values, disjunctively.
|
|
590
|
+
*/
|
|
591
|
+
orWhereNotBetween(column: Key<T>, values: [unknown, unknown]): this;
|
|
592
|
+
/**
|
|
593
|
+
* Constrain a column to match a pattern.
|
|
594
|
+
*/
|
|
595
|
+
whereLike(column: Key<T>, pattern: string): this;
|
|
596
|
+
/**
|
|
597
|
+
* Constrain a column to match a pattern, disjunctively.
|
|
598
|
+
*/
|
|
599
|
+
orWhereLike(column: Key<T>, pattern: string): this;
|
|
600
|
+
/**
|
|
601
|
+
* Constrain a column to not match a pattern.
|
|
602
|
+
*/
|
|
603
|
+
whereNotLike(column: Key<T>, pattern: string): this;
|
|
604
|
+
/**
|
|
605
|
+
* Constrain a column to not match a pattern, disjunctively.
|
|
606
|
+
*/
|
|
607
|
+
orWhereNotLike(column: Key<T>, pattern: string): this;
|
|
608
|
+
/**
|
|
609
|
+
* Constrain a date column to fall on a given day.
|
|
610
|
+
*/
|
|
611
|
+
whereDate(column: Key<T>, value: Date | string): this;
|
|
612
|
+
/**
|
|
613
|
+
* Constrain a date column to fall in a given year.
|
|
614
|
+
*/
|
|
615
|
+
whereYear(column: Key<T>, value: number): this;
|
|
616
|
+
/**
|
|
617
|
+
* Constrain a date column to fall in a given month, numbered from one.
|
|
618
|
+
*/
|
|
619
|
+
whereMonth(column: Key<T>, value: number): this;
|
|
620
|
+
/**
|
|
621
|
+
* Constrain a date column to fall on a given day of the month.
|
|
622
|
+
*/
|
|
623
|
+
whereDay(column: Key<T>, value: number): this;
|
|
624
|
+
/**
|
|
625
|
+
* Join another table, keeping only the rows that match.
|
|
626
|
+
*/
|
|
627
|
+
join<R = Record<string, unknown>>(table: string, first: string | Joining, operator?: Operator | string, second?: string): Builder<R>;
|
|
628
|
+
/**
|
|
629
|
+
* Join another table, keeping every row of this one.
|
|
630
|
+
*/
|
|
631
|
+
leftJoin<R = Record<string, unknown>>(table: string, first: string | Joining, operator?: Operator | string, second?: string): Builder<R>;
|
|
632
|
+
/**
|
|
633
|
+
* Join another table, keeping every row of it.
|
|
634
|
+
*/
|
|
635
|
+
rightJoin<R = Record<string, unknown>>(table: string, first: string | Joining, operator?: Operator | string, second?: string): Builder<R>;
|
|
636
|
+
/**
|
|
637
|
+
* Pair every row of this table with every row of another.
|
|
638
|
+
*/
|
|
639
|
+
crossJoin<R = Record<string, unknown>>(table: string): Builder<R>;
|
|
640
|
+
/**
|
|
641
|
+
* Constrain a column against another column of the same row.
|
|
642
|
+
*/
|
|
643
|
+
whereColumn(column: Key<T>, operator: Operator | string, other?: string): this;
|
|
644
|
+
/**
|
|
645
|
+
* Constrain a column against another column of the same row, disjunctively.
|
|
646
|
+
*/
|
|
647
|
+
orWhereColumn(column: Key<T>, operator: Operator | string, other?: string): this;
|
|
648
|
+
/**
|
|
649
|
+
* Project only the given columns, which may alias what they select.
|
|
650
|
+
*/
|
|
651
|
+
select(...columns: (Key<T> | Key<T>[])[]): this;
|
|
652
|
+
/**
|
|
653
|
+
* Remove duplicate records from the result.
|
|
654
|
+
*/
|
|
655
|
+
distinct(value?: boolean): this;
|
|
656
|
+
/**
|
|
657
|
+
* Group the matching records by one or more columns.
|
|
658
|
+
*/
|
|
659
|
+
groupBy<G extends (keyof T & string)[]>(...columns: G): Grouping<T, G>;
|
|
660
|
+
/**
|
|
661
|
+
* Sort the result by a column.
|
|
662
|
+
*/
|
|
663
|
+
orderBy(column: Key<T>, direction?: Direction): this;
|
|
664
|
+
/**
|
|
665
|
+
* Sort the result by a column, newest first.
|
|
666
|
+
*/
|
|
667
|
+
latest(column?: Key<T>): this;
|
|
668
|
+
/**
|
|
669
|
+
* Sort the result by a column, oldest first.
|
|
670
|
+
*/
|
|
671
|
+
oldest(column?: Key<T>): this;
|
|
672
|
+
/**
|
|
673
|
+
* Limit the number of records the query returns.
|
|
674
|
+
*/
|
|
675
|
+
limit(value: number): this;
|
|
676
|
+
/**
|
|
677
|
+
* Limit the number of records the query returns.
|
|
678
|
+
*/
|
|
679
|
+
take(value: number): this;
|
|
680
|
+
/**
|
|
681
|
+
* Skip the given number of records.
|
|
682
|
+
*/
|
|
683
|
+
offset(value: number): this;
|
|
684
|
+
/**
|
|
685
|
+
* Skip the given number of records.
|
|
686
|
+
*/
|
|
687
|
+
skip(value: number): this;
|
|
688
|
+
/**
|
|
689
|
+
* Limit the query to a single page of records.
|
|
690
|
+
*/
|
|
691
|
+
forPage(page: number, perPage?: number): this;
|
|
692
|
+
/**
|
|
693
|
+
* Apply the callback when the value is truthy.
|
|
694
|
+
*/
|
|
695
|
+
when(value: unknown, callback: (query: this, value: unknown) => void): this;
|
|
696
|
+
/**
|
|
697
|
+
* Apply the callback when the value is falsy.
|
|
698
|
+
*/
|
|
699
|
+
unless(value: unknown, callback: (query: this, value: unknown) => void): this;
|
|
700
|
+
/**
|
|
701
|
+
* Pass the query to the callback and carry on.
|
|
702
|
+
*/
|
|
703
|
+
tap(callback: (query: this) => void): this;
|
|
704
|
+
/**
|
|
705
|
+
* Get a copy of the query.
|
|
706
|
+
*/
|
|
707
|
+
clone(): Builder<T>;
|
|
708
|
+
/**
|
|
709
|
+
* Dump the state of the query.
|
|
710
|
+
*/
|
|
711
|
+
dump(): this;
|
|
712
|
+
/**
|
|
713
|
+
* Describe the plan the query would run under.
|
|
714
|
+
*/
|
|
715
|
+
explain(): Promise<string>;
|
|
716
|
+
/**
|
|
717
|
+
* Get every record matching the query.
|
|
718
|
+
*/
|
|
719
|
+
get(): Promise<T[]>;
|
|
720
|
+
/**
|
|
721
|
+
* Get the first record matching the query.
|
|
722
|
+
*/
|
|
723
|
+
first(): Promise<T | null>;
|
|
724
|
+
/**
|
|
725
|
+
* Get the first record matching the query, or fail.
|
|
726
|
+
*/
|
|
727
|
+
firstOrFail(): Promise<T>;
|
|
728
|
+
/**
|
|
729
|
+
* Get the one record matching the query, failing when there is not exactly one.
|
|
730
|
+
*/
|
|
731
|
+
sole(): Promise<T>;
|
|
732
|
+
/**
|
|
733
|
+
* Get the record with the given key.
|
|
734
|
+
*/
|
|
735
|
+
find(key: IDBValidKey): Promise<T | null>;
|
|
736
|
+
/**
|
|
737
|
+
* Get the record with the given key, or fail.
|
|
738
|
+
*/
|
|
739
|
+
findOrFail(key: IDBValidKey): Promise<T>;
|
|
740
|
+
/**
|
|
741
|
+
* Get a single column from the first record matching the query.
|
|
742
|
+
*/
|
|
743
|
+
value<V = unknown>(column: Key<T>): Promise<V | null>;
|
|
744
|
+
/**
|
|
745
|
+
* Get a single column from every record matching the query.
|
|
746
|
+
*/
|
|
747
|
+
pluck<V = unknown>(column: Key<T>): Promise<V[]>;
|
|
748
|
+
pluck<V = unknown>(column: Key<T>, key: Key<T>): Promise<Record<string, V>>;
|
|
749
|
+
/**
|
|
750
|
+
* Determine whether any record matches the query.
|
|
751
|
+
*/
|
|
752
|
+
exists(): Promise<boolean>;
|
|
753
|
+
/**
|
|
754
|
+
* Determine whether no record matches the query.
|
|
755
|
+
*/
|
|
756
|
+
doesntExist(): Promise<boolean>;
|
|
757
|
+
/**
|
|
758
|
+
* Count the records matching the query.
|
|
759
|
+
*/
|
|
760
|
+
count(): Promise<number>;
|
|
761
|
+
/**
|
|
762
|
+
* Sum a column across the records matching the query.
|
|
763
|
+
*/
|
|
764
|
+
sum(column: Key<T>): Promise<number>;
|
|
765
|
+
/**
|
|
766
|
+
* Average a column across the records matching the query.
|
|
767
|
+
*/
|
|
768
|
+
avg(column: Key<T>): Promise<number | null>;
|
|
769
|
+
/**
|
|
770
|
+
* Get the smallest value of a column across the records matching the query.
|
|
771
|
+
*/
|
|
772
|
+
min(column: Key<T>): Promise<number | null>;
|
|
773
|
+
/**
|
|
774
|
+
* Get the largest value of a column across the records matching the query.
|
|
775
|
+
*/
|
|
776
|
+
max(column: Key<T>): Promise<number | null>;
|
|
777
|
+
/**
|
|
778
|
+
* Get a single page of records, alongside the totals a pager needs.
|
|
779
|
+
*/
|
|
780
|
+
paginate(page?: number, perPage?: number): Promise<Paginated<T>>;
|
|
781
|
+
/**
|
|
782
|
+
* Walk the records matching the query in chunks.
|
|
783
|
+
*/
|
|
784
|
+
chunk(size: number, callback: (records: T[], page: number) => unknown): Promise<boolean>;
|
|
785
|
+
/**
|
|
786
|
+
* Walk the records matching the query as an async iterable.
|
|
787
|
+
*/
|
|
788
|
+
lazy(size?: number): AsyncGenerator<T, void, undefined>;
|
|
789
|
+
/**
|
|
790
|
+
* Walk the records matching the query one at a time.
|
|
791
|
+
*/
|
|
792
|
+
each(callback: (record: T, index: number) => unknown): Promise<boolean>;
|
|
793
|
+
/**
|
|
794
|
+
* Insert one or more records into the table.
|
|
795
|
+
*/
|
|
796
|
+
insert(records: Partial<T> | Partial<T>[]): Promise<number>;
|
|
797
|
+
/**
|
|
798
|
+
* Insert one or more records, skipping any the unique indexes reject.
|
|
799
|
+
*/
|
|
800
|
+
insertOrIgnore(records: Partial<T> | Partial<T>[]): Promise<number>;
|
|
801
|
+
/**
|
|
802
|
+
* Insert a record and get the key the database gave it.
|
|
803
|
+
*/
|
|
804
|
+
insertGetId(record: Partial<T>): Promise<IDBValidKey>;
|
|
805
|
+
/**
|
|
806
|
+
* Update every record matching the query.
|
|
807
|
+
*/
|
|
808
|
+
update(values: Partial<T>): Promise<number>;
|
|
809
|
+
/**
|
|
810
|
+
* Update the matching record, inserting it when there is none.
|
|
811
|
+
*/
|
|
812
|
+
updateOrInsert(attributes: Partial<T>, values?: Partial<T>): Promise<boolean>;
|
|
813
|
+
/**
|
|
814
|
+
* Insert records, updating those that already exist.
|
|
815
|
+
*/
|
|
816
|
+
upsert(values: Partial<T>[], uniqueBy: Key<T> | Key<T>[], update?: Key<T>[]): Promise<number>;
|
|
817
|
+
/**
|
|
818
|
+
* Add the given amount to a column of every record matching the query.
|
|
819
|
+
*/
|
|
820
|
+
increment(column: Key<T>, amount?: number, extra?: Partial<T>): Promise<number>;
|
|
821
|
+
/**
|
|
822
|
+
* Subtract the given amount from a column of every record matching the query.
|
|
823
|
+
*/
|
|
824
|
+
decrement(column: Key<T>, amount?: number, extra?: Partial<T>): Promise<number>;
|
|
825
|
+
/**
|
|
826
|
+
* Delete every record matching the query.
|
|
827
|
+
*/
|
|
828
|
+
delete(): Promise<number>;
|
|
829
|
+
/**
|
|
830
|
+
* Delete every record in the table.
|
|
831
|
+
*/
|
|
832
|
+
truncate(): Promise<void>;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
declare class DatabaseBlocked extends Event {
|
|
836
|
+
#private;
|
|
837
|
+
/**
|
|
838
|
+
* Create a new Database Blocked event instance.
|
|
839
|
+
*/
|
|
840
|
+
constructor(database: string);
|
|
841
|
+
/**
|
|
842
|
+
* Get the name of the database.
|
|
843
|
+
*/
|
|
844
|
+
get database(): string;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
declare class MigrationEnded extends Event {
|
|
848
|
+
#private;
|
|
849
|
+
/**
|
|
850
|
+
* Create a new Migration Ended event instance.
|
|
851
|
+
*/
|
|
852
|
+
constructor(migration: string);
|
|
853
|
+
/**
|
|
854
|
+
* Get the name of the migration.
|
|
855
|
+
*/
|
|
856
|
+
get migration(): string;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
declare class MigrationsEnded extends Event {
|
|
860
|
+
#private;
|
|
861
|
+
/**
|
|
862
|
+
* Create a new Migrations Ended event instance.
|
|
863
|
+
*/
|
|
864
|
+
constructor(connection: string, migrations: string[]);
|
|
865
|
+
/**
|
|
866
|
+
* Get the name of the connection.
|
|
867
|
+
*/
|
|
868
|
+
get connection(): string;
|
|
869
|
+
/**
|
|
870
|
+
* Get the names of the migrations.
|
|
871
|
+
*/
|
|
872
|
+
get migrations(): string[];
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
declare class MigrationsStarted extends Event {
|
|
876
|
+
#private;
|
|
877
|
+
/**
|
|
878
|
+
* Create a new Migrations Started event instance.
|
|
879
|
+
*/
|
|
880
|
+
constructor(connection: string, migrations: string[]);
|
|
881
|
+
/**
|
|
882
|
+
* Get the name of the connection.
|
|
883
|
+
*/
|
|
884
|
+
get connection(): string;
|
|
885
|
+
/**
|
|
886
|
+
* Get the names of the migrations.
|
|
887
|
+
*/
|
|
888
|
+
get migrations(): string[];
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
declare class MigrationStarted extends Event {
|
|
892
|
+
#private;
|
|
893
|
+
/**
|
|
894
|
+
* Create a new Migration Started event instance.
|
|
895
|
+
*/
|
|
896
|
+
constructor(migration: string);
|
|
897
|
+
/**
|
|
898
|
+
* Get the name of the migration.
|
|
899
|
+
*/
|
|
900
|
+
get migration(): string;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
declare class NoPendingMigrations extends Event {
|
|
904
|
+
#private;
|
|
905
|
+
/**
|
|
906
|
+
* Create a new No Pending Migrations event instance.
|
|
907
|
+
*/
|
|
908
|
+
constructor(connection: string);
|
|
909
|
+
/**
|
|
910
|
+
* Get the name of the connection.
|
|
911
|
+
*/
|
|
912
|
+
get connection(): string;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
declare class QueryExecuted extends Event {
|
|
916
|
+
#private;
|
|
917
|
+
/**
|
|
918
|
+
* Create a new Query Executed event instance.
|
|
919
|
+
*/
|
|
920
|
+
constructor(connection: string, table: string, plan: string, constraints: Constraint[], orders: Order[], limit: number | null, duration: number, records: number);
|
|
921
|
+
/**
|
|
922
|
+
* Get the name of the connection the query ran on.
|
|
923
|
+
*/
|
|
924
|
+
get connection(): string;
|
|
925
|
+
/**
|
|
926
|
+
* Get the name of the table the query ran against.
|
|
927
|
+
*/
|
|
928
|
+
get table(): string;
|
|
929
|
+
/**
|
|
930
|
+
* Get the description of the plan the query ran under.
|
|
931
|
+
*/
|
|
932
|
+
get plan(): string;
|
|
933
|
+
/**
|
|
934
|
+
* Get the constraints the query was compiled from.
|
|
935
|
+
*/
|
|
936
|
+
get constraints(): Constraint[];
|
|
937
|
+
/**
|
|
938
|
+
* Get the orders the query was compiled from.
|
|
939
|
+
*/
|
|
940
|
+
get orders(): Order[];
|
|
941
|
+
/**
|
|
942
|
+
* Get the maximum number of records the query was allowed to return.
|
|
943
|
+
*/
|
|
944
|
+
get limit(): number | null;
|
|
945
|
+
/**
|
|
946
|
+
* Get the time the query took in milliseconds.
|
|
947
|
+
*/
|
|
948
|
+
get duration(): number;
|
|
949
|
+
/**
|
|
950
|
+
* Get the number of records the query returned or affected.
|
|
951
|
+
*/
|
|
952
|
+
get records(): number;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
declare class SeederEnded extends Event {
|
|
956
|
+
#private;
|
|
957
|
+
/**
|
|
958
|
+
* Create a new Seeder Ended event instance.
|
|
959
|
+
*/
|
|
960
|
+
constructor(seeder: string);
|
|
961
|
+
/**
|
|
962
|
+
* Get the name of the seeder.
|
|
963
|
+
*/
|
|
964
|
+
get seeder(): string;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
declare class SeederStarted extends Event {
|
|
968
|
+
#private;
|
|
969
|
+
/**
|
|
970
|
+
* Create a new Seeder Started event instance.
|
|
971
|
+
*/
|
|
972
|
+
constructor(seeder: string);
|
|
973
|
+
/**
|
|
974
|
+
* Get the name of the seeder.
|
|
975
|
+
*/
|
|
976
|
+
get seeder(): string;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
declare class SeedingEnded extends Event {
|
|
980
|
+
#private;
|
|
981
|
+
/**
|
|
982
|
+
* Create a new Seeding Ended event instance.
|
|
983
|
+
*/
|
|
984
|
+
constructor(connection: string, seeders: string[]);
|
|
985
|
+
/**
|
|
986
|
+
* Get the name of the connection.
|
|
987
|
+
*/
|
|
988
|
+
get connection(): string;
|
|
989
|
+
/**
|
|
990
|
+
* Get the names of the seeders.
|
|
991
|
+
*/
|
|
992
|
+
get seeders(): string[];
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
declare class SeedingStarted extends Event {
|
|
996
|
+
#private;
|
|
997
|
+
/**
|
|
998
|
+
* Create a new Seeding Started event instance.
|
|
999
|
+
*/
|
|
1000
|
+
constructor(connection: string, seeders: string[]);
|
|
1001
|
+
/**
|
|
1002
|
+
* Get the name of the connection.
|
|
1003
|
+
*/
|
|
1004
|
+
get connection(): string;
|
|
1005
|
+
/**
|
|
1006
|
+
* Get the names of the seeders.
|
|
1007
|
+
*/
|
|
1008
|
+
get seeders(): string[];
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
declare class TransactionBeginning extends Event {
|
|
1012
|
+
#private;
|
|
1013
|
+
/**
|
|
1014
|
+
* Create a new Transaction Beginning event instance.
|
|
1015
|
+
*/
|
|
1016
|
+
constructor(connection: string);
|
|
1017
|
+
/**
|
|
1018
|
+
* Get the name of the connection.
|
|
1019
|
+
*/
|
|
1020
|
+
get connection(): string;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
declare class TransactionCommitted extends Event {
|
|
1024
|
+
#private;
|
|
1025
|
+
/**
|
|
1026
|
+
* Create a new Transaction Committed event instance.
|
|
1027
|
+
*/
|
|
1028
|
+
constructor(connection: string);
|
|
1029
|
+
/**
|
|
1030
|
+
* Get the name of the connection.
|
|
1031
|
+
*/
|
|
1032
|
+
get connection(): string;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
declare class TransactionRolledBack extends Event {
|
|
1036
|
+
#private;
|
|
1037
|
+
/**
|
|
1038
|
+
* Create a new Transaction Rolled Back event instance.
|
|
1039
|
+
*/
|
|
1040
|
+
constructor(connection: string, reason: unknown);
|
|
1041
|
+
/**
|
|
1042
|
+
* Get the name of the connection.
|
|
1043
|
+
*/
|
|
1044
|
+
get connection(): string;
|
|
1045
|
+
/**
|
|
1046
|
+
* Get the reason the transaction was rolled back.
|
|
1047
|
+
*/
|
|
1048
|
+
get reason(): unknown;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
type DatabaseEvent = {
|
|
1052
|
+
'database-blocked': DatabaseBlocked;
|
|
1053
|
+
'migration-ended': MigrationEnded;
|
|
1054
|
+
'migration-started': MigrationStarted;
|
|
1055
|
+
'migrations-ended': MigrationsEnded;
|
|
1056
|
+
'migrations-started': MigrationsStarted;
|
|
1057
|
+
'no-pending-migrations': NoPendingMigrations;
|
|
1058
|
+
'query': QueryExecuted;
|
|
1059
|
+
'seeder-ended': SeederEnded;
|
|
1060
|
+
'seeder-started': SeederStarted;
|
|
1061
|
+
'seeding-ended': SeedingEnded;
|
|
1062
|
+
'seeding-started': SeedingStarted;
|
|
1063
|
+
'transaction-beginning': TransactionBeginning;
|
|
1064
|
+
'transaction-committed': TransactionCommitted;
|
|
1065
|
+
'transaction-rolled-back': TransactionRolledBack;
|
|
1066
|
+
};
|
|
1067
|
+
type DatabaseEventListener<K extends keyof DatabaseEvent> = (event: DatabaseEvent[K]) => void;
|
|
1068
|
+
|
|
1069
|
+
declare class DatabaseManager {
|
|
1070
|
+
#private;
|
|
1071
|
+
/**
|
|
1072
|
+
* Register the database configuration, replacing anything registered before.
|
|
1073
|
+
*/
|
|
1074
|
+
static configure(config: DatabaseConfig): void;
|
|
1075
|
+
/**
|
|
1076
|
+
* Resolve a connection by name, or the default one.
|
|
1077
|
+
*/
|
|
1078
|
+
static connection(name?: string): Connection;
|
|
1079
|
+
/**
|
|
1080
|
+
* Begin a query against a table on the default connection.
|
|
1081
|
+
*/
|
|
1082
|
+
static table<T = Record<string, unknown>>(table: string): Builder<T>;
|
|
1083
|
+
/**
|
|
1084
|
+
* Run the callback inside a transaction on the default connection.
|
|
1085
|
+
*/
|
|
1086
|
+
static transaction<R>(callback: (transaction: Transaction) => R | Promise<R>, options?: TransactionOptions): Promise<R>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Run any pending migrations, returning the names of those this call ran.
|
|
1089
|
+
*/
|
|
1090
|
+
static migrate(name: string): Promise<string[]>;
|
|
1091
|
+
/**
|
|
1092
|
+
* Run every registered seeder, returning their names.
|
|
1093
|
+
*/
|
|
1094
|
+
static seed(name: string): Promise<string[]>;
|
|
1095
|
+
/**
|
|
1096
|
+
* Delete the database and replay every migration, optionally seeding afterwards.
|
|
1097
|
+
*/
|
|
1098
|
+
static fresh(name: string, options?: FreshOptions): Promise<string[]>;
|
|
1099
|
+
/**
|
|
1100
|
+
* Get the state of every registered migration.
|
|
1101
|
+
*/
|
|
1102
|
+
static status(name: string): Promise<MigrationStatus[]>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Determine whether a table exists.
|
|
1105
|
+
*/
|
|
1106
|
+
static hasTable(table: string, name?: string): Promise<boolean>;
|
|
1107
|
+
/**
|
|
1108
|
+
* Determine whether a table has a column.
|
|
1109
|
+
*/
|
|
1110
|
+
static hasColumn(table: string, column: string, name?: string): Promise<boolean>;
|
|
1111
|
+
/**
|
|
1112
|
+
* Get the names of every table.
|
|
1113
|
+
*/
|
|
1114
|
+
static getTables(name?: string): Promise<string[]>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Get the columns of a table.
|
|
1117
|
+
*/
|
|
1118
|
+
static getColumns(table: string, name?: string): Promise<ColumnSchema[]>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Get the indexes of a table.
|
|
1121
|
+
*/
|
|
1122
|
+
static getIndexes(table: string, name?: string): Promise<IndexSchema[]>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Close a connection, leaving it registered so the next query reopens it.
|
|
1125
|
+
*/
|
|
1126
|
+
static disconnect(name: string): void;
|
|
1127
|
+
/**
|
|
1128
|
+
* Close a connection and drop it, so the next resolve rebuilds it from configuration.
|
|
1129
|
+
*/
|
|
1130
|
+
static purge(name: string): void;
|
|
1131
|
+
/**
|
|
1132
|
+
* Get how much storage this origin is using, and how much it may use.
|
|
1133
|
+
*/
|
|
1134
|
+
static estimate(): Promise<StorageEstimate>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Ask the browser not to evict this origin's storage under pressure.
|
|
1137
|
+
*/
|
|
1138
|
+
static persist(): Promise<boolean>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Determine whether this origin's storage is already exempt from eviction.
|
|
1141
|
+
*/
|
|
1142
|
+
static persisted(): Promise<boolean>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Register an event listener.
|
|
1145
|
+
*/
|
|
1146
|
+
static listen<K extends keyof DatabaseEvent>(event: K, listener: DatabaseEventListener<K>, options?: ListenOptions): void;
|
|
1147
|
+
/**
|
|
1148
|
+
* Remove an event listener.
|
|
1149
|
+
*/
|
|
1150
|
+
static forget<K extends keyof DatabaseEvent>(event: K, listener: DatabaseEventListener<K>): void;
|
|
1151
|
+
/**
|
|
1152
|
+
* Register a listener on the "query" event.
|
|
1153
|
+
*/
|
|
1154
|
+
static onQueryExecuted(listener: (event: QueryExecuted) => void, options?: ListenOptions): void;
|
|
1155
|
+
/**
|
|
1156
|
+
* Register a listener on the "transaction-beginning" event.
|
|
1157
|
+
*/
|
|
1158
|
+
static onTransactionBeginning(listener: (event: TransactionBeginning) => void, options?: ListenOptions): void;
|
|
1159
|
+
/**
|
|
1160
|
+
* Register a listener on the "transaction-committed" event.
|
|
1161
|
+
*/
|
|
1162
|
+
static onTransactionCommitted(listener: (event: TransactionCommitted) => void, options?: ListenOptions): void;
|
|
1163
|
+
/**
|
|
1164
|
+
* Register a listener on the "transaction-rolled-back" event.
|
|
1165
|
+
*/
|
|
1166
|
+
static onTransactionRolledBack(listener: (event: TransactionRolledBack) => void, options?: ListenOptions): void;
|
|
1167
|
+
/**
|
|
1168
|
+
* Register a listener on the "migrations-started" event.
|
|
1169
|
+
*/
|
|
1170
|
+
static onMigrationsStarted(listener: (event: MigrationsStarted) => void, options?: ListenOptions): void;
|
|
1171
|
+
/**
|
|
1172
|
+
* Register a listener on the "migration-started" event.
|
|
1173
|
+
*/
|
|
1174
|
+
static onMigrationStarted(listener: (event: MigrationStarted) => void, options?: ListenOptions): void;
|
|
1175
|
+
/**
|
|
1176
|
+
* Register a listener on the "migration-ended" event.
|
|
1177
|
+
*/
|
|
1178
|
+
static onMigrationEnded(listener: (event: MigrationEnded) => void, options?: ListenOptions): void;
|
|
1179
|
+
/**
|
|
1180
|
+
* Register a listener on the "migrations-ended" event.
|
|
1181
|
+
*/
|
|
1182
|
+
static onMigrationsEnded(listener: (event: MigrationsEnded) => void, options?: ListenOptions): void;
|
|
1183
|
+
/**
|
|
1184
|
+
* Register a listener on the "no-pending-migrations" event.
|
|
1185
|
+
*/
|
|
1186
|
+
static onNoPendingMigrations(listener: (event: NoPendingMigrations) => void, options?: ListenOptions): void;
|
|
1187
|
+
/**
|
|
1188
|
+
* Register a listener on the "database-blocked" event.
|
|
1189
|
+
*/
|
|
1190
|
+
static onDatabaseBlocked(listener: (event: DatabaseBlocked) => void, options?: ListenOptions): void;
|
|
1191
|
+
/**
|
|
1192
|
+
* Register a listener on the "seeding-started" event.
|
|
1193
|
+
*/
|
|
1194
|
+
static onSeedingStarted(listener: (event: SeedingStarted) => void, options?: ListenOptions): void;
|
|
1195
|
+
/**
|
|
1196
|
+
* Register a listener on the "seeder-started" event.
|
|
1197
|
+
*/
|
|
1198
|
+
static onSeederStarted(listener: (event: SeederStarted) => void, options?: ListenOptions): void;
|
|
1199
|
+
/**
|
|
1200
|
+
* Register a listener on the "seeder-ended" event.
|
|
1201
|
+
*/
|
|
1202
|
+
static onSeederEnded(listener: (event: SeederEnded) => void, options?: ListenOptions): void;
|
|
1203
|
+
/**
|
|
1204
|
+
* Register a listener on the "seeding-ended" event.
|
|
1205
|
+
*/
|
|
1206
|
+
static onSeedingEnded(listener: (event: SeedingEnded) => void, options?: ListenOptions): void;
|
|
1207
|
+
/**
|
|
1208
|
+
* Start recording every query that runs.
|
|
1209
|
+
*/
|
|
1210
|
+
static enableQueryLog(): void;
|
|
1211
|
+
/**
|
|
1212
|
+
* Stop recording queries.
|
|
1213
|
+
*/
|
|
1214
|
+
static disableQueryLog(): void;
|
|
1215
|
+
/**
|
|
1216
|
+
* Get the recorded queries.
|
|
1217
|
+
*/
|
|
1218
|
+
static getQueryLog(): QueryLogEntry[];
|
|
1219
|
+
/**
|
|
1220
|
+
* Discard the recorded queries.
|
|
1221
|
+
*/
|
|
1222
|
+
static flushQueryLog(): void;
|
|
1223
|
+
/**
|
|
1224
|
+
* Determine whether queries are being recorded.
|
|
1225
|
+
*/
|
|
1226
|
+
static logging(): boolean;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
declare class Schema {
|
|
1230
|
+
#private;
|
|
1231
|
+
/**
|
|
1232
|
+
* Get the table names the database layer reserves for itself.
|
|
1233
|
+
*/
|
|
1234
|
+
static reserved(): string[];
|
|
1235
|
+
/**
|
|
1236
|
+
* Get a connection to read schema information from.
|
|
1237
|
+
*/
|
|
1238
|
+
static connection(name?: string): Connection;
|
|
1239
|
+
/**
|
|
1240
|
+
* Determine whether a table exists.
|
|
1241
|
+
*/
|
|
1242
|
+
static hasTable(table: string): Promise<boolean>;
|
|
1243
|
+
/**
|
|
1244
|
+
* Determine whether a table has a column.
|
|
1245
|
+
*/
|
|
1246
|
+
static hasColumn(table: string, column: string): Promise<boolean>;
|
|
1247
|
+
/**
|
|
1248
|
+
* Get the names of every table.
|
|
1249
|
+
*/
|
|
1250
|
+
static getTables(): Promise<string[]>;
|
|
1251
|
+
/**
|
|
1252
|
+
* Get the columns of a table.
|
|
1253
|
+
*/
|
|
1254
|
+
static getColumns(table: string): Promise<ColumnSchema[]>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Get the indexes of a table.
|
|
1257
|
+
*/
|
|
1258
|
+
static getIndexes(table: string): Promise<IndexSchema[]>;
|
|
1259
|
+
/**
|
|
1260
|
+
* Create a table.
|
|
1261
|
+
*/
|
|
1262
|
+
static create(table: string, callback: (table: Blueprint) => void): Promise<void>;
|
|
1263
|
+
/**
|
|
1264
|
+
* Alter a table.
|
|
1265
|
+
*/
|
|
1266
|
+
static table(table: string, callback: (table: Blueprint) => void): Promise<void>;
|
|
1267
|
+
/**
|
|
1268
|
+
* Drop a table.
|
|
1269
|
+
*/
|
|
1270
|
+
static drop(table: string): Promise<void>;
|
|
1271
|
+
/**
|
|
1272
|
+
* Drop a table, if it exists.
|
|
1273
|
+
*/
|
|
1274
|
+
static dropIfExists(table: string): Promise<void>;
|
|
1275
|
+
/**
|
|
1276
|
+
* Rename a table, copying every record into the new one.
|
|
1277
|
+
*/
|
|
1278
|
+
static rename(from: string, to: string): Promise<void>;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
declare class CheckConstraintViolationException extends Error {
|
|
1282
|
+
/**
|
|
1283
|
+
* Create a new exception for a value the column does not accept.
|
|
1284
|
+
*/
|
|
1285
|
+
constructor(table: string, column: string, value: unknown, accepted: string[]);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
declare class ConnectionNotConfiguredException extends Error {
|
|
1289
|
+
/**
|
|
1290
|
+
* Create a new exception for an unconfigured connection.
|
|
1291
|
+
*/
|
|
1292
|
+
constructor(connection: string);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
declare class DatabaseBlockedException extends Error {
|
|
1296
|
+
/**
|
|
1297
|
+
* Create a new exception for a database blocked by another connection.
|
|
1298
|
+
*/
|
|
1299
|
+
constructor(database: string);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
declare class MigrationMismatchException extends Error {
|
|
1303
|
+
/**
|
|
1304
|
+
* Create a new exception for a migration list that diverged from what has run.
|
|
1305
|
+
*/
|
|
1306
|
+
constructor(ran: string[], registered: string[]);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
declare class MigrationTransactionClosedException extends Error {
|
|
1310
|
+
/**
|
|
1311
|
+
* Create a new exception for a migration that outlived its transaction.
|
|
1312
|
+
*/
|
|
1313
|
+
constructor(migration: string);
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
declare class MultipleRecordsFoundException extends Error {
|
|
1317
|
+
/**
|
|
1318
|
+
* Create a new exception for a query that matched more records than it should.
|
|
1319
|
+
*/
|
|
1320
|
+
constructor(table: string);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
declare class NotNullConstraintViolationException extends Error {
|
|
1324
|
+
/**
|
|
1325
|
+
* Create a new exception for a null value in a non-nullable column.
|
|
1326
|
+
*/
|
|
1327
|
+
constructor(table: string, column: string);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
declare class QuotaExceededException extends Error {
|
|
1331
|
+
/**
|
|
1332
|
+
* Create a new exception for storage the browser refused to grant.
|
|
1333
|
+
*/
|
|
1334
|
+
constructor(message?: string);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
declare class RecordsNotFoundException extends Error {
|
|
1338
|
+
/**
|
|
1339
|
+
* Create a new exception for a query that matched no records.
|
|
1340
|
+
*/
|
|
1341
|
+
constructor(message?: string);
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
declare class ReservedTableException extends Error {
|
|
1345
|
+
/**
|
|
1346
|
+
* Create a new exception for a table name reserved by the database layer.
|
|
1347
|
+
*/
|
|
1348
|
+
constructor(table: string);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
declare class SchemaException extends Error {
|
|
1352
|
+
/**
|
|
1353
|
+
* Create a new exception for a failed schema operation.
|
|
1354
|
+
*/
|
|
1355
|
+
constructor(message?: string);
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
declare class TableNotFoundException extends Error {
|
|
1359
|
+
/**
|
|
1360
|
+
* Create a new exception for a missing table.
|
|
1361
|
+
*/
|
|
1362
|
+
constructor(table: string);
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
declare class UniqueConstraintViolationException extends Error {
|
|
1366
|
+
/**
|
|
1367
|
+
* Create a new exception for a violated unique index.
|
|
1368
|
+
*/
|
|
1369
|
+
constructor(table: string, index: string);
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
export { type Aggregated, type Aggregation, type Aggregations, Blueprint, Builder, CheckConstraintViolationException, ColumnDefinition, type ColumnSchema, type ColumnType, type Conjunction, Connection, type ConnectionConfig, ConnectionNotConfiguredException, type Constraint, DatabaseManager as DB, DatabaseBlocked, DatabaseBlockedException, type DatabaseConfig, type DatabaseEvent, type DatabaseEventListener, DatabaseManager, type DatePart, type Direction, type Enumerable, type FreshOptions, type Grouped, Grouping, type IndexSchema, Join, type JoinClause, type JoinCondition, type JoinType, type Key, type ListenOptions, Migration, type MigrationConstructor, MigrationEnded, MigrationMismatchException, MigrationStarted, type MigrationStatus, MigrationTransactionClosedException, MigrationsEnded, MigrationsStarted, MultipleRecordsFoundException, NoPendingMigrations, NotNullConstraintViolationException, type Operator, type Order, type Paginated, type Plan, type Projection, QueryExecuted, type QueryLogEntry, QuotaExceededException, RecordsNotFoundException, ReservedTableException, Schema, SchemaException, Seeder, type SeederConstructor, SeederEnded, SeederStarted, SeedingEnded, SeedingStarted, TableNotFoundException, type TableSchema, Transaction, TransactionBeginning, TransactionCommitted, type TransactionOptions, TransactionRolledBack, UniqueConstraintViolationException };
|