kysely 0.23.2 → 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 +3 -3
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -3
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +3 -3
- package/dist/cjs/index.d.ts +2 -1
- 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/binary-operation-parser.d.ts +1 -1
- package/dist/cjs/parser/update-set-parser.d.ts +3 -3
- package/dist/cjs/parser/update-set-parser.js +2 -2
- 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 +23 -7
- package/dist/cjs/query-builder/insert-query-builder.js +32 -8
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +2 -2
- 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 +23 -7
- 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 +3 -3
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/esm/dialect/postgres/postgres-introspector.js +3 -3
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +3 -3
- package/dist/esm/index.d.ts +2 -1
- 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/binary-operation-parser.d.ts +1 -1
- package/dist/esm/parser/update-set-parser.d.ts +3 -3
- package/dist/esm/parser/update-set-parser.js +2 -2
- 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 +23 -7
- package/dist/esm/query-builder/insert-query-builder.js +33 -9
- package/dist/esm/query-builder/on-conflict-builder.d.ts +2 -2
- 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 +23 -7
- package/dist/esm/query-builder/update-query-builder.js +33 -9
- 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
|
@@ -488,7 +488,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
488
488
|
* To select all columns of the query or specific tables see the
|
|
489
489
|
* {@link selectAll} method.
|
|
490
490
|
*
|
|
491
|
-
* See the {@link if} method if you are looking for a way to add selections
|
|
491
|
+
* See the {@link $if} method if you are looking for a way to add selections
|
|
492
492
|
* based on a runtime condition.
|
|
493
493
|
*
|
|
494
494
|
* ### Examples
|
|
@@ -1292,6 +1292,26 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1292
1292
|
* ```
|
|
1293
1293
|
*/
|
|
1294
1294
|
exceptAll(expression: Expression<O>): SelectQueryBuilder<DB, TB, O>;
|
|
1295
|
+
/**
|
|
1296
|
+
* Gives an alias for the query. This method is only useful for sub queries.
|
|
1297
|
+
*
|
|
1298
|
+
* ### Examples
|
|
1299
|
+
*
|
|
1300
|
+
* ```ts
|
|
1301
|
+
* const pets = await db.selectFrom('pet')
|
|
1302
|
+
* .selectAll('pet')
|
|
1303
|
+
* .select(
|
|
1304
|
+
* (qb) => qb.selectFrom('person')
|
|
1305
|
+
* .select('first_name')
|
|
1306
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
1307
|
+
* .as('owner_first_name')
|
|
1308
|
+
* )
|
|
1309
|
+
* .execute()
|
|
1310
|
+
*
|
|
1311
|
+
* pets[0].owner_first_name
|
|
1312
|
+
* ```
|
|
1313
|
+
*/
|
|
1314
|
+
as<A extends string>(alias: A): AliasedSelectQueryBuilder<DB, TB, O, A>;
|
|
1295
1315
|
/**
|
|
1296
1316
|
* Clears all select clauses from the query.
|
|
1297
1317
|
*
|
|
@@ -1392,7 +1412,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1392
1412
|
* Simply calls the given function passing `this` as the only argument.
|
|
1393
1413
|
*
|
|
1394
1414
|
* If you want to conditionally call a method on `this`, see
|
|
1395
|
-
* the {@link if} method.
|
|
1415
|
+
* the {@link $if} method.
|
|
1396
1416
|
*
|
|
1397
1417
|
* ### Examples
|
|
1398
1418
|
*
|
|
@@ -1406,10 +1426,14 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1406
1426
|
*
|
|
1407
1427
|
* db.selectFrom('person')
|
|
1408
1428
|
* .selectAll()
|
|
1409
|
-
*
|
|
1429
|
+
* .$call(log)
|
|
1410
1430
|
* .execute()
|
|
1411
1431
|
* ```
|
|
1412
1432
|
*/
|
|
1433
|
+
$call<T>(func: (qb: this) => T): T;
|
|
1434
|
+
/**
|
|
1435
|
+
* @deprecated Use `$call` instead
|
|
1436
|
+
*/
|
|
1413
1437
|
call<T>(func: (qb: this) => T): T;
|
|
1414
1438
|
/**
|
|
1415
1439
|
* Call `func(this)` if `condition` is true.
|
|
@@ -1428,7 +1452,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1428
1452
|
* return await db
|
|
1429
1453
|
* .selectFrom('person')
|
|
1430
1454
|
* .select(['id', 'first_name'])
|
|
1431
|
-
*
|
|
1455
|
+
* .$if(withLastName, (qb) => qb.select('last_name'))
|
|
1432
1456
|
* .where('id', '=', id)
|
|
1433
1457
|
* .executeTakeFirstOrThrow()
|
|
1434
1458
|
* }
|
|
@@ -1453,41 +1477,29 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1453
1477
|
*
|
|
1454
1478
|
* db.selectFrom('person')
|
|
1455
1479
|
* .select('person.id')
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1480
|
+
* .$if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
|
|
1481
|
+
* .$if(filterByPetCount, (qb) => qb
|
|
1458
1482
|
* .innerJoin('pet', 'pet.owner_id', 'person.id')
|
|
1459
1483
|
* .having(count('pet.id'), '>', petCountLimit)
|
|
1460
1484
|
* .groupBy('person.id')
|
|
1461
1485
|
* )
|
|
1462
1486
|
* ```
|
|
1463
1487
|
*/
|
|
1464
|
-
if<O2 extends O>(condition: boolean, func: (qb: this) => SelectQueryBuilder<DB, TB, O2>): SelectQueryBuilder<DB, TB, MergePartial<O, O2>>;
|
|
1488
|
+
$if<O2 extends O>(condition: boolean, func: (qb: this) => SelectQueryBuilder<DB, TB, O2>): SelectQueryBuilder<DB, TB, MergePartial<O, O2>>;
|
|
1465
1489
|
/**
|
|
1466
|
-
*
|
|
1467
|
-
*
|
|
1468
|
-
* ### Examples
|
|
1469
|
-
*
|
|
1470
|
-
* ```ts
|
|
1471
|
-
* const pets = await db.selectFrom('pet')
|
|
1472
|
-
* .selectAll('pet')
|
|
1473
|
-
* .select(
|
|
1474
|
-
* (qb) => qb.selectFrom('person')
|
|
1475
|
-
* .select('first_name')
|
|
1476
|
-
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
1477
|
-
* .as('owner_first_name')
|
|
1478
|
-
* )
|
|
1479
|
-
* .execute()
|
|
1480
|
-
*
|
|
1481
|
-
* pets[0].owner_first_name
|
|
1482
|
-
* ```
|
|
1490
|
+
* @deprecated Use `$if` instead
|
|
1483
1491
|
*/
|
|
1484
|
-
|
|
1492
|
+
if<O2 extends O>(condition: boolean, func: (qb: this) => SelectQueryBuilder<DB, TB, O2>): SelectQueryBuilder<DB, TB, MergePartial<O, O2>>;
|
|
1485
1493
|
/**
|
|
1486
1494
|
* Change the output type of the query.
|
|
1487
1495
|
*
|
|
1488
1496
|
* You should only use this method as the last resort if the types
|
|
1489
1497
|
* don't support your use case.
|
|
1490
1498
|
*/
|
|
1499
|
+
$castTo<T>(): SelectQueryBuilder<DB, TB, T>;
|
|
1500
|
+
/**
|
|
1501
|
+
* @deprecated Use `$castTo` instead.
|
|
1502
|
+
*/
|
|
1491
1503
|
castTo<T>(): SelectQueryBuilder<DB, TB, T>;
|
|
1492
1504
|
/**
|
|
1493
1505
|
* Asserts that query's output row type equals the given type `T`.
|
|
@@ -1516,18 +1528,22 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1516
1528
|
* .with('first_and_last', (qb) => qb
|
|
1517
1529
|
* .selectFrom('person')
|
|
1518
1530
|
* .select(['first_name', 'last_name'])
|
|
1519
|
-
*
|
|
1531
|
+
* .$assertType<{ first_name: string, last_name: string }>()
|
|
1520
1532
|
* )
|
|
1521
1533
|
* .with('age', (qb) => qb
|
|
1522
1534
|
* .selectFrom('person')
|
|
1523
1535
|
* .select('age')
|
|
1524
|
-
*
|
|
1536
|
+
* .$assertType<{ age: number }>()
|
|
1525
1537
|
* )
|
|
1526
1538
|
* .selectFrom(['first_and_last', 'age'])
|
|
1527
1539
|
* .selectAll()
|
|
1528
1540
|
* .executeTakeFirstOrThrow()
|
|
1529
1541
|
* ```
|
|
1530
1542
|
*/
|
|
1543
|
+
$assertType<T extends O>(): O extends T ? SelectQueryBuilder<DB, TB, T> : KyselyTypeError<`$assertType() call failed: The type passed in is not equal to the output type of the query.`>;
|
|
1544
|
+
/**
|
|
1545
|
+
* @deprecated Use `$assertType` instead.
|
|
1546
|
+
*/
|
|
1531
1547
|
assertType<T extends O>(): O extends T ? SelectQueryBuilder<DB, TB, T> : KyselyTypeError<`assertType() call failed: The type passed in is not equal to the output type of the query.`>;
|
|
1532
1548
|
/**
|
|
1533
1549
|
* Returns a copy of this SelectQueryBuilder instance with the given plugin installed.
|
|
@@ -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
|
}
|
|
@@ -7,7 +7,7 @@ import { ReturningRow } from '../parser/returning-parser.js';
|
|
|
7
7
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
8
8
|
import { MergePartial, Nullable, SingleResultType } from '../util/type-utils.js';
|
|
9
9
|
import { UpdateQueryNode } from '../operation-node/update-query-node.js';
|
|
10
|
-
import {
|
|
10
|
+
import { UpdateObject } from '../parser/update-set-parser.js';
|
|
11
11
|
import { Compilable } from '../util/compilable.js';
|
|
12
12
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
13
13
|
import { QueryId } from '../util/query-id.js';
|
|
@@ -670,7 +670,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
|
|
|
670
670
|
* where "id" = $4
|
|
671
671
|
* ```
|
|
672
672
|
*/
|
|
673
|
-
set(row:
|
|
673
|
+
set(row: UpdateObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
674
674
|
/**
|
|
675
675
|
* Allows you to return data from modified rows.
|
|
676
676
|
*
|
|
@@ -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
|
*/
|