kysely 0.23.3 → 0.23.4

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 (90) hide show
  1. package/README.md +22 -24
  2. package/dist/cjs/dialect/dialect-adapter-base.d.ts +32 -6
  3. package/dist/cjs/dialect/dialect-adapter.d.ts +50 -8
  4. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +32 -6
  5. package/dist/cjs/dialect/mysql/mysql-introspector.js +2 -2
  6. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
  7. package/dist/cjs/dialect/postgres/postgres-introspector.js +2 -2
  8. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
  9. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +2 -2
  10. package/dist/cjs/index.d.ts +1 -0
  11. package/dist/cjs/index.js +1 -0
  12. package/dist/cjs/migration/migrator.d.ts +8 -3
  13. package/dist/cjs/migration/migrator.js +15 -5
  14. package/dist/cjs/operation-node/create-index-node.d.ts +1 -0
  15. package/dist/cjs/operation-node/delete-query-node.d.ts +3 -0
  16. package/dist/cjs/operation-node/delete-query-node.js +9 -0
  17. package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
  18. package/dist/cjs/operation-node/operation-node-transformer.js +9 -0
  19. package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
  20. package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
  21. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  22. package/dist/cjs/operation-node/operator-node.d.ts +1 -1
  23. package/dist/cjs/operation-node/operator-node.js +1 -0
  24. package/dist/cjs/operation-node/using-node.d.ts +13 -0
  25. package/dist/cjs/operation-node/using-node.js +24 -0
  26. package/dist/cjs/parser/update-set-parser.d.ts +1 -1
  27. package/dist/cjs/query-builder/delete-query-builder.d.ts +98 -6
  28. package/dist/cjs/query-builder/delete-query-builder.js +39 -8
  29. package/dist/cjs/query-builder/insert-query-builder.d.ts +21 -5
  30. package/dist/cjs/query-builder/insert-query-builder.js +32 -8
  31. package/dist/cjs/query-builder/select-query-builder.d.ts +43 -27
  32. package/dist/cjs/query-builder/select-query-builder.js +53 -29
  33. package/dist/cjs/query-builder/update-query-builder.d.ts +21 -5
  34. package/dist/cjs/query-builder/update-query-builder.js +32 -8
  35. package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
  36. package/dist/cjs/query-compiler/default-query-compiler.js +11 -0
  37. package/dist/cjs/raw-builder/raw-builder.d.ts +4 -0
  38. package/dist/cjs/raw-builder/raw-builder.js +8 -2
  39. package/dist/cjs/schema/alter-table-builder.d.ts +5 -1
  40. package/dist/cjs/schema/alter-table-builder.js +8 -2
  41. package/dist/cjs/schema/create-index-builder.d.ts +6 -0
  42. package/dist/cjs/schema/create-index-builder.js +13 -0
  43. package/dist/cjs/schema/create-table-builder.d.ts +6 -2
  44. package/dist/cjs/schema/create-table-builder.js +9 -3
  45. package/dist/cjs/util/type-utils.d.ts +18 -0
  46. package/dist/esm/dialect/dialect-adapter-base.d.ts +32 -6
  47. package/dist/esm/dialect/dialect-adapter.d.ts +50 -8
  48. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +32 -6
  49. package/dist/esm/dialect/mysql/mysql-introspector.js +2 -2
  50. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
  51. package/dist/esm/dialect/postgres/postgres-introspector.js +2 -2
  52. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
  53. package/dist/esm/dialect/sqlite/sqlite-introspector.js +2 -2
  54. package/dist/esm/index.d.ts +1 -0
  55. package/dist/esm/index.js +1 -0
  56. package/dist/esm/migration/migrator.d.ts +8 -3
  57. package/dist/esm/migration/migrator.js +15 -5
  58. package/dist/esm/operation-node/create-index-node.d.ts +1 -0
  59. package/dist/esm/operation-node/delete-query-node.d.ts +3 -0
  60. package/dist/esm/operation-node/delete-query-node.js +9 -0
  61. package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
  62. package/dist/esm/operation-node/operation-node-transformer.js +9 -0
  63. package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
  64. package/dist/esm/operation-node/operation-node-visitor.js +1 -0
  65. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  66. package/dist/esm/operation-node/operator-node.d.ts +1 -1
  67. package/dist/esm/operation-node/operator-node.js +1 -0
  68. package/dist/esm/operation-node/using-node.d.ts +13 -0
  69. package/dist/esm/operation-node/using-node.js +22 -0
  70. package/dist/esm/parser/update-set-parser.d.ts +1 -1
  71. package/dist/esm/query-builder/delete-query-builder.d.ts +98 -6
  72. package/dist/esm/query-builder/delete-query-builder.js +39 -8
  73. package/dist/esm/query-builder/insert-query-builder.d.ts +21 -5
  74. package/dist/esm/query-builder/insert-query-builder.js +33 -9
  75. package/dist/esm/query-builder/select-query-builder.d.ts +43 -27
  76. package/dist/esm/query-builder/select-query-builder.js +53 -29
  77. package/dist/esm/query-builder/update-query-builder.d.ts +21 -5
  78. package/dist/esm/query-builder/update-query-builder.js +32 -8
  79. package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
  80. package/dist/esm/query-compiler/default-query-compiler.js +11 -0
  81. package/dist/esm/raw-builder/raw-builder.d.ts +4 -0
  82. package/dist/esm/raw-builder/raw-builder.js +8 -2
  83. package/dist/esm/schema/alter-table-builder.d.ts +5 -1
  84. package/dist/esm/schema/alter-table-builder.js +8 -2
  85. package/dist/esm/schema/create-index-builder.d.ts +6 -0
  86. package/dist/esm/schema/create-index-builder.js +13 -0
  87. package/dist/esm/schema/create-table-builder.d.ts +6 -2
  88. package/dist/esm/schema/create-table-builder.js +9 -3
  89. package/dist/esm/util/type-utils.d.ts +18 -0
  90. package/package.json +1 -1
@@ -579,6 +579,28 @@ export class SelectQueryBuilder {
579
579
  queryNode: SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, parseSetOperation('except', expression, true)),
580
580
  });
581
581
  }
582
+ /**
583
+ * Gives an alias for the query. This method is only useful for sub queries.
584
+ *
585
+ * ### Examples
586
+ *
587
+ * ```ts
588
+ * const pets = await db.selectFrom('pet')
589
+ * .selectAll('pet')
590
+ * .select(
591
+ * (qb) => qb.selectFrom('person')
592
+ * .select('first_name')
593
+ * .whereRef('pet.owner_id', '=', 'person.id')
594
+ * .as('owner_first_name')
595
+ * )
596
+ * .execute()
597
+ *
598
+ * pets[0].owner_first_name
599
+ * ```
600
+ */
601
+ as(alias) {
602
+ return new AliasedSelectQueryBuilder(this, alias);
603
+ }
582
604
  /**
583
605
  * Clears all select clauses from the query.
584
606
  *
@@ -686,7 +708,7 @@ export class SelectQueryBuilder {
686
708
  * Simply calls the given function passing `this` as the only argument.
687
709
  *
688
710
  * If you want to conditionally call a method on `this`, see
689
- * the {@link if} method.
711
+ * the {@link $if} method.
690
712
  *
691
713
  * ### Examples
692
714
  *
@@ -700,13 +722,19 @@ export class SelectQueryBuilder {
700
722
  *
701
723
  * db.selectFrom('person')
702
724
  * .selectAll()
703
- * .call(log)
725
+ * .$call(log)
704
726
  * .execute()
705
727
  * ```
706
728
  */
707
- call(func) {
729
+ $call(func) {
708
730
  return func(this);
709
731
  }
732
+ /**
733
+ * @deprecated Use `$call` instead
734
+ */
735
+ call(func) {
736
+ return this.$call(func);
737
+ }
710
738
  /**
711
739
  * Call `func(this)` if `condition` is true.
712
740
  *
@@ -724,7 +752,7 @@ export class SelectQueryBuilder {
724
752
  * return await db
725
753
  * .selectFrom('person')
726
754
  * .select(['id', 'first_name'])
727
- * .if(withLastName, (qb) => qb.select('last_name'))
755
+ * .$if(withLastName, (qb) => qb.select('last_name'))
728
756
  * .where('id', '=', id)
729
757
  * .executeTakeFirstOrThrow()
730
758
  * }
@@ -749,15 +777,15 @@ export class SelectQueryBuilder {
749
777
  *
750
778
  * db.selectFrom('person')
751
779
  * .select('person.id')
752
- * .if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
753
- * .if(filterByPetCount, (qb) => qb
780
+ * .$if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
781
+ * .$if(filterByPetCount, (qb) => qb
754
782
  * .innerJoin('pet', 'pet.owner_id', 'person.id')
755
783
  * .having(count('pet.id'), '>', petCountLimit)
756
784
  * .groupBy('person.id')
757
785
  * )
758
786
  * ```
759
787
  */
760
- if(condition, func) {
788
+ $if(condition, func) {
761
789
  if (condition) {
762
790
  return func(this);
763
791
  }
@@ -766,26 +794,10 @@ export class SelectQueryBuilder {
766
794
  });
767
795
  }
768
796
  /**
769
- * Gives an alias for the query. This method is only useful for sub queries.
770
- *
771
- * ### Examples
772
- *
773
- * ```ts
774
- * const pets = await db.selectFrom('pet')
775
- * .selectAll('pet')
776
- * .select(
777
- * (qb) => qb.selectFrom('person')
778
- * .select('first_name')
779
- * .whereRef('pet.owner_id', '=', 'person.id')
780
- * .as('owner_first_name')
781
- * )
782
- * .execute()
783
- *
784
- * pets[0].owner_first_name
785
- * ```
797
+ * @deprecated Use `$if` instead
786
798
  */
787
- as(alias) {
788
- return new AliasedSelectQueryBuilder(this, alias);
799
+ if(condition, func) {
800
+ return this.$if(condition, func);
789
801
  }
790
802
  /**
791
803
  * Change the output type of the query.
@@ -793,9 +805,15 @@ export class SelectQueryBuilder {
793
805
  * You should only use this method as the last resort if the types
794
806
  * don't support your use case.
795
807
  */
796
- castTo() {
808
+ $castTo() {
797
809
  return new SelectQueryBuilder(this.#props);
798
810
  }
811
+ /**
812
+ * @deprecated Use `$castTo` instead.
813
+ */
814
+ castTo() {
815
+ return this.$castTo();
816
+ }
799
817
  /**
800
818
  * Asserts that query's output row type equals the given type `T`.
801
819
  *
@@ -823,18 +841,24 @@ export class SelectQueryBuilder {
823
841
  * .with('first_and_last', (qb) => qb
824
842
  * .selectFrom('person')
825
843
  * .select(['first_name', 'last_name'])
826
- * .assertType<{ first_name: string, last_name: string }>()
844
+ * .$assertType<{ first_name: string, last_name: string }>()
827
845
  * )
828
846
  * .with('age', (qb) => qb
829
847
  * .selectFrom('person')
830
848
  * .select('age')
831
- * .assertType<{ age: number }>()
849
+ * .$assertType<{ age: number }>()
832
850
  * )
833
851
  * .selectFrom(['first_and_last', 'age'])
834
852
  * .selectAll()
835
853
  * .executeTakeFirstOrThrow()
836
854
  * ```
837
855
  */
856
+ $assertType() {
857
+ return new SelectQueryBuilder(this.#props);
858
+ }
859
+ /**
860
+ * @deprecated Use `$assertType` instead.
861
+ */
838
862
  assertType() {
839
863
  return new SelectQueryBuilder(this.#props);
840
864
  }
@@ -741,7 +741,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
741
741
  * Simply calls the given function passing `this` as the only argument.
742
742
  *
743
743
  * If you want to conditionally call a method on `this`, see
744
- * the {@link if} method.
744
+ * the {@link $if} method.
745
745
  *
746
746
  * ### Examples
747
747
  *
@@ -755,10 +755,14 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
755
755
  *
756
756
  * db.updateTable('person')
757
757
  * .set(values)
758
- * .call(log)
758
+ * .$call(log)
759
759
  * .execute()
760
760
  * ```
761
761
  */
762
+ $call<T>(func: (qb: this) => T): T;
763
+ /**
764
+ * @deprecated Use `$call` instead
765
+ */
762
766
  call<T>(func: (qb: this) => T): T;
763
767
  /**
764
768
  * Call `func(this)` if `condition` is true.
@@ -779,7 +783,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
779
783
  * .set(updates)
780
784
  * .where('id', '=', id)
781
785
  * .returning(['id', 'first_name'])
782
- * .if(returnLastName, (qb) => qb.returning('last_name'))
786
+ * .$if(returnLastName, (qb) => qb.returning('last_name'))
783
787
  * .executeTakeFirstOrThrow()
784
788
  * }
785
789
  * ```
@@ -796,6 +800,10 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
796
800
  * }
797
801
  * ```
798
802
  */
803
+ $if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, UT, TB, O2>): UpdateQueryBuilder<DB, UT, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
804
+ /**
805
+ * @deprecated Use `$if` instead
806
+ */
799
807
  if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, UT, TB, O2>): UpdateQueryBuilder<DB, UT, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
800
808
  /**
801
809
  * Change the output type of the query.
@@ -803,6 +811,10 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
803
811
  * You should only use this method as the last resort if the types
804
812
  * don't support your use case.
805
813
  */
814
+ $castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
815
+ /**
816
+ * @deprecated Use `$castTo` instead.
817
+ */
806
818
  castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
807
819
  /**
808
820
  * Asserts that query's output row type equals the given type `T`.
@@ -833,20 +845,24 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
833
845
  * .set(person)
834
846
  * .where('id', '=', person.id)
835
847
  * .returning('first_name')
836
- * .assertType<{ first_name: string }>()
848
+ * .$assertType<{ first_name: string }>()
837
849
  * )
838
850
  * .with('updated_pet', (qb) => qb
839
851
  * .updateTable('pet')
840
852
  * .set(pet)
841
853
  * .where('owner_id', '=', person.id)
842
854
  * .returning(['name as pet_name', 'species'])
843
- * .assertType<{ pet_name: string, species: Species }>()
855
+ * .$assertType<{ pet_name: string, species: Species }>()
844
856
  * )
845
857
  * .selectFrom(['updated_person', 'updated_pet'])
846
858
  * .selectAll()
847
859
  * .executeTakeFirstOrThrow()
848
860
  * ```
849
861
  */
862
+ $assertType<T extends O>(): O extends T ? UpdateQueryBuilder<DB, UT, TB, T> : KyselyTypeError<`$assertType() call failed: The type passed in is not equal to the output type of the query.`>;
863
+ /**
864
+ * @deprecated Use `$assertType` instead.
865
+ */
850
866
  assertType<T extends O>(): O extends T ? UpdateQueryBuilder<DB, UT, TB, T> : KyselyTypeError<`assertType() call failed: The type passed in is not equal to the output type of the query.`>;
851
867
  /**
852
868
  * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
@@ -210,7 +210,7 @@ export class UpdateQueryBuilder {
210
210
  * Simply calls the given function passing `this` as the only argument.
211
211
  *
212
212
  * If you want to conditionally call a method on `this`, see
213
- * the {@link if} method.
213
+ * the {@link $if} method.
214
214
  *
215
215
  * ### Examples
216
216
  *
@@ -224,13 +224,19 @@ export class UpdateQueryBuilder {
224
224
  *
225
225
  * db.updateTable('person')
226
226
  * .set(values)
227
- * .call(log)
227
+ * .$call(log)
228
228
  * .execute()
229
229
  * ```
230
230
  */
231
- call(func) {
231
+ $call(func) {
232
232
  return func(this);
233
233
  }
234
+ /**
235
+ * @deprecated Use `$call` instead
236
+ */
237
+ call(func) {
238
+ return this.$call(func);
239
+ }
234
240
  /**
235
241
  * Call `func(this)` if `condition` is true.
236
242
  *
@@ -250,7 +256,7 @@ export class UpdateQueryBuilder {
250
256
  * .set(updates)
251
257
  * .where('id', '=', id)
252
258
  * .returning(['id', 'first_name'])
253
- * .if(returnLastName, (qb) => qb.returning('last_name'))
259
+ * .$if(returnLastName, (qb) => qb.returning('last_name'))
254
260
  * .executeTakeFirstOrThrow()
255
261
  * }
256
262
  * ```
@@ -267,7 +273,7 @@ export class UpdateQueryBuilder {
267
273
  * }
268
274
  * ```
269
275
  */
270
- if(condition, func) {
276
+ $if(condition, func) {
271
277
  if (condition) {
272
278
  return func(this);
273
279
  }
@@ -275,15 +281,27 @@ export class UpdateQueryBuilder {
275
281
  ...this.#props,
276
282
  });
277
283
  }
284
+ /**
285
+ * @deprecated Use `$if` instead
286
+ */
287
+ if(condition, func) {
288
+ return this.$if(condition, func);
289
+ }
278
290
  /**
279
291
  * Change the output type of the query.
280
292
  *
281
293
  * You should only use this method as the last resort if the types
282
294
  * don't support your use case.
283
295
  */
284
- castTo() {
296
+ $castTo() {
285
297
  return new UpdateQueryBuilder(this.#props);
286
298
  }
299
+ /**
300
+ * @deprecated Use `$castTo` instead.
301
+ */
302
+ castTo() {
303
+ return this.$castTo();
304
+ }
287
305
  /**
288
306
  * Asserts that query's output row type equals the given type `T`.
289
307
  *
@@ -313,20 +331,26 @@ export class UpdateQueryBuilder {
313
331
  * .set(person)
314
332
  * .where('id', '=', person.id)
315
333
  * .returning('first_name')
316
- * .assertType<{ first_name: string }>()
334
+ * .$assertType<{ first_name: string }>()
317
335
  * )
318
336
  * .with('updated_pet', (qb) => qb
319
337
  * .updateTable('pet')
320
338
  * .set(pet)
321
339
  * .where('owner_id', '=', person.id)
322
340
  * .returning(['name as pet_name', 'species'])
323
- * .assertType<{ pet_name: string, species: Species }>()
341
+ * .$assertType<{ pet_name: string, species: Species }>()
324
342
  * )
325
343
  * .selectFrom(['updated_person', 'updated_pet'])
326
344
  * .selectAll()
327
345
  * .executeTakeFirstOrThrow()
328
346
  * ```
329
347
  */
348
+ $assertType() {
349
+ return new UpdateQueryBuilder(this.#props);
350
+ }
351
+ /**
352
+ * @deprecated Use `$assertType` instead.
353
+ */
330
354
  assertType() {
331
355
  return new UpdateQueryBuilder(this.#props);
332
356
  }
@@ -79,6 +79,7 @@ import { PartitionByItemNode } from '../operation-node/partition-by-item-node.js
79
79
  import { SetOperationNode } from '../operation-node/set-operation-node.js';
80
80
  import { BinaryOperationNode } from '../operation-node/binary-operation-node.js';
81
81
  import { UnaryOperationNode } from '../operation-node/unary-operation-node.js';
82
+ import { UsingNode } from '../operation-node/using-node.js';
82
83
  export declare class DefaultQueryCompiler extends OperationNodeVisitor implements QueryCompiler {
83
84
  #private;
84
85
  protected get numParameters(): number;
@@ -165,6 +166,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
165
166
  protected visitPartitionByItem(node: PartitionByItemNode): void;
166
167
  protected visitBinaryOperation(node: BinaryOperationNode): void;
167
168
  protected visitUnaryOperation(node: UnaryOperationNode): void;
169
+ protected visitUsing(node: UsingNode): void;
168
170
  protected append(str: string): void;
169
171
  protected appendValue(parameter: unknown): void;
170
172
  protected getLeftIdentifierWrapper(): string;
@@ -189,6 +189,10 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
189
189
  }
190
190
  this.append('delete ');
191
191
  this.visitNode(node.from);
192
+ if (node.using) {
193
+ this.append(' ');
194
+ this.visitNode(node.using);
195
+ }
192
196
  if (node.joins) {
193
197
  this.append(' ');
194
198
  this.compileList(node.joins, ' ');
@@ -529,6 +533,9 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
529
533
  this.append('unique ');
530
534
  }
531
535
  this.append('index ');
536
+ if (node.ifNotExists) {
537
+ this.append('if not exists ');
538
+ }
532
539
  this.visitNode(node.name);
533
540
  if (node.table) {
534
541
  this.append(' on ');
@@ -899,6 +906,10 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
899
906
  this.append(' ');
900
907
  this.visitNode(node.operand);
901
908
  }
909
+ visitUsing(node) {
910
+ this.append('using ');
911
+ this.compileList(node.tables);
912
+ }
902
913
  append(str) {
903
914
  this.#sql += str;
904
915
  }
@@ -93,6 +93,10 @@ export declare class RawBuilder<O> implements Expression<O> {
93
93
  * This method call doesn't change the SQL in any way. This methods simply
94
94
  * returns a copy of this `RawBuilder` with a new output type.
95
95
  */
96
+ $castTo<T>(): RawBuilder<T>;
97
+ /**
98
+ * @deprecated Use `$castTo` instead.
99
+ */
96
100
  castTo<T>(): RawBuilder<T>;
97
101
  /**
98
102
  * Adds a plugin for this SQL snippet.
@@ -29,9 +29,15 @@ export class RawBuilder {
29
29
  * This method call doesn't change the SQL in any way. This methods simply
30
30
  * returns a copy of this `RawBuilder` with a new output type.
31
31
  */
32
- castTo() {
32
+ $castTo() {
33
33
  return new RawBuilder({ ...this.#props });
34
34
  }
35
+ /**
36
+ * @deprecated Use `$castTo` instead.
37
+ */
38
+ castTo() {
39
+ return this.$castTo();
40
+ }
35
41
  /**
36
42
  * Adds a plugin for this SQL snippet.
37
43
  */
@@ -65,7 +71,7 @@ export class RawBuilder {
65
71
  export function isRawBuilder(obj) {
66
72
  return (isObject(obj) &&
67
73
  isFunction(obj.as) &&
68
- isFunction(obj.castTo) &&
74
+ isFunction(obj.$castTo) &&
69
75
  isFunction(obj.withPlugin) &&
70
76
  isFunction(obj.toOperationNode) &&
71
77
  isFunction(obj.execute));
@@ -52,7 +52,11 @@ export declare class AlterTableBuilder implements ColumnAlteringInterface {
52
52
  /**
53
53
  * Calls the given function passing `this` as the only argument.
54
54
  *
55
- * See {@link CreateTableBuilder.call}
55
+ * See {@link CreateTableBuilder.$call}
56
+ */
57
+ $call<T>(func: (qb: this) => T): T;
58
+ /**
59
+ * @deprecated Use `$call` instead
56
60
  */
57
61
  call<T>(func: (qb: this) => T): T;
58
62
  }
@@ -126,11 +126,17 @@ export class AlterTableBuilder {
126
126
  /**
127
127
  * Calls the given function passing `this` as the only argument.
128
128
  *
129
- * See {@link CreateTableBuilder.call}
129
+ * See {@link CreateTableBuilder.$call}
130
130
  */
131
- call(func) {
131
+ $call(func) {
132
132
  return func(this);
133
133
  }
134
+ /**
135
+ * @deprecated Use `$call` instead
136
+ */
137
+ call(func) {
138
+ return this.$call(func);
139
+ }
134
140
  }
135
141
  export class AlterTableColumnAlteringBuilder {
136
142
  #props;
@@ -8,6 +8,12 @@ import { Expression } from '../expression/expression.js';
8
8
  export declare class CreateIndexBuilder implements OperationNodeSource, Compilable {
9
9
  #private;
10
10
  constructor(props: CreateIndexBuilderProps);
11
+ /**
12
+ * Adds the "if not exists" modifier.
13
+ *
14
+ * If the index already exists, no error is thrown if this method has been called.
15
+ */
16
+ ifNotExists(): CreateIndexBuilder;
11
17
  /**
12
18
  * Makes the index unique.
13
19
  */
@@ -11,6 +11,19 @@ export class CreateIndexBuilder {
11
11
  constructor(props) {
12
12
  this.#props = freeze(props);
13
13
  }
14
+ /**
15
+ * Adds the "if not exists" modifier.
16
+ *
17
+ * If the index already exists, no error is thrown if this method has been called.
18
+ */
19
+ ifNotExists() {
20
+ return new CreateIndexBuilder({
21
+ ...this.#props,
22
+ node: CreateIndexNode.cloneWith(this.#props.node, {
23
+ ifNotExists: true,
24
+ }),
25
+ });
26
+ }
14
27
  /**
15
28
  * Makes the index unique.
16
29
  */
@@ -211,7 +211,7 @@ export declare class CreateTableBuilder<TB extends string, C extends string = ne
211
211
  * ```ts
212
212
  * db.schema
213
213
  * .createTable('test')
214
- * .call((builder) => builder.addColumn('id', 'integer'))
214
+ * .$call((builder) => builder.addColumn('id', 'integer'))
215
215
  * .execute()
216
216
  * ```
217
217
  *
@@ -231,10 +231,14 @@ export declare class CreateTableBuilder<TB extends string, C extends string = ne
231
231
  *
232
232
  * db.schema
233
233
  * .createTable('test')
234
- * .call(addDefaultColumns)
234
+ * .$call(addDefaultColumns)
235
235
  * .execute()
236
236
  * ```
237
237
  */
238
+ $call<T>(func: (qb: this) => T): T;
239
+ /**
240
+ * @deprecated Use `$call` instead
241
+ */
238
242
  call<T>(func: (qb: this) => T): T;
239
243
  toOperationNode(): CreateTableNode;
240
244
  compile(): CompiledQuery;
@@ -276,7 +276,7 @@ export class CreateTableBuilder {
276
276
  * ```ts
277
277
  * db.schema
278
278
  * .createTable('test')
279
- * .call((builder) => builder.addColumn('id', 'integer'))
279
+ * .$call((builder) => builder.addColumn('id', 'integer'))
280
280
  * .execute()
281
281
  * ```
282
282
  *
@@ -296,13 +296,19 @@ export class CreateTableBuilder {
296
296
  *
297
297
  * db.schema
298
298
  * .createTable('test')
299
- * .call(addDefaultColumns)
299
+ * .$call(addDefaultColumns)
300
300
  * .execute()
301
301
  * ```
302
302
  */
303
- call(func) {
303
+ $call(func) {
304
304
  return func(this);
305
305
  }
306
+ /**
307
+ * @deprecated Use `$call` instead
308
+ */
309
+ call(func) {
310
+ return this.$call(func);
311
+ }
306
312
  toOperationNode() {
307
313
  return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
308
314
  }
@@ -96,9 +96,21 @@ export declare type AnyAliasedColumnWithTable<DB, TB extends keyof DB> = {
96
96
  * Extracts the item type of an array.
97
97
  */
98
98
  export declare type ArrayItemType<T> = T extends ReadonlyArray<infer I> ? I : never;
99
+ /**
100
+ * Any select query builder.
101
+ */
99
102
  export declare type AnySelectQueryBuilder = SelectQueryBuilder<any, any, any>;
103
+ /**
104
+ * Given a query output type `O` evaluates to the output type of a `executeTakeFirst` call.
105
+ */
100
106
  export declare type SingleResultType<O> = O extends InsertResult ? O : O extends DeleteResult ? O : O extends UpdateResult ? O : O | undefined;
107
+ /**
108
+ * Represents a database row whose column names and their types are unknown.
109
+ */
101
110
  export declare type UnknownRow = Record<string, unknown>;
111
+ /**
112
+ * Makes all properties of object type `T` nullable.
113
+ */
102
114
  export declare type Nullable<T> = {
103
115
  [P in keyof T]: T[P] | null;
104
116
  };
@@ -123,5 +135,11 @@ export declare type Nullable<T> = {
123
135
  * // { name: string, age: number, species?: 'cat' | 'dog' }
124
136
  */
125
137
  export declare type MergePartial<T1, T2> = T1 & Partial<Omit<T2, keyof T1>>;
138
+ /**
139
+ * Evaluates to `true` if `T` is `never`.
140
+ */
126
141
  export declare type IsNever<T> = [T] extends [never] ? true : false;
142
+ /**
143
+ * Evaluates to `true` if the types `T` and `U` are equal.
144
+ */
127
145
  export declare type Equals<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely",
3
- "version": "0.23.3",
3
+ "version": "0.23.4",
4
4
  "description": "Type safe SQL query builder",
5
5
  "repository": {
6
6
  "type": "git",