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.
|
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
753
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
788
|
-
return
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
}
|
|
@@ -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.
|
|
@@ -4,7 +4,7 @@ import { parseTableExpressionOrList, } from '../parser/table-parser.js';
|
|
|
4
4
|
import { parseSelectExpressionOrList, parseSelectAll, } from '../parser/select-parser.js';
|
|
5
5
|
import { QueryNode } from '../operation-node/query-node.js';
|
|
6
6
|
import { UpdateQueryNode } from '../operation-node/update-query-node.js';
|
|
7
|
-
import { parseUpdateObject
|
|
7
|
+
import { parseUpdateObject } from '../parser/update-set-parser.js';
|
|
8
8
|
import { preventAwait } from '../util/prevent-await.js';
|
|
9
9
|
import { freeze } from '../util/object-utils.js';
|
|
10
10
|
import { UpdateResult } from './update-result.js';
|
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
*/
|