kysely 0.27.0 → 0.27.2
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 +2 -2
- package/dist/cjs/dialect/mssql/mssql-introspector.js +8 -6
- package/dist/cjs/expression/expression-wrapper.d.ts +13 -3
- package/dist/cjs/expression/expression-wrapper.js +12 -0
- package/dist/cjs/migration/migrator.d.ts +19 -2
- package/dist/cjs/migration/migrator.js +77 -43
- package/dist/cjs/operation-node/insert-query-node.d.ts +1 -0
- package/dist/cjs/operation-node/limit-node.d.ts +2 -3
- package/dist/cjs/operation-node/limit-node.js +1 -2
- package/dist/cjs/operation-node/offset-node.d.ts +2 -3
- package/dist/cjs/operation-node/offset-node.js +1 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +2 -0
- package/dist/cjs/operation-node/select-modifier-node.d.ts +2 -1
- package/dist/cjs/operation-node/select-modifier-node.js +2 -1
- package/dist/cjs/query-builder/aggregate-function-builder.d.ts +17 -0
- package/dist/cjs/query-builder/aggregate-function-builder.js +21 -0
- package/dist/cjs/query-builder/case-builder.d.ts +2 -2
- package/dist/cjs/query-builder/delete-query-builder.d.ts +5 -4
- package/dist/cjs/query-builder/delete-query-builder.js +4 -3
- package/dist/cjs/query-builder/function-module.d.ts +1 -1
- package/dist/cjs/query-builder/insert-query-builder.d.ts +9 -6
- package/dist/cjs/query-builder/insert-query-builder.js +173 -2
- package/dist/cjs/query-builder/json-path-builder.d.ts +2 -1
- package/dist/cjs/query-builder/json-path-builder.js +3 -0
- package/dist/cjs/query-builder/select-query-builder.d.ts +11 -9
- package/dist/cjs/query-builder/select-query-builder.js +12 -10
- package/dist/cjs/query-builder/update-query-builder.d.ts +5 -6
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +8 -0
- package/dist/cjs/raw-builder/raw-builder.d.ts +11 -1
- package/dist/cjs/raw-builder/raw-builder.js +3 -0
- package/dist/cjs/raw-builder/sql.js +9 -2
- package/dist/cjs/util/object-utils.d.ts +1 -1
- package/dist/cjs/util/object-utils.js +1 -1
- package/dist/esm/dialect/mssql/mssql-introspector.js +8 -6
- package/dist/esm/expression/expression-wrapper.d.ts +13 -3
- package/dist/esm/expression/expression-wrapper.js +12 -0
- package/dist/esm/migration/migrator.d.ts +19 -2
- package/dist/esm/migration/migrator.js +76 -42
- package/dist/esm/operation-node/insert-query-node.d.ts +1 -0
- package/dist/esm/operation-node/limit-node.d.ts +2 -3
- package/dist/esm/operation-node/limit-node.js +1 -2
- package/dist/esm/operation-node/offset-node.d.ts +2 -3
- package/dist/esm/operation-node/offset-node.js +1 -2
- package/dist/esm/operation-node/operation-node-transformer.js +2 -0
- package/dist/esm/operation-node/select-modifier-node.d.ts +2 -1
- package/dist/esm/operation-node/select-modifier-node.js +2 -1
- package/dist/esm/query-builder/aggregate-function-builder.d.ts +17 -0
- package/dist/esm/query-builder/aggregate-function-builder.js +21 -0
- package/dist/esm/query-builder/case-builder.d.ts +2 -2
- package/dist/esm/query-builder/delete-query-builder.d.ts +5 -4
- package/dist/esm/query-builder/delete-query-builder.js +4 -3
- package/dist/esm/query-builder/function-module.d.ts +1 -1
- package/dist/esm/query-builder/insert-query-builder.d.ts +9 -6
- package/dist/esm/query-builder/insert-query-builder.js +173 -2
- package/dist/esm/query-builder/json-path-builder.d.ts +2 -1
- package/dist/esm/query-builder/json-path-builder.js +3 -0
- package/dist/esm/query-builder/select-query-builder.d.ts +11 -9
- package/dist/esm/query-builder/select-query-builder.js +13 -11
- package/dist/esm/query-builder/update-query-builder.d.ts +5 -6
- package/dist/esm/query-builder/update-query-builder.js +2 -2
- package/dist/esm/query-compiler/default-query-compiler.js +8 -0
- package/dist/esm/raw-builder/raw-builder.d.ts +11 -1
- package/dist/esm/raw-builder/raw-builder.js +3 -0
- package/dist/esm/raw-builder/sql.js +9 -2
- package/dist/esm/util/object-utils.d.ts +1 -1
- package/dist/esm/util/object-utils.js +1 -1
- package/package.json +5 -11
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# [Kysely](https://kysely.dev)
|
|
14
14
|
|
|
15
15
|
Kysely (pronounce “Key-Seh-Lee”) is a type-safe and autocompletion-friendly typescript SQL query builder.
|
|
16
|
-
Inspired by [knex](http://knexjs.org/). Mainly developed for [node.js](https://nodejs.org/en/) but also
|
|
16
|
+
Inspired by [knex](http://knexjs.org/). Mainly developed for [node.js](https://nodejs.org/en/) but also
|
|
17
17
|
runs on all other javascript environments like [deno](https://deno.land/).
|
|
18
18
|
|
|
19
19
|

|
|
@@ -32,7 +32,7 @@ hatches for these situations. See the [sql template tag](https://kysely-org.gith
|
|
|
32
32
|
and the [DynamicModule](https://kysely-org.github.io/kysely-apidoc/classes/DynamicModule.html#ref) for more info.
|
|
33
33
|
|
|
34
34
|
All API documentation is written in the typing files and you can simply hover over the module, class
|
|
35
|
-
or method you're using to see it in your IDE. The same documentation is also hosted [here](https://github.
|
|
35
|
+
or method you're using to see it in your IDE. The same documentation is also hosted [here](https://kysely-org.github.io/kysely-apidoc/).
|
|
36
36
|
|
|
37
37
|
If you start using Kysely and can't find something you'd want to use, please open an issue or join our
|
|
38
38
|
[discord server](https://discord.gg/xyBJ3GwvAm).
|
|
@@ -67,12 +67,14 @@ class MssqlIntrospector {
|
|
|
67
67
|
const tableDictionary = {};
|
|
68
68
|
for (const rawColumn of rawColumns) {
|
|
69
69
|
const key = `${rawColumn.table_schema_name}.${rawColumn.table_name}`;
|
|
70
|
-
const table = (tableDictionary[key]
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
const table = (tableDictionary[key] =
|
|
71
|
+
tableDictionary[key] ||
|
|
72
|
+
(0, object_utils_js_1.freeze)({
|
|
73
|
+
columns: [],
|
|
74
|
+
isView: rawColumn.table_type === 'V ',
|
|
75
|
+
name: rawColumn.table_name,
|
|
76
|
+
schema: rawColumn.table_schema_name ?? undefined,
|
|
77
|
+
}));
|
|
76
78
|
table.columns.push((0, object_utils_js_1.freeze)({
|
|
77
79
|
dataType: rawColumn.type_name,
|
|
78
80
|
dataTypeSchema: rawColumn.type_schema_name ?? undefined,
|
|
@@ -243,7 +243,17 @@ export declare class ExpressionWrapper<DB, TB extends keyof DB, T> implements Al
|
|
|
243
243
|
* This method call doesn't change the SQL in any way. This methods simply
|
|
244
244
|
* returns a copy of this `ExpressionWrapper` with a new output type.
|
|
245
245
|
*/
|
|
246
|
-
$castTo<
|
|
246
|
+
$castTo<C>(): ExpressionWrapper<DB, TB, C>;
|
|
247
|
+
/**
|
|
248
|
+
* Omit null from the expression's type.
|
|
249
|
+
*
|
|
250
|
+
* This function can be useful in cases where you know an expression can't be
|
|
251
|
+
* null, but Kysely is unable to infer it.
|
|
252
|
+
*
|
|
253
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
254
|
+
* returns a copy of `this` with a new output type.
|
|
255
|
+
*/
|
|
256
|
+
$notNull(): ExpressionWrapper<DB, TB, Exclude<T, null>>;
|
|
247
257
|
/**
|
|
248
258
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
249
259
|
*
|
|
@@ -397,7 +407,7 @@ export declare class OrWrapper<DB, TB extends keyof DB, T extends SqlBool> imple
|
|
|
397
407
|
* This method call doesn't change the SQL in any way. This methods simply
|
|
398
408
|
* returns a copy of this `OrWrapper` with a new output type.
|
|
399
409
|
*/
|
|
400
|
-
$castTo<
|
|
410
|
+
$castTo<C extends SqlBool>(): OrWrapper<DB, TB, C>;
|
|
401
411
|
/**
|
|
402
412
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
403
413
|
*
|
|
@@ -533,7 +543,7 @@ export declare class AndWrapper<DB, TB extends keyof DB, T extends SqlBool> impl
|
|
|
533
543
|
* This method call doesn't change the SQL in any way. This methods simply
|
|
534
544
|
* returns a copy of this `AndWrapper` with a new output type.
|
|
535
545
|
*/
|
|
536
|
-
$castTo<
|
|
546
|
+
$castTo<C extends SqlBool>(): AndWrapper<DB, TB, C>;
|
|
537
547
|
/**
|
|
538
548
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
539
549
|
*
|
|
@@ -35,6 +35,18 @@ class ExpressionWrapper {
|
|
|
35
35
|
$castTo() {
|
|
36
36
|
return new ExpressionWrapper(this.#node);
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Omit null from the expression's type.
|
|
40
|
+
*
|
|
41
|
+
* This function can be useful in cases where you know an expression can't be
|
|
42
|
+
* null, but Kysely is unable to infer it.
|
|
43
|
+
*
|
|
44
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
45
|
+
* returns a copy of `this` with a new output type.
|
|
46
|
+
*/
|
|
47
|
+
$notNull() {
|
|
48
|
+
return new ExpressionWrapper(this.#node);
|
|
49
|
+
}
|
|
38
50
|
toOperationNode() {
|
|
39
51
|
return this.#node;
|
|
40
52
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Kysely } from '../kysely.js';
|
|
2
2
|
export declare const DEFAULT_MIGRATION_TABLE = "kysely_migration";
|
|
3
3
|
export declare const DEFAULT_MIGRATION_LOCK_TABLE = "kysely_migration_lock";
|
|
4
|
+
export declare const DEFAULT_ALLOW_UNORDERED_MIGRATIONS = false;
|
|
4
5
|
export declare const MIGRATION_LOCK_ID = "migration_lock";
|
|
5
6
|
export declare const NO_MIGRATIONS: NoMigrations;
|
|
6
7
|
export interface Migration {
|
|
@@ -58,7 +59,7 @@ export declare class Migrator {
|
|
|
58
59
|
* This method goes through all possible migrations provided by the provider and runs the
|
|
59
60
|
* ones whose names come alphabetically after the last migration that has been run. If the
|
|
60
61
|
* list of executed migrations doesn't match the beginning of the list of possible migrations
|
|
61
|
-
* an error is
|
|
62
|
+
* an error is returned.
|
|
62
63
|
*
|
|
63
64
|
* ### Examples
|
|
64
65
|
*
|
|
@@ -197,6 +198,20 @@ export interface MigratorProps {
|
|
|
197
198
|
* This only works on postgres.
|
|
198
199
|
*/
|
|
199
200
|
readonly migrationTableSchema?: string;
|
|
201
|
+
/**
|
|
202
|
+
* Enforces whether or not migrations must be run in alpha-numeric order.
|
|
203
|
+
*
|
|
204
|
+
* When false, migrations must be run in their exact alpha-numeric order.
|
|
205
|
+
* This is checked against the migrations already run in the database
|
|
206
|
+
* (`migrationTableName'). This ensures your migrations are always run in
|
|
207
|
+
* the same order and is the safest option.
|
|
208
|
+
*
|
|
209
|
+
* When true, migrations are still run in alpha-numeric order, but
|
|
210
|
+
* the order is not checked against already-run migrations in the database.
|
|
211
|
+
* Kysely will simply run all migrations that haven't run yet, in alpha-numeric
|
|
212
|
+
* order.
|
|
213
|
+
*/
|
|
214
|
+
readonly allowUnorderedMigrations?: boolean;
|
|
200
215
|
}
|
|
201
216
|
/**
|
|
202
217
|
* All migration methods ({@link Migrator.migrateTo | migrateTo},
|
|
@@ -231,12 +246,13 @@ export interface MigrationResultSet {
|
|
|
231
246
|
*/
|
|
232
247
|
readonly results?: MigrationResult[];
|
|
233
248
|
}
|
|
249
|
+
type MigrationDirection = 'Up' | 'Down';
|
|
234
250
|
export interface MigrationResult {
|
|
235
251
|
readonly migrationName: string;
|
|
236
252
|
/**
|
|
237
253
|
* The direction in which this migration was executed.
|
|
238
254
|
*/
|
|
239
|
-
readonly direction:
|
|
255
|
+
readonly direction: MigrationDirection;
|
|
240
256
|
/**
|
|
241
257
|
* The execution status.
|
|
242
258
|
*
|
|
@@ -293,3 +309,4 @@ export interface MigrationInfo {
|
|
|
293
309
|
*/
|
|
294
310
|
executedAt?: Date;
|
|
295
311
|
}
|
|
312
|
+
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Migrator = exports.NO_MIGRATIONS = exports.MIGRATION_LOCK_ID = exports.DEFAULT_MIGRATION_LOCK_TABLE = exports.DEFAULT_MIGRATION_TABLE = void 0;
|
|
3
|
+
exports.Migrator = exports.NO_MIGRATIONS = exports.MIGRATION_LOCK_ID = exports.DEFAULT_ALLOW_UNORDERED_MIGRATIONS = exports.DEFAULT_MIGRATION_LOCK_TABLE = exports.DEFAULT_MIGRATION_TABLE = void 0;
|
|
4
4
|
const noop_plugin_js_1 = require("../plugin/noop-plugin.js");
|
|
5
5
|
const with_schema_plugin_js_1 = require("../plugin/with-schema/with-schema-plugin.js");
|
|
6
6
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
7
7
|
exports.DEFAULT_MIGRATION_TABLE = 'kysely_migration';
|
|
8
8
|
exports.DEFAULT_MIGRATION_LOCK_TABLE = 'kysely_migration_lock';
|
|
9
|
+
exports.DEFAULT_ALLOW_UNORDERED_MIGRATIONS = false;
|
|
9
10
|
exports.MIGRATION_LOCK_ID = 'migration_lock';
|
|
10
11
|
exports.NO_MIGRATIONS = (0, object_utils_js_1.freeze)({ __noMigrations__: true });
|
|
11
12
|
/**
|
|
@@ -72,7 +73,7 @@ class Migrator {
|
|
|
72
73
|
* This method goes through all possible migrations provided by the provider and runs the
|
|
73
74
|
* ones whose names come alphabetically after the last migration that has been run. If the
|
|
74
75
|
* list of executed migrations doesn't match the beginning of the list of possible migrations
|
|
75
|
-
* an error is
|
|
76
|
+
* an error is returned.
|
|
76
77
|
*
|
|
77
78
|
* ### Examples
|
|
78
79
|
*
|
|
@@ -109,7 +110,7 @@ class Migrator {
|
|
|
109
110
|
* ```
|
|
110
111
|
*/
|
|
111
112
|
async migrateToLatest() {
|
|
112
|
-
return this.#migrate(({
|
|
113
|
+
return this.#migrate(() => ({ direction: 'Up', step: Infinity }));
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
116
|
* Migrate up/down to a specific migration.
|
|
@@ -135,15 +136,27 @@ class Migrator {
|
|
|
135
136
|
* ```
|
|
136
137
|
*/
|
|
137
138
|
async migrateTo(targetMigrationName) {
|
|
138
|
-
return this.#migrate(({ migrations }) => {
|
|
139
|
+
return this.#migrate(({ migrations, executedMigrations, pendingMigrations, }) => {
|
|
139
140
|
if (targetMigrationName === exports.NO_MIGRATIONS) {
|
|
140
|
-
return
|
|
141
|
+
return { direction: 'Down', step: Infinity };
|
|
141
142
|
}
|
|
142
|
-
|
|
143
|
-
if (index === -1) {
|
|
143
|
+
if (!migrations.find((m) => m.name === targetMigrationName)) {
|
|
144
144
|
throw new Error(`migration "${targetMigrationName}" doesn't exist`);
|
|
145
145
|
}
|
|
146
|
-
|
|
146
|
+
const executedIndex = executedMigrations.indexOf(targetMigrationName);
|
|
147
|
+
const pendingIndex = pendingMigrations.findIndex((m) => m.name === targetMigrationName);
|
|
148
|
+
if (executedIndex !== -1) {
|
|
149
|
+
return {
|
|
150
|
+
direction: 'Down',
|
|
151
|
+
step: executedMigrations.length - executedIndex - 1,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
else if (pendingIndex !== -1) {
|
|
155
|
+
return { direction: 'Up', step: pendingIndex + 1 };
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw new Error(`migration "${targetMigrationName}" isn't executed or pending`);
|
|
159
|
+
}
|
|
147
160
|
});
|
|
148
161
|
}
|
|
149
162
|
/**
|
|
@@ -161,7 +174,7 @@ class Migrator {
|
|
|
161
174
|
* ```
|
|
162
175
|
*/
|
|
163
176
|
async migrateUp() {
|
|
164
|
-
return this.#migrate((
|
|
177
|
+
return this.#migrate(() => ({ direction: 'Up', step: 1 }));
|
|
165
178
|
}
|
|
166
179
|
/**
|
|
167
180
|
* Migrate one step down.
|
|
@@ -178,12 +191,12 @@ class Migrator {
|
|
|
178
191
|
* ```
|
|
179
192
|
*/
|
|
180
193
|
async migrateDown() {
|
|
181
|
-
return this.#migrate((
|
|
194
|
+
return this.#migrate(() => ({ direction: 'Down', step: 1 }));
|
|
182
195
|
}
|
|
183
|
-
async #migrate(
|
|
196
|
+
async #migrate(getMigrationDirectionAndStep) {
|
|
184
197
|
try {
|
|
185
198
|
await this.#ensureMigrationTablesExists();
|
|
186
|
-
return await this.#runMigrations(
|
|
199
|
+
return await this.#runMigrations(getMigrationDirectionAndStep);
|
|
187
200
|
}
|
|
188
201
|
catch (error) {
|
|
189
202
|
if (error instanceof MigrationResultSetError) {
|
|
@@ -201,6 +214,9 @@ class Migrator {
|
|
|
201
214
|
get #migrationLockTable() {
|
|
202
215
|
return this.#props.migrationLockTableName ?? exports.DEFAULT_MIGRATION_LOCK_TABLE;
|
|
203
216
|
}
|
|
217
|
+
get #allowUnorderedMigrations() {
|
|
218
|
+
return (this.#props.allowUnorderedMigrations ?? exports.DEFAULT_ALLOW_UNORDERED_MIGRATIONS);
|
|
219
|
+
}
|
|
204
220
|
get #schemaPlugin() {
|
|
205
221
|
if (this.#migrationTableSchema) {
|
|
206
222
|
return new with_schema_plugin_js_1.WithSchemaPlugin(this.#migrationTableSchema);
|
|
@@ -311,7 +327,7 @@ class Migrator {
|
|
|
311
327
|
.executeTakeFirst();
|
|
312
328
|
return !!lockRow;
|
|
313
329
|
}
|
|
314
|
-
async #runMigrations(
|
|
330
|
+
async #runMigrations(getMigrationDirectionAndStep) {
|
|
315
331
|
const adapter = this.#props.db.getExecutor().adapter;
|
|
316
332
|
const lockOptions = (0, object_utils_js_1.freeze)({
|
|
317
333
|
lockTable: this.#props.migrationLockTableName ?? exports.DEFAULT_MIGRATION_LOCK_TABLE,
|
|
@@ -325,15 +341,15 @@ class Migrator {
|
|
|
325
341
|
if (state.migrations.length === 0) {
|
|
326
342
|
return { results: [] };
|
|
327
343
|
}
|
|
328
|
-
const
|
|
329
|
-
if (
|
|
344
|
+
const { direction, step } = getMigrationDirectionAndStep(state);
|
|
345
|
+
if (step <= 0) {
|
|
330
346
|
return { results: [] };
|
|
331
347
|
}
|
|
332
|
-
if (
|
|
333
|
-
return await this.#migrateDown(db, state,
|
|
348
|
+
if (direction === 'Down') {
|
|
349
|
+
return await this.#migrateDown(db, state, step);
|
|
334
350
|
}
|
|
335
|
-
else if (
|
|
336
|
-
return await this.#migrateUp(db, state,
|
|
351
|
+
else if (direction === 'Up') {
|
|
352
|
+
return await this.#migrateUp(db, state, step);
|
|
337
353
|
}
|
|
338
354
|
return { results: [] };
|
|
339
355
|
}
|
|
@@ -351,10 +367,21 @@ class Migrator {
|
|
|
351
367
|
async #getState(db) {
|
|
352
368
|
const migrations = await this.#resolveMigrations();
|
|
353
369
|
const executedMigrations = await this.#getExecutedMigrations(db);
|
|
354
|
-
this.#
|
|
370
|
+
this.#ensureNoMissingMigrations(migrations, executedMigrations);
|
|
371
|
+
if (!this.#allowUnorderedMigrations) {
|
|
372
|
+
this.#ensureMigrationsInOrder(migrations, executedMigrations);
|
|
373
|
+
}
|
|
374
|
+
const pendingMigrations = this.#getPendingMigrations(migrations, executedMigrations);
|
|
355
375
|
return (0, object_utils_js_1.freeze)({
|
|
356
376
|
migrations,
|
|
357
|
-
|
|
377
|
+
executedMigrations,
|
|
378
|
+
lastMigration: (0, object_utils_js_1.getLast)(executedMigrations),
|
|
379
|
+
pendingMigrations,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
#getPendingMigrations(migrations, executedMigrations) {
|
|
383
|
+
return migrations.filter((migration) => {
|
|
384
|
+
return !executedMigrations.includes(migration.name);
|
|
358
385
|
});
|
|
359
386
|
}
|
|
360
387
|
async #resolveMigrations() {
|
|
@@ -371,36 +398,43 @@ class Migrator {
|
|
|
371
398
|
.withPlugin(this.#schemaPlugin)
|
|
372
399
|
.selectFrom(this.#migrationTable)
|
|
373
400
|
.select('name')
|
|
374
|
-
.orderBy('name')
|
|
401
|
+
.orderBy(['timestamp', 'name'])
|
|
375
402
|
.execute();
|
|
376
403
|
return executedMigrations.map((it) => it.name);
|
|
377
404
|
}
|
|
378
|
-
#
|
|
405
|
+
#ensureNoMissingMigrations(migrations, executedMigrations) {
|
|
406
|
+
// Ensure all executed migrations exist in the `migrations` list.
|
|
379
407
|
for (const executed of executedMigrations) {
|
|
380
408
|
if (!migrations.some((it) => it.name === executed)) {
|
|
381
409
|
throw new Error(`corrupted migrations: previously executed migration ${executed} is missing`);
|
|
382
410
|
}
|
|
383
411
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
// ones in the migration list.
|
|
412
|
+
}
|
|
413
|
+
#ensureMigrationsInOrder(migrations, executedMigrations) {
|
|
414
|
+
// Ensure the executed migrations are the first ones in the migration list.
|
|
387
415
|
for (let i = 0; i < executedMigrations.length; ++i) {
|
|
388
416
|
if (migrations[i].name !== executedMigrations[i]) {
|
|
389
417
|
throw new Error(`corrupted migrations: expected previously executed migration ${executedMigrations[i]} to be at index ${i} but ${migrations[i].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`);
|
|
390
418
|
}
|
|
391
419
|
}
|
|
392
420
|
}
|
|
393
|
-
async #migrateDown(db, state,
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
421
|
+
async #migrateDown(db, state, step) {
|
|
422
|
+
const migrationsToRollback = state.executedMigrations
|
|
423
|
+
.slice()
|
|
424
|
+
.reverse()
|
|
425
|
+
.slice(0, step)
|
|
426
|
+
.map((name) => {
|
|
427
|
+
return state.migrations.find((it) => it.name === name);
|
|
428
|
+
});
|
|
429
|
+
const results = migrationsToRollback.map((migration) => {
|
|
430
|
+
return {
|
|
431
|
+
migrationName: migration.name,
|
|
398
432
|
direction: 'Down',
|
|
399
433
|
status: 'NotExecuted',
|
|
400
|
-
}
|
|
401
|
-
}
|
|
434
|
+
};
|
|
435
|
+
});
|
|
402
436
|
for (let i = 0; i < results.length; ++i) {
|
|
403
|
-
const migration =
|
|
437
|
+
const migration = migrationsToRollback[i];
|
|
404
438
|
try {
|
|
405
439
|
if (migration.down) {
|
|
406
440
|
await migration.down(db);
|
|
@@ -430,17 +464,17 @@ class Migrator {
|
|
|
430
464
|
}
|
|
431
465
|
return { results };
|
|
432
466
|
}
|
|
433
|
-
async #migrateUp(db, state,
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
migrationName:
|
|
467
|
+
async #migrateUp(db, state, step) {
|
|
468
|
+
const migrationsToRun = state.pendingMigrations.slice(0, step);
|
|
469
|
+
const results = migrationsToRun.map((migration) => {
|
|
470
|
+
return {
|
|
471
|
+
migrationName: migration.name,
|
|
438
472
|
direction: 'Up',
|
|
439
473
|
status: 'NotExecuted',
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
for (let i = 0; i < results.length; ++
|
|
443
|
-
const migration = state.
|
|
474
|
+
};
|
|
475
|
+
});
|
|
476
|
+
for (let i = 0; i < results.length; i++) {
|
|
477
|
+
const migration = state.pendingMigrations[i];
|
|
444
478
|
try {
|
|
445
479
|
await migration.up(db);
|
|
446
480
|
await db
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
-
import { ValueNode } from './value-node.js';
|
|
3
2
|
export interface LimitNode extends OperationNode {
|
|
4
3
|
readonly kind: 'LimitNode';
|
|
5
|
-
readonly limit:
|
|
4
|
+
readonly limit: OperationNode;
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
8
7
|
* @internal
|
|
9
8
|
*/
|
|
10
9
|
export declare const LimitNode: Readonly<{
|
|
11
10
|
is(node: OperationNode): node is LimitNode;
|
|
12
|
-
create(limit:
|
|
11
|
+
create(limit: OperationNode): LimitNode;
|
|
13
12
|
}>;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LimitNode = void 0;
|
|
4
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
-
const value_node_js_1 = require("./value-node.js");
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
@@ -13,7 +12,7 @@ exports.LimitNode = (0, object_utils_js_1.freeze)({
|
|
|
13
12
|
create(limit) {
|
|
14
13
|
return (0, object_utils_js_1.freeze)({
|
|
15
14
|
kind: 'LimitNode',
|
|
16
|
-
limit
|
|
15
|
+
limit,
|
|
17
16
|
});
|
|
18
17
|
},
|
|
19
18
|
});
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
-
import { ValueNode } from './value-node.js';
|
|
3
2
|
export interface OffsetNode extends OperationNode {
|
|
4
3
|
readonly kind: 'OffsetNode';
|
|
5
|
-
readonly offset:
|
|
4
|
+
readonly offset: OperationNode;
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
8
7
|
* @internal
|
|
9
8
|
*/
|
|
10
9
|
export declare const OffsetNode: Readonly<{
|
|
11
10
|
is(node: OperationNode): node is OffsetNode;
|
|
12
|
-
create(offset:
|
|
11
|
+
create(offset: OperationNode): OffsetNode;
|
|
13
12
|
}>;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OffsetNode = void 0;
|
|
4
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
-
const value_node_js_1 = require("./value-node.js");
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
@@ -13,7 +12,7 @@ exports.OffsetNode = (0, object_utils_js_1.freeze)({
|
|
|
13
12
|
create(offset) {
|
|
14
13
|
return (0, object_utils_js_1.freeze)({
|
|
15
14
|
kind: 'OffsetNode',
|
|
16
|
-
offset
|
|
15
|
+
offset,
|
|
17
16
|
});
|
|
18
17
|
},
|
|
19
18
|
});
|
|
@@ -259,6 +259,7 @@ class OperationNodeTransformer {
|
|
|
259
259
|
ignore: node.ignore,
|
|
260
260
|
replace: node.replace,
|
|
261
261
|
explain: this.transformNode(node.explain),
|
|
262
|
+
defaultValues: node.defaultValues,
|
|
262
263
|
});
|
|
263
264
|
}
|
|
264
265
|
transformValues(node) {
|
|
@@ -635,6 +636,7 @@ class OperationNodeTransformer {
|
|
|
635
636
|
kind: 'SelectModifierNode',
|
|
636
637
|
modifier: node.modifier,
|
|
637
638
|
rawModifier: this.transformNode(node.rawModifier),
|
|
639
|
+
of: this.transformNodeList(node.of),
|
|
638
640
|
});
|
|
639
641
|
}
|
|
640
642
|
transformCreateType(node) {
|
|
@@ -4,12 +4,13 @@ export interface SelectModifierNode extends OperationNode {
|
|
|
4
4
|
readonly kind: 'SelectModifierNode';
|
|
5
5
|
readonly modifier?: SelectModifier;
|
|
6
6
|
readonly rawModifier?: OperationNode;
|
|
7
|
+
readonly of?: ReadonlyArray<OperationNode>;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* @internal
|
|
10
11
|
*/
|
|
11
12
|
export declare const SelectModifierNode: Readonly<{
|
|
12
13
|
is(node: OperationNode): node is SelectModifierNode;
|
|
13
|
-
create(modifier: SelectModifier): SelectModifierNode;
|
|
14
|
+
create(modifier: SelectModifier, of?: ReadonlyArray<OperationNode>): SelectModifierNode;
|
|
14
15
|
createWithExpression(modifier: OperationNode): SelectModifierNode;
|
|
15
16
|
}>;
|
|
@@ -9,10 +9,11 @@ exports.SelectModifierNode = (0, object_utils_js_1.freeze)({
|
|
|
9
9
|
is(node) {
|
|
10
10
|
return node.kind === 'SelectModifierNode';
|
|
11
11
|
},
|
|
12
|
-
create(modifier) {
|
|
12
|
+
create(modifier, of) {
|
|
13
13
|
return (0, object_utils_js_1.freeze)({
|
|
14
14
|
kind: 'SelectModifierNode',
|
|
15
15
|
modifier,
|
|
16
|
+
of,
|
|
16
17
|
});
|
|
17
18
|
},
|
|
18
19
|
createWithExpression(modifier) {
|
|
@@ -199,6 +199,23 @@ export declare class AggregateFunctionBuilder<DB, TB extends keyof DB, O = unkno
|
|
|
199
199
|
* what the provided function returns.
|
|
200
200
|
*/
|
|
201
201
|
$call<T>(func: (qb: this) => T): T;
|
|
202
|
+
/**
|
|
203
|
+
* Casts the expression to the given type.
|
|
204
|
+
*
|
|
205
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
206
|
+
* returns a copy of this `AggregateFunctionBuilder` with a new output type.
|
|
207
|
+
*/
|
|
208
|
+
$castTo<C>(): AggregateFunctionBuilder<DB, TB, C>;
|
|
209
|
+
/**
|
|
210
|
+
* Omit null from the expression's type.
|
|
211
|
+
*
|
|
212
|
+
* This function can be useful in cases where you know an expression can't be
|
|
213
|
+
* null, but Kysely is unable to infer it.
|
|
214
|
+
*
|
|
215
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
216
|
+
* returns a copy of `this` with a new output type.
|
|
217
|
+
*/
|
|
218
|
+
$notNull(): AggregateFunctionBuilder<DB, TB, Exclude<O, null>>;
|
|
202
219
|
/**
|
|
203
220
|
* Creates the OperationNode that describes how to compile this expression into SQL.
|
|
204
221
|
*
|
|
@@ -172,6 +172,27 @@ class AggregateFunctionBuilder {
|
|
|
172
172
|
$call(func) {
|
|
173
173
|
return func(this);
|
|
174
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Casts the expression to the given type.
|
|
177
|
+
*
|
|
178
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
179
|
+
* returns a copy of this `AggregateFunctionBuilder` with a new output type.
|
|
180
|
+
*/
|
|
181
|
+
$castTo() {
|
|
182
|
+
return new AggregateFunctionBuilder(this.#props);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Omit null from the expression's type.
|
|
186
|
+
*
|
|
187
|
+
* This function can be useful in cases where you know an expression can't be
|
|
188
|
+
* null, but Kysely is unable to infer it.
|
|
189
|
+
*
|
|
190
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
191
|
+
* returns a copy of `this` with a new output type.
|
|
192
|
+
*/
|
|
193
|
+
$notNull() {
|
|
194
|
+
return new AggregateFunctionBuilder(this.#props);
|
|
195
|
+
}
|
|
175
196
|
toOperationNode() {
|
|
176
197
|
return this.#props.aggregateFunctionNode;
|
|
177
198
|
}
|
|
@@ -29,7 +29,7 @@ export declare class CaseThenBuilder<DB, TB extends keyof DB, W, O> {
|
|
|
29
29
|
* A `then` call can be followed by {@link Whenable.when}, {@link CaseWhenBuilder.else},
|
|
30
30
|
* {@link CaseWhenBuilder.end} or {@link CaseWhenBuilder.endCase} call.
|
|
31
31
|
*/
|
|
32
|
-
then<E extends Expression<
|
|
32
|
+
then<E extends Expression<unknown>>(expression: E): CaseWhenBuilder<DB, TB, W, O | ExtractTypeFromValueExpression<E>>;
|
|
33
33
|
then<V>(value: V): CaseWhenBuilder<DB, TB, W, O | V>;
|
|
34
34
|
}
|
|
35
35
|
export declare class CaseWhenBuilder<DB, TB extends keyof DB, W, O> implements Whenable<DB, TB, W, O>, Endable<DB, TB, O | null> {
|
|
@@ -48,7 +48,7 @@ export declare class CaseWhenBuilder<DB, TB extends keyof DB, W, O> implements W
|
|
|
48
48
|
*
|
|
49
49
|
* An `else` call must be followed by an {@link Endable.end} or {@link Endable.endCase} call.
|
|
50
50
|
*/
|
|
51
|
-
else<
|
|
51
|
+
else<E extends Expression<unknown>>(expression: E): CaseEndBuilder<DB, TB, O | ExtractTypeFromValueExpression<E>>;
|
|
52
52
|
else<V>(value: V): CaseEndBuilder<DB, TB, O | V>;
|
|
53
53
|
/**
|
|
54
54
|
* Adds an `end` keyword to the case operator.
|
|
@@ -23,6 +23,7 @@ import { ComparisonOperatorExpression, OperandValueExpressionOrList } from '../p
|
|
|
23
23
|
import { KyselyTypeError } from '../util/type-error.js';
|
|
24
24
|
import { Streamable } from '../util/streamable.js';
|
|
25
25
|
import { ExpressionOrFactory } from '../parser/expression-parser.js';
|
|
26
|
+
import { ValueExpression } from '../parser/value-parser.js';
|
|
26
27
|
export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable<O>, Explainable, Streamable<O> {
|
|
27
28
|
#private;
|
|
28
29
|
constructor(props: DeleteQueryBuilderProps);
|
|
@@ -814,7 +815,7 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
814
815
|
* .execute()
|
|
815
816
|
* ```
|
|
816
817
|
*/
|
|
817
|
-
limit(limit: number): DeleteQueryBuilder<DB, TB, O>;
|
|
818
|
+
limit(limit: ValueExpression<DB, TB, number>): DeleteQueryBuilder<DB, TB, O>;
|
|
818
819
|
/**
|
|
819
820
|
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
|
820
821
|
* what the provided function returns.
|
|
@@ -877,10 +878,10 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
877
878
|
/**
|
|
878
879
|
* Change the output type of the query.
|
|
879
880
|
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
881
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
882
|
+
* returns a copy of this `DeleteQueryBuilder` with a new output type.
|
|
882
883
|
*/
|
|
883
|
-
$castTo<
|
|
884
|
+
$castTo<C>(): DeleteQueryBuilder<DB, TB, C>;
|
|
884
885
|
/**
|
|
885
886
|
* Narrows (parts of) the output type of the query.
|
|
886
887
|
*
|
|
@@ -13,6 +13,7 @@ const delete_query_node_js_1 = require("../operation-node/delete-query-node.js")
|
|
|
13
13
|
const limit_node_js_1 = require("../operation-node/limit-node.js");
|
|
14
14
|
const order_by_parser_js_1 = require("../parser/order-by-parser.js");
|
|
15
15
|
const binary_operation_parser_js_1 = require("../parser/binary-operation-parser.js");
|
|
16
|
+
const value_parser_js_1 = require("../parser/value-parser.js");
|
|
16
17
|
class DeleteQueryBuilder {
|
|
17
18
|
#props;
|
|
18
19
|
constructor(props) {
|
|
@@ -139,7 +140,7 @@ class DeleteQueryBuilder {
|
|
|
139
140
|
limit(limit) {
|
|
140
141
|
return new DeleteQueryBuilder({
|
|
141
142
|
...this.#props,
|
|
142
|
-
queryNode: delete_query_node_js_1.DeleteQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create(limit)),
|
|
143
|
+
queryNode: delete_query_node_js_1.DeleteQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create((0, value_parser_js_1.parseValueExpression)(limit))),
|
|
143
144
|
});
|
|
144
145
|
}
|
|
145
146
|
/**
|
|
@@ -213,8 +214,8 @@ class DeleteQueryBuilder {
|
|
|
213
214
|
/**
|
|
214
215
|
* Change the output type of the query.
|
|
215
216
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
217
|
+
* This method call doesn't change the SQL in any way. This methods simply
|
|
218
|
+
* returns a copy of this `DeleteQueryBuilder` with a new output type.
|
|
218
219
|
*/
|
|
219
220
|
$castTo() {
|
|
220
221
|
return new DeleteQueryBuilder(this.#props);
|