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.
- package/README.md +22 -24
- package/dist/cjs/dialect/dialect-adapter-base.d.ts +32 -6
- package/dist/cjs/dialect/dialect-adapter.d.ts +50 -8
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +32 -6
- package/dist/cjs/dialect/mysql/mysql-introspector.js +2 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/cjs/dialect/postgres/postgres-introspector.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +2 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/migration/migrator.d.ts +8 -3
- package/dist/cjs/migration/migrator.js +15 -5
- package/dist/cjs/operation-node/create-index-node.d.ts +1 -0
- package/dist/cjs/operation-node/delete-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/delete-query-node.js +9 -0
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +9 -0
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.js +1 -0
- package/dist/cjs/operation-node/using-node.d.ts +13 -0
- package/dist/cjs/operation-node/using-node.js +24 -0
- package/dist/cjs/parser/update-set-parser.d.ts +1 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +98 -6
- package/dist/cjs/query-builder/delete-query-builder.js +39 -8
- package/dist/cjs/query-builder/insert-query-builder.d.ts +21 -5
- package/dist/cjs/query-builder/insert-query-builder.js +32 -8
- package/dist/cjs/query-builder/select-query-builder.d.ts +43 -27
- package/dist/cjs/query-builder/select-query-builder.js +53 -29
- package/dist/cjs/query-builder/update-query-builder.d.ts +21 -5
- package/dist/cjs/query-builder/update-query-builder.js +32 -8
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +11 -0
- package/dist/cjs/raw-builder/raw-builder.d.ts +4 -0
- package/dist/cjs/raw-builder/raw-builder.js +8 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +5 -1
- package/dist/cjs/schema/alter-table-builder.js +8 -2
- package/dist/cjs/schema/create-index-builder.d.ts +6 -0
- package/dist/cjs/schema/create-index-builder.js +13 -0
- package/dist/cjs/schema/create-table-builder.d.ts +6 -2
- package/dist/cjs/schema/create-table-builder.js +9 -3
- package/dist/cjs/util/type-utils.d.ts +18 -0
- package/dist/esm/dialect/dialect-adapter-base.d.ts +32 -6
- package/dist/esm/dialect/dialect-adapter.d.ts +50 -8
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +32 -6
- package/dist/esm/dialect/mysql/mysql-introspector.js +2 -2
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/esm/dialect/postgres/postgres-introspector.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +2 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/migration/migrator.d.ts +8 -3
- package/dist/esm/migration/migrator.js +15 -5
- package/dist/esm/operation-node/create-index-node.d.ts +1 -0
- package/dist/esm/operation-node/delete-query-node.d.ts +3 -0
- package/dist/esm/operation-node/delete-query-node.js +9 -0
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +9 -0
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-visitor.js +1 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.js +1 -0
- package/dist/esm/operation-node/using-node.d.ts +13 -0
- package/dist/esm/operation-node/using-node.js +22 -0
- package/dist/esm/parser/update-set-parser.d.ts +1 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +98 -6
- package/dist/esm/query-builder/delete-query-builder.js +39 -8
- package/dist/esm/query-builder/insert-query-builder.d.ts +21 -5
- package/dist/esm/query-builder/insert-query-builder.js +33 -9
- package/dist/esm/query-builder/select-query-builder.d.ts +43 -27
- package/dist/esm/query-builder/select-query-builder.js +53 -29
- package/dist/esm/query-builder/update-query-builder.d.ts +21 -5
- package/dist/esm/query-builder/update-query-builder.js +32 -8
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/esm/query-compiler/default-query-compiler.js +11 -0
- package/dist/esm/raw-builder/raw-builder.d.ts +4 -0
- package/dist/esm/raw-builder/raw-builder.js +8 -2
- package/dist/esm/schema/alter-table-builder.d.ts +5 -1
- package/dist/esm/schema/alter-table-builder.js +8 -2
- package/dist/esm/schema/create-index-builder.d.ts +6 -0
- package/dist/esm/schema/create-index-builder.js +13 -0
- package/dist/esm/schema/create-table-builder.d.ts +6 -2
- package/dist/esm/schema/create-table-builder.js +9 -3
- package/dist/esm/util/type-utils.d.ts +18 -0
- package/package.json +1 -1
|
@@ -581,6 +581,28 @@ class SelectQueryBuilder {
|
|
|
581
581
|
queryNode: select_query_node_js_1.SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, (0, set_operation_parser_js_1.parseSetOperation)('except', expression, true)),
|
|
582
582
|
});
|
|
583
583
|
}
|
|
584
|
+
/**
|
|
585
|
+
* Gives an alias for the query. This method is only useful for sub queries.
|
|
586
|
+
*
|
|
587
|
+
* ### Examples
|
|
588
|
+
*
|
|
589
|
+
* ```ts
|
|
590
|
+
* const pets = await db.selectFrom('pet')
|
|
591
|
+
* .selectAll('pet')
|
|
592
|
+
* .select(
|
|
593
|
+
* (qb) => qb.selectFrom('person')
|
|
594
|
+
* .select('first_name')
|
|
595
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
596
|
+
* .as('owner_first_name')
|
|
597
|
+
* )
|
|
598
|
+
* .execute()
|
|
599
|
+
*
|
|
600
|
+
* pets[0].owner_first_name
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
as(alias) {
|
|
604
|
+
return new AliasedSelectQueryBuilder(this, alias);
|
|
605
|
+
}
|
|
584
606
|
/**
|
|
585
607
|
* Clears all select clauses from the query.
|
|
586
608
|
*
|
|
@@ -688,7 +710,7 @@ class SelectQueryBuilder {
|
|
|
688
710
|
* Simply calls the given function passing `this` as the only argument.
|
|
689
711
|
*
|
|
690
712
|
* If you want to conditionally call a method on `this`, see
|
|
691
|
-
* the {@link if} method.
|
|
713
|
+
* the {@link $if} method.
|
|
692
714
|
*
|
|
693
715
|
* ### Examples
|
|
694
716
|
*
|
|
@@ -702,13 +724,19 @@ class SelectQueryBuilder {
|
|
|
702
724
|
*
|
|
703
725
|
* db.selectFrom('person')
|
|
704
726
|
* .selectAll()
|
|
705
|
-
*
|
|
727
|
+
* .$call(log)
|
|
706
728
|
* .execute()
|
|
707
729
|
* ```
|
|
708
730
|
*/
|
|
709
|
-
call(func) {
|
|
731
|
+
$call(func) {
|
|
710
732
|
return func(this);
|
|
711
733
|
}
|
|
734
|
+
/**
|
|
735
|
+
* @deprecated Use `$call` instead
|
|
736
|
+
*/
|
|
737
|
+
call(func) {
|
|
738
|
+
return this.$call(func);
|
|
739
|
+
}
|
|
712
740
|
/**
|
|
713
741
|
* Call `func(this)` if `condition` is true.
|
|
714
742
|
*
|
|
@@ -726,7 +754,7 @@ class SelectQueryBuilder {
|
|
|
726
754
|
* return await db
|
|
727
755
|
* .selectFrom('person')
|
|
728
756
|
* .select(['id', 'first_name'])
|
|
729
|
-
*
|
|
757
|
+
* .$if(withLastName, (qb) => qb.select('last_name'))
|
|
730
758
|
* .where('id', '=', id)
|
|
731
759
|
* .executeTakeFirstOrThrow()
|
|
732
760
|
* }
|
|
@@ -751,15 +779,15 @@ class SelectQueryBuilder {
|
|
|
751
779
|
*
|
|
752
780
|
* db.selectFrom('person')
|
|
753
781
|
* .select('person.id')
|
|
754
|
-
*
|
|
755
|
-
*
|
|
782
|
+
* .$if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
|
|
783
|
+
* .$if(filterByPetCount, (qb) => qb
|
|
756
784
|
* .innerJoin('pet', 'pet.owner_id', 'person.id')
|
|
757
785
|
* .having(count('pet.id'), '>', petCountLimit)
|
|
758
786
|
* .groupBy('person.id')
|
|
759
787
|
* )
|
|
760
788
|
* ```
|
|
761
789
|
*/
|
|
762
|
-
if(condition, func) {
|
|
790
|
+
$if(condition, func) {
|
|
763
791
|
if (condition) {
|
|
764
792
|
return func(this);
|
|
765
793
|
}
|
|
@@ -768,26 +796,10 @@ class SelectQueryBuilder {
|
|
|
768
796
|
});
|
|
769
797
|
}
|
|
770
798
|
/**
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
* ### Examples
|
|
774
|
-
*
|
|
775
|
-
* ```ts
|
|
776
|
-
* const pets = await db.selectFrom('pet')
|
|
777
|
-
* .selectAll('pet')
|
|
778
|
-
* .select(
|
|
779
|
-
* (qb) => qb.selectFrom('person')
|
|
780
|
-
* .select('first_name')
|
|
781
|
-
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
782
|
-
* .as('owner_first_name')
|
|
783
|
-
* )
|
|
784
|
-
* .execute()
|
|
785
|
-
*
|
|
786
|
-
* pets[0].owner_first_name
|
|
787
|
-
* ```
|
|
799
|
+
* @deprecated Use `$if` instead
|
|
788
800
|
*/
|
|
789
|
-
|
|
790
|
-
return
|
|
801
|
+
if(condition, func) {
|
|
802
|
+
return this.$if(condition, func);
|
|
791
803
|
}
|
|
792
804
|
/**
|
|
793
805
|
* Change the output type of the query.
|
|
@@ -795,9 +807,15 @@ class SelectQueryBuilder {
|
|
|
795
807
|
* You should only use this method as the last resort if the types
|
|
796
808
|
* don't support your use case.
|
|
797
809
|
*/
|
|
798
|
-
castTo() {
|
|
810
|
+
$castTo() {
|
|
799
811
|
return new SelectQueryBuilder(this.#props);
|
|
800
812
|
}
|
|
813
|
+
/**
|
|
814
|
+
* @deprecated Use `$castTo` instead.
|
|
815
|
+
*/
|
|
816
|
+
castTo() {
|
|
817
|
+
return this.$castTo();
|
|
818
|
+
}
|
|
801
819
|
/**
|
|
802
820
|
* Asserts that query's output row type equals the given type `T`.
|
|
803
821
|
*
|
|
@@ -825,18 +843,24 @@ class SelectQueryBuilder {
|
|
|
825
843
|
* .with('first_and_last', (qb) => qb
|
|
826
844
|
* .selectFrom('person')
|
|
827
845
|
* .select(['first_name', 'last_name'])
|
|
828
|
-
*
|
|
846
|
+
* .$assertType<{ first_name: string, last_name: string }>()
|
|
829
847
|
* )
|
|
830
848
|
* .with('age', (qb) => qb
|
|
831
849
|
* .selectFrom('person')
|
|
832
850
|
* .select('age')
|
|
833
|
-
*
|
|
851
|
+
* .$assertType<{ age: number }>()
|
|
834
852
|
* )
|
|
835
853
|
* .selectFrom(['first_and_last', 'age'])
|
|
836
854
|
* .selectAll()
|
|
837
855
|
* .executeTakeFirstOrThrow()
|
|
838
856
|
* ```
|
|
839
857
|
*/
|
|
858
|
+
$assertType() {
|
|
859
|
+
return new SelectQueryBuilder(this.#props);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* @deprecated Use `$assertType` instead.
|
|
863
|
+
*/
|
|
840
864
|
assertType() {
|
|
841
865
|
return new SelectQueryBuilder(this.#props);
|
|
842
866
|
}
|
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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.
|
|
@@ -212,7 +212,7 @@ class UpdateQueryBuilder {
|
|
|
212
212
|
* Simply calls the given function passing `this` as the only argument.
|
|
213
213
|
*
|
|
214
214
|
* If you want to conditionally call a method on `this`, see
|
|
215
|
-
* the {@link if} method.
|
|
215
|
+
* the {@link $if} method.
|
|
216
216
|
*
|
|
217
217
|
* ### Examples
|
|
218
218
|
*
|
|
@@ -226,13 +226,19 @@ class UpdateQueryBuilder {
|
|
|
226
226
|
*
|
|
227
227
|
* db.updateTable('person')
|
|
228
228
|
* .set(values)
|
|
229
|
-
*
|
|
229
|
+
* .$call(log)
|
|
230
230
|
* .execute()
|
|
231
231
|
* ```
|
|
232
232
|
*/
|
|
233
|
-
call(func) {
|
|
233
|
+
$call(func) {
|
|
234
234
|
return func(this);
|
|
235
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* @deprecated Use `$call` instead
|
|
238
|
+
*/
|
|
239
|
+
call(func) {
|
|
240
|
+
return this.$call(func);
|
|
241
|
+
}
|
|
236
242
|
/**
|
|
237
243
|
* Call `func(this)` if `condition` is true.
|
|
238
244
|
*
|
|
@@ -252,7 +258,7 @@ class UpdateQueryBuilder {
|
|
|
252
258
|
* .set(updates)
|
|
253
259
|
* .where('id', '=', id)
|
|
254
260
|
* .returning(['id', 'first_name'])
|
|
255
|
-
*
|
|
261
|
+
* .$if(returnLastName, (qb) => qb.returning('last_name'))
|
|
256
262
|
* .executeTakeFirstOrThrow()
|
|
257
263
|
* }
|
|
258
264
|
* ```
|
|
@@ -269,7 +275,7 @@ class UpdateQueryBuilder {
|
|
|
269
275
|
* }
|
|
270
276
|
* ```
|
|
271
277
|
*/
|
|
272
|
-
if(condition, func) {
|
|
278
|
+
$if(condition, func) {
|
|
273
279
|
if (condition) {
|
|
274
280
|
return func(this);
|
|
275
281
|
}
|
|
@@ -277,15 +283,27 @@ class UpdateQueryBuilder {
|
|
|
277
283
|
...this.#props,
|
|
278
284
|
});
|
|
279
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* @deprecated Use `$if` instead
|
|
288
|
+
*/
|
|
289
|
+
if(condition, func) {
|
|
290
|
+
return this.$if(condition, func);
|
|
291
|
+
}
|
|
280
292
|
/**
|
|
281
293
|
* Change the output type of the query.
|
|
282
294
|
*
|
|
283
295
|
* You should only use this method as the last resort if the types
|
|
284
296
|
* don't support your use case.
|
|
285
297
|
*/
|
|
286
|
-
castTo() {
|
|
298
|
+
$castTo() {
|
|
287
299
|
return new UpdateQueryBuilder(this.#props);
|
|
288
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* @deprecated Use `$castTo` instead.
|
|
303
|
+
*/
|
|
304
|
+
castTo() {
|
|
305
|
+
return this.$castTo();
|
|
306
|
+
}
|
|
289
307
|
/**
|
|
290
308
|
* Asserts that query's output row type equals the given type `T`.
|
|
291
309
|
*
|
|
@@ -315,20 +333,26 @@ class UpdateQueryBuilder {
|
|
|
315
333
|
* .set(person)
|
|
316
334
|
* .where('id', '=', person.id)
|
|
317
335
|
* .returning('first_name')
|
|
318
|
-
*
|
|
336
|
+
* .$assertType<{ first_name: string }>()
|
|
319
337
|
* )
|
|
320
338
|
* .with('updated_pet', (qb) => qb
|
|
321
339
|
* .updateTable('pet')
|
|
322
340
|
* .set(pet)
|
|
323
341
|
* .where('owner_id', '=', person.id)
|
|
324
342
|
* .returning(['name as pet_name', 'species'])
|
|
325
|
-
*
|
|
343
|
+
* .$assertType<{ pet_name: string, species: Species }>()
|
|
326
344
|
* )
|
|
327
345
|
* .selectFrom(['updated_person', 'updated_pet'])
|
|
328
346
|
* .selectAll()
|
|
329
347
|
* .executeTakeFirstOrThrow()
|
|
330
348
|
* ```
|
|
331
349
|
*/
|
|
350
|
+
$assertType() {
|
|
351
|
+
return new UpdateQueryBuilder(this.#props);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* @deprecated Use `$assertType` instead.
|
|
355
|
+
*/
|
|
332
356
|
assertType() {
|
|
333
357
|
return new UpdateQueryBuilder(this.#props);
|
|
334
358
|
}
|
|
@@ -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;
|
|
@@ -191,6 +191,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
191
191
|
}
|
|
192
192
|
this.append('delete ');
|
|
193
193
|
this.visitNode(node.from);
|
|
194
|
+
if (node.using) {
|
|
195
|
+
this.append(' ');
|
|
196
|
+
this.visitNode(node.using);
|
|
197
|
+
}
|
|
194
198
|
if (node.joins) {
|
|
195
199
|
this.append(' ');
|
|
196
200
|
this.compileList(node.joins, ' ');
|
|
@@ -531,6 +535,9 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
531
535
|
this.append('unique ');
|
|
532
536
|
}
|
|
533
537
|
this.append('index ');
|
|
538
|
+
if (node.ifNotExists) {
|
|
539
|
+
this.append('if not exists ');
|
|
540
|
+
}
|
|
534
541
|
this.visitNode(node.name);
|
|
535
542
|
if (node.table) {
|
|
536
543
|
this.append(' on ');
|
|
@@ -901,6 +908,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
901
908
|
this.append(' ');
|
|
902
909
|
this.visitNode(node.operand);
|
|
903
910
|
}
|
|
911
|
+
visitUsing(node) {
|
|
912
|
+
this.append('using ');
|
|
913
|
+
this.compileList(node.tables);
|
|
914
|
+
}
|
|
904
915
|
append(str) {
|
|
905
916
|
this.#sql += str;
|
|
906
917
|
}
|
|
@@ -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.
|
|
@@ -31,9 +31,15 @@ class RawBuilder {
|
|
|
31
31
|
* This method call doesn't change the SQL in any way. This methods simply
|
|
32
32
|
* returns a copy of this `RawBuilder` with a new output type.
|
|
33
33
|
*/
|
|
34
|
-
castTo() {
|
|
34
|
+
$castTo() {
|
|
35
35
|
return new RawBuilder({ ...this.#props });
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated Use `$castTo` instead.
|
|
39
|
+
*/
|
|
40
|
+
castTo() {
|
|
41
|
+
return this.$castTo();
|
|
42
|
+
}
|
|
37
43
|
/**
|
|
38
44
|
* Adds a plugin for this SQL snippet.
|
|
39
45
|
*/
|
|
@@ -68,7 +74,7 @@ exports.RawBuilder = RawBuilder;
|
|
|
68
74
|
function isRawBuilder(obj) {
|
|
69
75
|
return ((0, object_utils_js_1.isObject)(obj) &&
|
|
70
76
|
(0, object_utils_js_1.isFunction)(obj.as) &&
|
|
71
|
-
(0, object_utils_js_1.isFunction)(obj
|
|
77
|
+
(0, object_utils_js_1.isFunction)(obj.$castTo) &&
|
|
72
78
|
(0, object_utils_js_1.isFunction)(obj.withPlugin) &&
|
|
73
79
|
(0, object_utils_js_1.isFunction)(obj.toOperationNode) &&
|
|
74
80
|
(0, object_utils_js_1.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
|
|
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
|
}
|
|
@@ -128,11 +128,17 @@ class AlterTableBuilder {
|
|
|
128
128
|
/**
|
|
129
129
|
* Calls the given function passing `this` as the only argument.
|
|
130
130
|
*
|
|
131
|
-
* See {@link CreateTableBuilder
|
|
131
|
+
* See {@link CreateTableBuilder.$call}
|
|
132
132
|
*/
|
|
133
|
-
call(func) {
|
|
133
|
+
$call(func) {
|
|
134
134
|
return func(this);
|
|
135
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated Use `$call` instead
|
|
138
|
+
*/
|
|
139
|
+
call(func) {
|
|
140
|
+
return this.$call(func);
|
|
141
|
+
}
|
|
136
142
|
}
|
|
137
143
|
exports.AlterTableBuilder = AlterTableBuilder;
|
|
138
144
|
class AlterTableColumnAlteringBuilder {
|
|
@@ -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
|
*/
|
|
@@ -13,6 +13,19 @@ class CreateIndexBuilder {
|
|
|
13
13
|
constructor(props) {
|
|
14
14
|
this.#props = (0, object_utils_js_1.freeze)(props);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Adds the "if not exists" modifier.
|
|
18
|
+
*
|
|
19
|
+
* If the index already exists, no error is thrown if this method has been called.
|
|
20
|
+
*/
|
|
21
|
+
ifNotExists() {
|
|
22
|
+
return new CreateIndexBuilder({
|
|
23
|
+
...this.#props,
|
|
24
|
+
node: create_index_node_js_1.CreateIndexNode.cloneWith(this.#props.node, {
|
|
25
|
+
ifNotExists: true,
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
16
29
|
/**
|
|
17
30
|
* Makes the index unique.
|
|
18
31
|
*/
|
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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;
|
|
@@ -278,7 +278,7 @@ class CreateTableBuilder {
|
|
|
278
278
|
* ```ts
|
|
279
279
|
* db.schema
|
|
280
280
|
* .createTable('test')
|
|
281
|
-
*
|
|
281
|
+
* .$call((builder) => builder.addColumn('id', 'integer'))
|
|
282
282
|
* .execute()
|
|
283
283
|
* ```
|
|
284
284
|
*
|
|
@@ -298,13 +298,19 @@ class CreateTableBuilder {
|
|
|
298
298
|
*
|
|
299
299
|
* db.schema
|
|
300
300
|
* .createTable('test')
|
|
301
|
-
*
|
|
301
|
+
* .$call(addDefaultColumns)
|
|
302
302
|
* .execute()
|
|
303
303
|
* ```
|
|
304
304
|
*/
|
|
305
|
-
call(func) {
|
|
305
|
+
$call(func) {
|
|
306
306
|
return func(this);
|
|
307
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* @deprecated Use `$call` instead
|
|
310
|
+
*/
|
|
311
|
+
call(func) {
|
|
312
|
+
return this.$call(func);
|
|
313
|
+
}
|
|
308
314
|
toOperationNode() {
|
|
309
315
|
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
|
310
316
|
}
|
|
@@ -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;
|
|
@@ -25,12 +25,38 @@ export declare abstract class DialectAdapterBase implements DialectAdapter {
|
|
|
25
25
|
* Most dialects have explicit locks that can be used, like advisory locks
|
|
26
26
|
* in PostgreSQL and the get_lock function in MySQL.
|
|
27
27
|
*
|
|
28
|
-
* If the dialect doesn't have explicit locks the {@link
|
|
29
|
-
* created by Kysely can be used instead.
|
|
30
|
-
* has two columns `id` and `is_locked` and there's only one row in the
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
28
|
+
* If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
|
|
29
|
+
* created by Kysely can be used instead. You can access it through the `options` object.
|
|
30
|
+
* The lock table has two columns `id` and `is_locked` and there's only one row in the table
|
|
31
|
+
* whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
|
|
32
|
+
* takes care of creating the lock table and inserting the one single row to it before this
|
|
33
|
+
* method is executed. If the dialect supports schemas and the user has specified a custom
|
|
34
|
+
* schema in their migration settings, the options object also contains the schema name in
|
|
35
|
+
* {@link MigrationLockOptions.lockTableSchema}.
|
|
36
|
+
*
|
|
37
|
+
* Here's an example of how you might implement this method for a dialect that doesn't
|
|
38
|
+
* have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* {
|
|
42
|
+
* async acquireMigrationLock(db, options): Promise<void> {
|
|
43
|
+
* const queryDb = options.lockTableSchema
|
|
44
|
+
* ? db.withSchema(options.lockTableSchema)
|
|
45
|
+
* : db
|
|
46
|
+
*
|
|
47
|
+
* // Since our imaginary dialect supports transactional DDL and has
|
|
48
|
+
* // row locks, we can simply take a row lock here and it will guarantee
|
|
49
|
+
* // all subsequent calls to this method from other transactions will
|
|
50
|
+
* // wait until this transaction finishes.
|
|
51
|
+
* await queryDb
|
|
52
|
+
* .selectFrom(options.lockTable)
|
|
53
|
+
* .selectAll()
|
|
54
|
+
* .where('id', '=', options.lockRowId)
|
|
55
|
+
* .forUpdate()
|
|
56
|
+
* .execute()
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
34
60
|
*
|
|
35
61
|
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
36
62
|
* is a transaction inside which the migrations will be executed. Otherwise
|