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.
Files changed (68) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/dialect/mssql/mssql-introspector.js +8 -6
  3. package/dist/cjs/expression/expression-wrapper.d.ts +13 -3
  4. package/dist/cjs/expression/expression-wrapper.js +12 -0
  5. package/dist/cjs/migration/migrator.d.ts +19 -2
  6. package/dist/cjs/migration/migrator.js +77 -43
  7. package/dist/cjs/operation-node/insert-query-node.d.ts +1 -0
  8. package/dist/cjs/operation-node/limit-node.d.ts +2 -3
  9. package/dist/cjs/operation-node/limit-node.js +1 -2
  10. package/dist/cjs/operation-node/offset-node.d.ts +2 -3
  11. package/dist/cjs/operation-node/offset-node.js +1 -2
  12. package/dist/cjs/operation-node/operation-node-transformer.js +2 -0
  13. package/dist/cjs/operation-node/select-modifier-node.d.ts +2 -1
  14. package/dist/cjs/operation-node/select-modifier-node.js +2 -1
  15. package/dist/cjs/query-builder/aggregate-function-builder.d.ts +17 -0
  16. package/dist/cjs/query-builder/aggregate-function-builder.js +21 -0
  17. package/dist/cjs/query-builder/case-builder.d.ts +2 -2
  18. package/dist/cjs/query-builder/delete-query-builder.d.ts +5 -4
  19. package/dist/cjs/query-builder/delete-query-builder.js +4 -3
  20. package/dist/cjs/query-builder/function-module.d.ts +1 -1
  21. package/dist/cjs/query-builder/insert-query-builder.d.ts +9 -6
  22. package/dist/cjs/query-builder/insert-query-builder.js +173 -2
  23. package/dist/cjs/query-builder/json-path-builder.d.ts +2 -1
  24. package/dist/cjs/query-builder/json-path-builder.js +3 -0
  25. package/dist/cjs/query-builder/select-query-builder.d.ts +11 -9
  26. package/dist/cjs/query-builder/select-query-builder.js +12 -10
  27. package/dist/cjs/query-builder/update-query-builder.d.ts +5 -6
  28. package/dist/cjs/query-builder/update-query-builder.js +2 -2
  29. package/dist/cjs/query-compiler/default-query-compiler.js +8 -0
  30. package/dist/cjs/raw-builder/raw-builder.d.ts +11 -1
  31. package/dist/cjs/raw-builder/raw-builder.js +3 -0
  32. package/dist/cjs/raw-builder/sql.js +9 -2
  33. package/dist/cjs/util/object-utils.d.ts +1 -1
  34. package/dist/cjs/util/object-utils.js +1 -1
  35. package/dist/esm/dialect/mssql/mssql-introspector.js +8 -6
  36. package/dist/esm/expression/expression-wrapper.d.ts +13 -3
  37. package/dist/esm/expression/expression-wrapper.js +12 -0
  38. package/dist/esm/migration/migrator.d.ts +19 -2
  39. package/dist/esm/migration/migrator.js +76 -42
  40. package/dist/esm/operation-node/insert-query-node.d.ts +1 -0
  41. package/dist/esm/operation-node/limit-node.d.ts +2 -3
  42. package/dist/esm/operation-node/limit-node.js +1 -2
  43. package/dist/esm/operation-node/offset-node.d.ts +2 -3
  44. package/dist/esm/operation-node/offset-node.js +1 -2
  45. package/dist/esm/operation-node/operation-node-transformer.js +2 -0
  46. package/dist/esm/operation-node/select-modifier-node.d.ts +2 -1
  47. package/dist/esm/operation-node/select-modifier-node.js +2 -1
  48. package/dist/esm/query-builder/aggregate-function-builder.d.ts +17 -0
  49. package/dist/esm/query-builder/aggregate-function-builder.js +21 -0
  50. package/dist/esm/query-builder/case-builder.d.ts +2 -2
  51. package/dist/esm/query-builder/delete-query-builder.d.ts +5 -4
  52. package/dist/esm/query-builder/delete-query-builder.js +4 -3
  53. package/dist/esm/query-builder/function-module.d.ts +1 -1
  54. package/dist/esm/query-builder/insert-query-builder.d.ts +9 -6
  55. package/dist/esm/query-builder/insert-query-builder.js +173 -2
  56. package/dist/esm/query-builder/json-path-builder.d.ts +2 -1
  57. package/dist/esm/query-builder/json-path-builder.js +3 -0
  58. package/dist/esm/query-builder/select-query-builder.d.ts +11 -9
  59. package/dist/esm/query-builder/select-query-builder.js +13 -11
  60. package/dist/esm/query-builder/update-query-builder.d.ts +5 -6
  61. package/dist/esm/query-builder/update-query-builder.js +2 -2
  62. package/dist/esm/query-compiler/default-query-compiler.js +8 -0
  63. package/dist/esm/raw-builder/raw-builder.d.ts +11 -1
  64. package/dist/esm/raw-builder/raw-builder.js +3 -0
  65. package/dist/esm/raw-builder/sql.js +9 -2
  66. package/dist/esm/util/object-utils.d.ts +1 -1
  67. package/dist/esm/util/object-utils.js +1 -1
  68. package/package.json +5 -11
@@ -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 thrown.
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: 'Up' | 'Down';
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 {};
@@ -4,6 +4,7 @@ import { WithSchemaPlugin } from '../plugin/with-schema/with-schema-plugin.js';
4
4
  import { freeze, getLast } from '../util/object-utils.js';
5
5
  export const DEFAULT_MIGRATION_TABLE = 'kysely_migration';
6
6
  export const DEFAULT_MIGRATION_LOCK_TABLE = 'kysely_migration_lock';
7
+ export const DEFAULT_ALLOW_UNORDERED_MIGRATIONS = false;
7
8
  export const MIGRATION_LOCK_ID = 'migration_lock';
8
9
  export const NO_MIGRATIONS = freeze({ __noMigrations__: true });
9
10
  /**
@@ -70,7 +71,7 @@ export class Migrator {
70
71
  * This method goes through all possible migrations provided by the provider and runs the
71
72
  * ones whose names come alphabetically after the last migration that has been run. If the
72
73
  * list of executed migrations doesn't match the beginning of the list of possible migrations
73
- * an error is thrown.
74
+ * an error is returned.
74
75
  *
75
76
  * ### Examples
76
77
  *
@@ -107,7 +108,7 @@ export class Migrator {
107
108
  * ```
108
109
  */
109
110
  async migrateToLatest() {
110
- return this.#migrate(({ migrations }) => migrations.length - 1);
111
+ return this.#migrate(() => ({ direction: 'Up', step: Infinity }));
111
112
  }
112
113
  /**
113
114
  * Migrate up/down to a specific migration.
@@ -133,15 +134,27 @@ export class Migrator {
133
134
  * ```
134
135
  */
135
136
  async migrateTo(targetMigrationName) {
136
- return this.#migrate(({ migrations }) => {
137
+ return this.#migrate(({ migrations, executedMigrations, pendingMigrations, }) => {
137
138
  if (targetMigrationName === NO_MIGRATIONS) {
138
- return -1;
139
+ return { direction: 'Down', step: Infinity };
139
140
  }
140
- const index = migrations.findIndex((it) => it.name === targetMigrationName);
141
- if (index === -1) {
141
+ if (!migrations.find((m) => m.name === targetMigrationName)) {
142
142
  throw new Error(`migration "${targetMigrationName}" doesn't exist`);
143
143
  }
144
- return index;
144
+ const executedIndex = executedMigrations.indexOf(targetMigrationName);
145
+ const pendingIndex = pendingMigrations.findIndex((m) => m.name === targetMigrationName);
146
+ if (executedIndex !== -1) {
147
+ return {
148
+ direction: 'Down',
149
+ step: executedMigrations.length - executedIndex - 1,
150
+ };
151
+ }
152
+ else if (pendingIndex !== -1) {
153
+ return { direction: 'Up', step: pendingIndex + 1 };
154
+ }
155
+ else {
156
+ throw new Error(`migration "${targetMigrationName}" isn't executed or pending`);
157
+ }
145
158
  });
146
159
  }
147
160
  /**
@@ -159,7 +172,7 @@ export class Migrator {
159
172
  * ```
160
173
  */
161
174
  async migrateUp() {
162
- return this.#migrate(({ currentIndex, migrations }) => Math.min(currentIndex + 1, migrations.length - 1));
175
+ return this.#migrate(() => ({ direction: 'Up', step: 1 }));
163
176
  }
164
177
  /**
165
178
  * Migrate one step down.
@@ -176,12 +189,12 @@ export class Migrator {
176
189
  * ```
177
190
  */
178
191
  async migrateDown() {
179
- return this.#migrate(({ currentIndex }) => Math.max(currentIndex - 1, -1));
192
+ return this.#migrate(() => ({ direction: 'Down', step: 1 }));
180
193
  }
181
- async #migrate(getTargetMigrationIndex) {
194
+ async #migrate(getMigrationDirectionAndStep) {
182
195
  try {
183
196
  await this.#ensureMigrationTablesExists();
184
- return await this.#runMigrations(getTargetMigrationIndex);
197
+ return await this.#runMigrations(getMigrationDirectionAndStep);
185
198
  }
186
199
  catch (error) {
187
200
  if (error instanceof MigrationResultSetError) {
@@ -199,6 +212,9 @@ export class Migrator {
199
212
  get #migrationLockTable() {
200
213
  return this.#props.migrationLockTableName ?? DEFAULT_MIGRATION_LOCK_TABLE;
201
214
  }
215
+ get #allowUnorderedMigrations() {
216
+ return (this.#props.allowUnorderedMigrations ?? DEFAULT_ALLOW_UNORDERED_MIGRATIONS);
217
+ }
202
218
  get #schemaPlugin() {
203
219
  if (this.#migrationTableSchema) {
204
220
  return new WithSchemaPlugin(this.#migrationTableSchema);
@@ -309,7 +325,7 @@ export class Migrator {
309
325
  .executeTakeFirst();
310
326
  return !!lockRow;
311
327
  }
312
- async #runMigrations(getTargetMigrationIndex) {
328
+ async #runMigrations(getMigrationDirectionAndStep) {
313
329
  const adapter = this.#props.db.getExecutor().adapter;
314
330
  const lockOptions = freeze({
315
331
  lockTable: this.#props.migrationLockTableName ?? DEFAULT_MIGRATION_LOCK_TABLE,
@@ -323,15 +339,15 @@ export class Migrator {
323
339
  if (state.migrations.length === 0) {
324
340
  return { results: [] };
325
341
  }
326
- const targetIndex = getTargetMigrationIndex(state);
327
- if (targetIndex === undefined) {
342
+ const { direction, step } = getMigrationDirectionAndStep(state);
343
+ if (step <= 0) {
328
344
  return { results: [] };
329
345
  }
330
- if (targetIndex < state.currentIndex) {
331
- return await this.#migrateDown(db, state, targetIndex);
346
+ if (direction === 'Down') {
347
+ return await this.#migrateDown(db, state, step);
332
348
  }
333
- else if (targetIndex > state.currentIndex) {
334
- return await this.#migrateUp(db, state, targetIndex);
349
+ else if (direction === 'Up') {
350
+ return await this.#migrateUp(db, state, step);
335
351
  }
336
352
  return { results: [] };
337
353
  }
@@ -349,10 +365,21 @@ export class Migrator {
349
365
  async #getState(db) {
350
366
  const migrations = await this.#resolveMigrations();
351
367
  const executedMigrations = await this.#getExecutedMigrations(db);
352
- this.#ensureMigrationsNotCorrupted(migrations, executedMigrations);
368
+ this.#ensureNoMissingMigrations(migrations, executedMigrations);
369
+ if (!this.#allowUnorderedMigrations) {
370
+ this.#ensureMigrationsInOrder(migrations, executedMigrations);
371
+ }
372
+ const pendingMigrations = this.#getPendingMigrations(migrations, executedMigrations);
353
373
  return freeze({
354
374
  migrations,
355
- currentIndex: migrations.findIndex((it) => it.name === getLast(executedMigrations)),
375
+ executedMigrations,
376
+ lastMigration: getLast(executedMigrations),
377
+ pendingMigrations,
378
+ });
379
+ }
380
+ #getPendingMigrations(migrations, executedMigrations) {
381
+ return migrations.filter((migration) => {
382
+ return !executedMigrations.includes(migration.name);
356
383
  });
357
384
  }
358
385
  async #resolveMigrations() {
@@ -369,36 +396,43 @@ export class Migrator {
369
396
  .withPlugin(this.#schemaPlugin)
370
397
  .selectFrom(this.#migrationTable)
371
398
  .select('name')
372
- .orderBy('name')
399
+ .orderBy(['timestamp', 'name'])
373
400
  .execute();
374
401
  return executedMigrations.map((it) => it.name);
375
402
  }
376
- #ensureMigrationsNotCorrupted(migrations, executedMigrations) {
403
+ #ensureNoMissingMigrations(migrations, executedMigrations) {
404
+ // Ensure all executed migrations exist in the `migrations` list.
377
405
  for (const executed of executedMigrations) {
378
406
  if (!migrations.some((it) => it.name === executed)) {
379
407
  throw new Error(`corrupted migrations: previously executed migration ${executed} is missing`);
380
408
  }
381
409
  }
382
- // Now we know all executed migrations exist in the `migrations` list.
383
- // Next we need to make sure that the executed migratiosns are the first
384
- // ones in the migration list.
410
+ }
411
+ #ensureMigrationsInOrder(migrations, executedMigrations) {
412
+ // Ensure the executed migrations are the first ones in the migration list.
385
413
  for (let i = 0; i < executedMigrations.length; ++i) {
386
414
  if (migrations[i].name !== executedMigrations[i]) {
387
415
  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.`);
388
416
  }
389
417
  }
390
418
  }
391
- async #migrateDown(db, state, targetIndex) {
392
- const results = [];
393
- for (let i = state.currentIndex; i > targetIndex; --i) {
394
- results.push({
395
- migrationName: state.migrations[i].name,
419
+ async #migrateDown(db, state, step) {
420
+ const migrationsToRollback = state.executedMigrations
421
+ .slice()
422
+ .reverse()
423
+ .slice(0, step)
424
+ .map((name) => {
425
+ return state.migrations.find((it) => it.name === name);
426
+ });
427
+ const results = migrationsToRollback.map((migration) => {
428
+ return {
429
+ migrationName: migration.name,
396
430
  direction: 'Down',
397
431
  status: 'NotExecuted',
398
- });
399
- }
432
+ };
433
+ });
400
434
  for (let i = 0; i < results.length; ++i) {
401
- const migration = state.migrations.find((it) => it.name === results[i].migrationName);
435
+ const migration = migrationsToRollback[i];
402
436
  try {
403
437
  if (migration.down) {
404
438
  await migration.down(db);
@@ -428,17 +462,17 @@ export class Migrator {
428
462
  }
429
463
  return { results };
430
464
  }
431
- async #migrateUp(db, state, targetIndex) {
432
- const results = [];
433
- for (let i = state.currentIndex + 1; i <= targetIndex; ++i) {
434
- results.push({
435
- migrationName: state.migrations[i].name,
465
+ async #migrateUp(db, state, step) {
466
+ const migrationsToRun = state.pendingMigrations.slice(0, step);
467
+ const results = migrationsToRun.map((migration) => {
468
+ return {
469
+ migrationName: migration.name,
436
470
  direction: 'Up',
437
471
  status: 'NotExecuted',
438
- });
439
- }
440
- for (let i = 0; i < results.length; ++i) {
441
- const migration = state.migrations.find((it) => it.name === results[i].migrationName);
472
+ };
473
+ });
474
+ for (let i = 0; i < results.length; i++) {
475
+ const migration = state.pendingMigrations[i];
442
476
  try {
443
477
  await migration.up(db);
444
478
  await db
@@ -19,6 +19,7 @@ export interface InsertQueryNode extends OperationNode {
19
19
  readonly ignore?: boolean;
20
20
  readonly replace?: boolean;
21
21
  readonly explain?: ExplainNode;
22
+ readonly defaultValues?: boolean;
22
23
  }
23
24
  /**
24
25
  * @internal
@@ -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: ValueNode;
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: number): LimitNode;
11
+ create(limit: OperationNode): LimitNode;
13
12
  }>;
@@ -1,6 +1,5 @@
1
1
  /// <reference types="./limit-node.d.ts" />
2
2
  import { freeze } from '../util/object-utils.js';
3
- import { ValueNode } from './value-node.js';
4
3
  /**
5
4
  * @internal
6
5
  */
@@ -11,7 +10,7 @@ export const LimitNode = freeze({
11
10
  create(limit) {
12
11
  return freeze({
13
12
  kind: 'LimitNode',
14
- limit: ValueNode.create(limit),
13
+ limit,
15
14
  });
16
15
  },
17
16
  });
@@ -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: ValueNode;
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: number): OffsetNode;
11
+ create(offset: OperationNode): OffsetNode;
13
12
  }>;
@@ -1,6 +1,5 @@
1
1
  /// <reference types="./offset-node.d.ts" />
2
2
  import { freeze } from '../util/object-utils.js';
3
- import { ValueNode } from './value-node.js';
4
3
  /**
5
4
  * @internal
6
5
  */
@@ -11,7 +10,7 @@ export const OffsetNode = freeze({
11
10
  create(offset) {
12
11
  return freeze({
13
12
  kind: 'OffsetNode',
14
- offset: ValueNode.create(offset),
13
+ offset,
15
14
  });
16
15
  },
17
16
  });
@@ -257,6 +257,7 @@ export class OperationNodeTransformer {
257
257
  ignore: node.ignore,
258
258
  replace: node.replace,
259
259
  explain: this.transformNode(node.explain),
260
+ defaultValues: node.defaultValues,
260
261
  });
261
262
  }
262
263
  transformValues(node) {
@@ -633,6 +634,7 @@ export class OperationNodeTransformer {
633
634
  kind: 'SelectModifierNode',
634
635
  modifier: node.modifier,
635
636
  rawModifier: this.transformNode(node.rawModifier),
637
+ of: this.transformNodeList(node.of),
636
638
  });
637
639
  }
638
640
  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
  }>;
@@ -7,10 +7,11 @@ export const SelectModifierNode = freeze({
7
7
  is(node) {
8
8
  return node.kind === 'SelectModifierNode';
9
9
  },
10
- create(modifier) {
10
+ create(modifier, of) {
11
11
  return freeze({
12
12
  kind: 'SelectModifierNode',
13
13
  modifier,
14
+ of,
14
15
  });
15
16
  },
16
17
  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
  *
@@ -170,6 +170,27 @@ export class AggregateFunctionBuilder {
170
170
  $call(func) {
171
171
  return func(this);
172
172
  }
173
+ /**
174
+ * Casts the expression to the given type.
175
+ *
176
+ * This method call doesn't change the SQL in any way. This methods simply
177
+ * returns a copy of this `AggregateFunctionBuilder` with a new output type.
178
+ */
179
+ $castTo() {
180
+ return new AggregateFunctionBuilder(this.#props);
181
+ }
182
+ /**
183
+ * Omit null from the expression's type.
184
+ *
185
+ * This function can be useful in cases where you know an expression can't be
186
+ * null, but Kysely is unable to infer it.
187
+ *
188
+ * This method call doesn't change the SQL in any way. This methods simply
189
+ * returns a copy of `this` with a new output type.
190
+ */
191
+ $notNull() {
192
+ return new AggregateFunctionBuilder(this.#props);
193
+ }
173
194
  toOperationNode() {
174
195
  return this.#props.aggregateFunctionNode;
175
196
  }
@@ -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<any>>(expression: E): CaseWhenBuilder<DB, TB, W, O | ExtractTypeFromValueExpression<E>>;
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<O2>(expression: Expression<O2>): CaseEndBuilder<DB, TB, O | O2>;
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
- * You should only use this method as the last resort if the types
881
- * don't support your use case.
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<T>(): DeleteQueryBuilder<DB, TB, T>;
884
+ $castTo<C>(): DeleteQueryBuilder<DB, TB, C>;
884
885
  /**
885
886
  * Narrows (parts of) the output type of the query.
886
887
  *
@@ -11,6 +11,7 @@ import { DeleteQueryNode } from '../operation-node/delete-query-node.js';
11
11
  import { LimitNode } from '../operation-node/limit-node.js';
12
12
  import { parseOrderBy, } from '../parser/order-by-parser.js';
13
13
  import { parseValueBinaryOperationOrExpression, parseReferentialBinaryOperation, } from '../parser/binary-operation-parser.js';
14
+ import { parseValueExpression, } from '../parser/value-parser.js';
14
15
  export class DeleteQueryBuilder {
15
16
  #props;
16
17
  constructor(props) {
@@ -137,7 +138,7 @@ export class DeleteQueryBuilder {
137
138
  limit(limit) {
138
139
  return new DeleteQueryBuilder({
139
140
  ...this.#props,
140
- queryNode: DeleteQueryNode.cloneWithLimit(this.#props.queryNode, LimitNode.create(limit)),
141
+ queryNode: DeleteQueryNode.cloneWithLimit(this.#props.queryNode, LimitNode.create(parseValueExpression(limit))),
141
142
  });
142
143
  }
143
144
  /**
@@ -211,8 +212,8 @@ export class DeleteQueryBuilder {
211
212
  /**
212
213
  * Change the output type of the query.
213
214
  *
214
- * You should only use this method as the last resort if the types
215
- * don't support your use case.
215
+ * This method call doesn't change the SQL in any way. This methods simply
216
+ * returns a copy of this `DeleteQueryBuilder` with a new output type.
216
217
  */
217
218
  $castTo() {
218
219
  return new DeleteQueryBuilder(this.#props);
@@ -138,7 +138,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
138
138
  * from "person"
139
139
  * ```
140
140
  */
141
- agg<O, RE extends ReferenceExpression<DB, TB>>(name: string, args?: ReadonlyArray<RE>): AggregateFunctionBuilder<DB, TB, O>;
141
+ agg<O, RE extends ReferenceExpression<DB, TB> = ReferenceExpression<DB, TB>>(name: string, args?: ReadonlyArray<RE>): AggregateFunctionBuilder<DB, TB, O>;
142
142
  /**
143
143
  * Calls the `avg` function for the column or expression given as the argument.
144
144
  *
@@ -1,7 +1,7 @@
1
1
  import { OperationNodeSource } from '../operation-node/operation-node-source.js';
2
2
  import { CompiledQuery } from '../query-compiler/compiled-query.js';
3
3
  import { SelectExpression, SelectCallback } from '../parser/select-parser.js';
4
- import { InsertObjectOrList, InsertObjectOrListFactory } from '../parser/insert-values-parser.js';
4
+ import { InsertExpression } from '../parser/insert-values-parser.js';
5
5
  import { InsertQueryNode } from '../operation-node/insert-query-node.js';
6
6
  import { QueryNode } from '../operation-node/query-node.js';
7
7
  import { NarrowPartial, SimplifyResult, SimplifySingleResult } from '../util/type-utils.js';
@@ -184,8 +184,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
184
184
  * }))
185
185
  * ```
186
186
  */
187
- values(insert: InsertObjectOrList<DB, TB>): InsertQueryBuilder<DB, TB, O>;
188
- values(insert: InsertObjectOrListFactory<DB, TB>): InsertQueryBuilder<DB, TB, O>;
187
+ values(insert: InsertExpression<DB, TB>): InsertQueryBuilder<DB, TB, O>;
189
188
  /**
190
189
  * Sets the columns to insert.
191
190
  *
@@ -240,6 +239,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
240
239
  * ```
241
240
  */
242
241
  expression(expression: ExpressionOrFactory<DB, TB, any>): InsertQueryBuilder<DB, TB, O>;
242
+ /**
243
+ * Creates an `insert into "person" default values` query.
244
+ */
245
+ defaultValues(): InsertQueryBuilder<DB, TB, O>;
243
246
  /**
244
247
  * Changes an `insert into` query to an `insert ignore into` query.
245
248
  *
@@ -563,10 +566,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
563
566
  /**
564
567
  * Change the output type of the query.
565
568
  *
566
- * You should only use this method as the last resort if the types
567
- * don't support your use case.
569
+ * This method call doesn't change the SQL in any way. This methods simply
570
+ * returns a copy of this `InsertQueryBuilder` with a new output type.
568
571
  */
569
- $castTo<T>(): InsertQueryBuilder<DB, TB, T>;
572
+ $castTo<C>(): InsertQueryBuilder<DB, TB, C>;
570
573
  /**
571
574
  * Narrows (parts of) the output type of the query.
572
575
  *