kysely 0.23.3 → 0.23.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +25 -25
  2. package/dist/cjs/dialect/database-introspector.d.ts +4 -2
  3. package/dist/cjs/dialect/dialect-adapter-base.d.ts +32 -6
  4. package/dist/cjs/dialect/dialect-adapter.d.ts +50 -8
  5. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +32 -6
  6. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
  7. package/dist/cjs/dialect/mysql/mysql-introspector.js +21 -15
  8. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
  9. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
  10. package/dist/cjs/dialect/postgres/postgres-introspector.js +5 -3
  11. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
  12. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  13. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +8 -7
  14. package/dist/cjs/index.d.ts +1 -0
  15. package/dist/cjs/index.js +1 -0
  16. package/dist/cjs/migration/migrator.d.ts +8 -3
  17. package/dist/cjs/migration/migrator.js +15 -5
  18. package/dist/cjs/operation-node/aggregate-function-node.d.ts +3 -2
  19. package/dist/cjs/operation-node/aggregate-function-node.js +2 -2
  20. package/dist/cjs/operation-node/create-index-node.d.ts +1 -0
  21. package/dist/cjs/operation-node/delete-query-node.d.ts +4 -1
  22. package/dist/cjs/operation-node/delete-query-node.js +11 -2
  23. package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
  24. package/dist/cjs/operation-node/operation-node-transformer.js +10 -1
  25. package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
  26. package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
  27. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  28. package/dist/cjs/operation-node/operator-node.d.ts +1 -1
  29. package/dist/cjs/operation-node/operator-node.js +1 -0
  30. package/dist/cjs/operation-node/using-node.d.ts +13 -0
  31. package/dist/cjs/operation-node/using-node.js +24 -0
  32. package/dist/cjs/parser/expression-parser.js +1 -1
  33. package/dist/cjs/parser/table-parser.d.ts +1 -0
  34. package/dist/cjs/parser/update-set-parser.d.ts +1 -1
  35. package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +7 -0
  36. package/dist/cjs/plugin/camel-case/camel-case-plugin.js +10 -4
  37. package/dist/cjs/query-builder/delete-query-builder.d.ts +103 -11
  38. package/dist/cjs/query-builder/delete-query-builder.js +40 -9
  39. package/dist/cjs/query-builder/function-module.d.ts +273 -39
  40. package/dist/cjs/query-builder/function-module.js +156 -34
  41. package/dist/cjs/query-builder/insert-query-builder.d.ts +25 -10
  42. package/dist/cjs/query-builder/insert-query-builder.js +32 -9
  43. package/dist/cjs/query-builder/select-query-builder.d.ts +51 -34
  44. package/dist/cjs/query-builder/select-query-builder.js +53 -29
  45. package/dist/cjs/query-builder/update-query-builder.d.ts +26 -10
  46. package/dist/cjs/query-builder/update-query-builder.js +33 -9
  47. package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
  48. package/dist/cjs/query-compiler/default-query-compiler.js +12 -1
  49. package/dist/cjs/query-creator.d.ts +29 -0
  50. package/dist/cjs/query-creator.js +2 -21
  51. package/dist/cjs/raw-builder/raw-builder.d.ts +4 -0
  52. package/dist/cjs/raw-builder/raw-builder.js +8 -2
  53. package/dist/cjs/schema/alter-table-builder.d.ts +5 -1
  54. package/dist/cjs/schema/alter-table-builder.js +8 -2
  55. package/dist/cjs/schema/create-index-builder.d.ts +6 -0
  56. package/dist/cjs/schema/create-index-builder.js +13 -0
  57. package/dist/cjs/schema/create-table-builder.d.ts +6 -2
  58. package/dist/cjs/schema/create-table-builder.js +9 -3
  59. package/dist/cjs/util/type-utils.d.ts +20 -1
  60. package/dist/esm/dialect/database-introspector.d.ts +4 -2
  61. package/dist/esm/dialect/dialect-adapter-base.d.ts +32 -6
  62. package/dist/esm/dialect/dialect-adapter.d.ts +50 -8
  63. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +32 -6
  64. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
  65. package/dist/esm/dialect/mysql/mysql-introspector.js +21 -15
  66. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
  67. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
  68. package/dist/esm/dialect/postgres/postgres-introspector.js +5 -3
  69. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
  70. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  71. package/dist/esm/dialect/sqlite/sqlite-introspector.js +8 -7
  72. package/dist/esm/index.d.ts +1 -0
  73. package/dist/esm/index.js +1 -0
  74. package/dist/esm/migration/migrator.d.ts +8 -3
  75. package/dist/esm/migration/migrator.js +15 -5
  76. package/dist/esm/operation-node/aggregate-function-node.d.ts +3 -2
  77. package/dist/esm/operation-node/aggregate-function-node.js +2 -2
  78. package/dist/esm/operation-node/create-index-node.d.ts +1 -0
  79. package/dist/esm/operation-node/delete-query-node.d.ts +4 -1
  80. package/dist/esm/operation-node/delete-query-node.js +11 -2
  81. package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
  82. package/dist/esm/operation-node/operation-node-transformer.js +10 -1
  83. package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
  84. package/dist/esm/operation-node/operation-node-visitor.js +1 -0
  85. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  86. package/dist/esm/operation-node/operator-node.d.ts +1 -1
  87. package/dist/esm/operation-node/operator-node.js +1 -0
  88. package/dist/esm/operation-node/using-node.d.ts +13 -0
  89. package/dist/esm/operation-node/using-node.js +22 -0
  90. package/dist/esm/parser/expression-parser.js +2 -2
  91. package/dist/esm/parser/table-parser.d.ts +1 -0
  92. package/dist/esm/parser/update-set-parser.d.ts +1 -1
  93. package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +7 -0
  94. package/dist/esm/plugin/camel-case/camel-case-plugin.js +10 -4
  95. package/dist/esm/query-builder/delete-query-builder.d.ts +103 -11
  96. package/dist/esm/query-builder/delete-query-builder.js +40 -9
  97. package/dist/esm/query-builder/function-module.d.ts +273 -39
  98. package/dist/esm/query-builder/function-module.js +156 -34
  99. package/dist/esm/query-builder/insert-query-builder.d.ts +25 -10
  100. package/dist/esm/query-builder/insert-query-builder.js +33 -10
  101. package/dist/esm/query-builder/select-query-builder.d.ts +51 -34
  102. package/dist/esm/query-builder/select-query-builder.js +53 -29
  103. package/dist/esm/query-builder/update-query-builder.d.ts +26 -10
  104. package/dist/esm/query-builder/update-query-builder.js +33 -9
  105. package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
  106. package/dist/esm/query-compiler/default-query-compiler.js +12 -1
  107. package/dist/esm/query-creator.d.ts +29 -0
  108. package/dist/esm/query-creator.js +2 -21
  109. package/dist/esm/raw-builder/raw-builder.d.ts +4 -0
  110. package/dist/esm/raw-builder/raw-builder.js +8 -2
  111. package/dist/esm/schema/alter-table-builder.d.ts +5 -1
  112. package/dist/esm/schema/alter-table-builder.js +8 -2
  113. package/dist/esm/schema/create-index-builder.d.ts +6 -0
  114. package/dist/esm/schema/create-index-builder.js +13 -0
  115. package/dist/esm/schema/create-table-builder.d.ts +6 -2
  116. package/dist/esm/schema/create-table-builder.js +9 -3
  117. package/dist/esm/util/type-utils.d.ts +20 -1
  118. package/package.json +1 -1
@@ -5,7 +5,7 @@ import { TableExpression } from '../parser/table-parser.js';
5
5
  import { SelectExpression, QueryBuilderWithSelection, SelectAllQueryBuilder } from '../parser/select-parser.js';
6
6
  import { ReferenceExpression } from '../parser/reference-parser.js';
7
7
  import { SelectQueryNode } from '../operation-node/select-query-node.js';
8
- import { MergePartial, Nullable, SingleResultType } from '../util/type-utils.js';
8
+ import { MergePartial, Nullable, Simplify, SimplifySingleResult } from '../util/type-utils.js';
9
9
  import { OrderByDirectionExpression, OrderByExpression } from '../parser/order-by-parser.js';
10
10
  import { Compilable } from '../util/compilable.js';
11
11
  import { QueryExecutor } from '../query-executor/query-executor.js';
@@ -483,12 +483,12 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
483
483
  * to override the types.
484
484
  *
485
485
  * Select calls are additive. Calling `select('id').select('first_name')` is the
486
- * same as calling `select(['id', 'first_name']).
486
+ * same as calling `select(['id', 'first_name'])`.
487
487
  *
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
@@ -892,7 +892,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
892
892
  * ```ts
893
893
  * await db.selectFrom('person')
894
894
  * .innerJoin(
895
- * qb.selectFrom('pet')
895
+ * db.selectFrom('pet')
896
896
  * .select(['owner_id', 'name'])
897
897
  * .where('name', '=', 'Doggo')
898
898
  * .as('doggos'),
@@ -950,6 +950,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
950
950
  * )
951
951
  * .select(['first_name', 'p.name'])
952
952
  * .orderBy('first_name')
953
+ * ```
953
954
  */
954
955
  innerJoinLateral<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): SelectQueryBuilderWithInnerJoin<DB, TB, O, TE>;
955
956
  innerJoinLateral<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): SelectQueryBuilderWithInnerJoin<DB, TB, O, TE>;
@@ -1292,6 +1293,26 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1292
1293
  * ```
1293
1294
  */
1294
1295
  exceptAll(expression: Expression<O>): SelectQueryBuilder<DB, TB, O>;
1296
+ /**
1297
+ * Gives an alias for the query. This method is only useful for sub queries.
1298
+ *
1299
+ * ### Examples
1300
+ *
1301
+ * ```ts
1302
+ * const pets = await db.selectFrom('pet')
1303
+ * .selectAll('pet')
1304
+ * .select(
1305
+ * (qb) => qb.selectFrom('person')
1306
+ * .select('first_name')
1307
+ * .whereRef('pet.owner_id', '=', 'person.id')
1308
+ * .as('owner_first_name')
1309
+ * )
1310
+ * .execute()
1311
+ *
1312
+ * pets[0].owner_first_name
1313
+ * ```
1314
+ */
1315
+ as<A extends string>(alias: A): AliasedSelectQueryBuilder<DB, TB, O, A>;
1295
1316
  /**
1296
1317
  * Clears all select clauses from the query.
1297
1318
  *
@@ -1392,7 +1413,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1392
1413
  * Simply calls the given function passing `this` as the only argument.
1393
1414
  *
1394
1415
  * If you want to conditionally call a method on `this`, see
1395
- * the {@link if} method.
1416
+ * the {@link $if} method.
1396
1417
  *
1397
1418
  * ### Examples
1398
1419
  *
@@ -1406,10 +1427,14 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1406
1427
  *
1407
1428
  * db.selectFrom('person')
1408
1429
  * .selectAll()
1409
- * .call(log)
1430
+ * .$call(log)
1410
1431
  * .execute()
1411
1432
  * ```
1412
1433
  */
1434
+ $call<T>(func: (qb: this) => T): T;
1435
+ /**
1436
+ * @deprecated Use `$call` instead
1437
+ */
1413
1438
  call<T>(func: (qb: this) => T): T;
1414
1439
  /**
1415
1440
  * Call `func(this)` if `condition` is true.
@@ -1428,7 +1453,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1428
1453
  * return await db
1429
1454
  * .selectFrom('person')
1430
1455
  * .select(['id', 'first_name'])
1431
- * .if(withLastName, (qb) => qb.select('last_name'))
1456
+ * .$if(withLastName, (qb) => qb.select('last_name'))
1432
1457
  * .where('id', '=', id)
1433
1458
  * .executeTakeFirstOrThrow()
1434
1459
  * }
@@ -1453,41 +1478,29 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1453
1478
  *
1454
1479
  * db.selectFrom('person')
1455
1480
  * .select('person.id')
1456
- * .if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
1457
- * .if(filterByPetCount, (qb) => qb
1481
+ * .$if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
1482
+ * .$if(filterByPetCount, (qb) => qb
1458
1483
  * .innerJoin('pet', 'pet.owner_id', 'person.id')
1459
1484
  * .having(count('pet.id'), '>', petCountLimit)
1460
1485
  * .groupBy('person.id')
1461
1486
  * )
1462
1487
  * ```
1463
1488
  */
1464
- if<O2 extends O>(condition: boolean, func: (qb: this) => SelectQueryBuilder<DB, TB, O2>): SelectQueryBuilder<DB, TB, MergePartial<O, O2>>;
1489
+ $if<O2 extends O>(condition: boolean, func: (qb: this) => SelectQueryBuilder<DB, TB, O2>): SelectQueryBuilder<DB, TB, MergePartial<O, O2>>;
1465
1490
  /**
1466
- * Gives an alias for the query. This method is only useful for sub queries.
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
- * ```
1491
+ * @deprecated Use `$if` instead
1483
1492
  */
1484
- as<A extends string>(alias: A): AliasedSelectQueryBuilder<DB, TB, O, A>;
1493
+ if<O2 extends O>(condition: boolean, func: (qb: this) => SelectQueryBuilder<DB, TB, O2>): SelectQueryBuilder<DB, TB, MergePartial<O, O2>>;
1485
1494
  /**
1486
1495
  * Change the output type of the query.
1487
1496
  *
1488
1497
  * You should only use this method as the last resort if the types
1489
1498
  * don't support your use case.
1490
1499
  */
1500
+ $castTo<T>(): SelectQueryBuilder<DB, TB, T>;
1501
+ /**
1502
+ * @deprecated Use `$castTo` instead.
1503
+ */
1491
1504
  castTo<T>(): SelectQueryBuilder<DB, TB, T>;
1492
1505
  /**
1493
1506
  * Asserts that query's output row type equals the given type `T`.
@@ -1516,18 +1529,22 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1516
1529
  * .with('first_and_last', (qb) => qb
1517
1530
  * .selectFrom('person')
1518
1531
  * .select(['first_name', 'last_name'])
1519
- * .assertType<{ first_name: string, last_name: string }>()
1532
+ * .$assertType<{ first_name: string, last_name: string }>()
1520
1533
  * )
1521
1534
  * .with('age', (qb) => qb
1522
1535
  * .selectFrom('person')
1523
1536
  * .select('age')
1524
- * .assertType<{ age: number }>()
1537
+ * .$assertType<{ age: number }>()
1525
1538
  * )
1526
1539
  * .selectFrom(['first_and_last', 'age'])
1527
1540
  * .selectAll()
1528
1541
  * .executeTakeFirstOrThrow()
1529
1542
  * ```
1530
1543
  */
1544
+ $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.`>;
1545
+ /**
1546
+ * @deprecated Use `$assertType` instead.
1547
+ */
1531
1548
  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
1549
  /**
1533
1550
  * Returns a copy of this SelectQueryBuilder instance with the given plugin installed.
@@ -1548,18 +1565,18 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1548
1565
  * ```
1549
1566
  */
1550
1567
  toOperationNode(): SelectQueryNode;
1551
- compile(): CompiledQuery<O>;
1568
+ compile(): CompiledQuery<Simplify<O>>;
1552
1569
  /**
1553
1570
  * Executes the query and returns an array of rows.
1554
1571
  *
1555
1572
  * Also see the {@link executeTakeFirst} and {@link executeTakeFirstOrThrow} methods.
1556
1573
  */
1557
- execute(): Promise<O[]>;
1574
+ execute(): Promise<Simplify<O>[]>;
1558
1575
  /**
1559
1576
  * Executes the query and returns the first result or undefined if
1560
1577
  * the query returned no result.
1561
1578
  */
1562
- executeTakeFirst(): Promise<SingleResultType<O>>;
1579
+ executeTakeFirst(): Promise<SimplifySingleResult<O>>;
1563
1580
  /**
1564
1581
  * Executes the query and returns the first result or throws if
1565
1582
  * the query returned no result.
@@ -1568,7 +1585,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1568
1585
  * provide a custom error class as the only argument to throw a different
1569
1586
  * error.
1570
1587
  */
1571
- executeTakeFirstOrThrow(errorConstructor?: NoResultErrorConstructor): Promise<O>;
1588
+ executeTakeFirstOrThrow(errorConstructor?: NoResultErrorConstructor): Promise<Simplify<O>>;
1572
1589
  /**
1573
1590
  * Executes the query and streams the rows.
1574
1591
  *
@@ -579,6 +579,28 @@ export class SelectQueryBuilder {
579
579
  queryNode: SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, parseSetOperation('except', expression, true)),
580
580
  });
581
581
  }
582
+ /**
583
+ * Gives an alias for the query. This method is only useful for sub queries.
584
+ *
585
+ * ### Examples
586
+ *
587
+ * ```ts
588
+ * const pets = await db.selectFrom('pet')
589
+ * .selectAll('pet')
590
+ * .select(
591
+ * (qb) => qb.selectFrom('person')
592
+ * .select('first_name')
593
+ * .whereRef('pet.owner_id', '=', 'person.id')
594
+ * .as('owner_first_name')
595
+ * )
596
+ * .execute()
597
+ *
598
+ * pets[0].owner_first_name
599
+ * ```
600
+ */
601
+ as(alias) {
602
+ return new AliasedSelectQueryBuilder(this, alias);
603
+ }
582
604
  /**
583
605
  * Clears all select clauses from the query.
584
606
  *
@@ -686,7 +708,7 @@ export class SelectQueryBuilder {
686
708
  * Simply calls the given function passing `this` as the only argument.
687
709
  *
688
710
  * If you want to conditionally call a method on `this`, see
689
- * the {@link if} method.
711
+ * the {@link $if} method.
690
712
  *
691
713
  * ### Examples
692
714
  *
@@ -700,13 +722,19 @@ export class SelectQueryBuilder {
700
722
  *
701
723
  * db.selectFrom('person')
702
724
  * .selectAll()
703
- * .call(log)
725
+ * .$call(log)
704
726
  * .execute()
705
727
  * ```
706
728
  */
707
- call(func) {
729
+ $call(func) {
708
730
  return func(this);
709
731
  }
732
+ /**
733
+ * @deprecated Use `$call` instead
734
+ */
735
+ call(func) {
736
+ return this.$call(func);
737
+ }
710
738
  /**
711
739
  * Call `func(this)` if `condition` is true.
712
740
  *
@@ -724,7 +752,7 @@ export class SelectQueryBuilder {
724
752
  * return await db
725
753
  * .selectFrom('person')
726
754
  * .select(['id', 'first_name'])
727
- * .if(withLastName, (qb) => qb.select('last_name'))
755
+ * .$if(withLastName, (qb) => qb.select('last_name'))
728
756
  * .where('id', '=', id)
729
757
  * .executeTakeFirstOrThrow()
730
758
  * }
@@ -749,15 +777,15 @@ export class SelectQueryBuilder {
749
777
  *
750
778
  * db.selectFrom('person')
751
779
  * .select('person.id')
752
- * .if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
753
- * .if(filterByPetCount, (qb) => qb
780
+ * .$if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
781
+ * .$if(filterByPetCount, (qb) => qb
754
782
  * .innerJoin('pet', 'pet.owner_id', 'person.id')
755
783
  * .having(count('pet.id'), '>', petCountLimit)
756
784
  * .groupBy('person.id')
757
785
  * )
758
786
  * ```
759
787
  */
760
- if(condition, func) {
788
+ $if(condition, func) {
761
789
  if (condition) {
762
790
  return func(this);
763
791
  }
@@ -766,26 +794,10 @@ export class SelectQueryBuilder {
766
794
  });
767
795
  }
768
796
  /**
769
- * Gives an alias for the query. This method is only useful for sub queries.
770
- *
771
- * ### Examples
772
- *
773
- * ```ts
774
- * const pets = await db.selectFrom('pet')
775
- * .selectAll('pet')
776
- * .select(
777
- * (qb) => qb.selectFrom('person')
778
- * .select('first_name')
779
- * .whereRef('pet.owner_id', '=', 'person.id')
780
- * .as('owner_first_name')
781
- * )
782
- * .execute()
783
- *
784
- * pets[0].owner_first_name
785
- * ```
797
+ * @deprecated Use `$if` instead
786
798
  */
787
- as(alias) {
788
- return new AliasedSelectQueryBuilder(this, alias);
799
+ if(condition, func) {
800
+ return this.$if(condition, func);
789
801
  }
790
802
  /**
791
803
  * Change the output type of the query.
@@ -793,9 +805,15 @@ export class SelectQueryBuilder {
793
805
  * You should only use this method as the last resort if the types
794
806
  * don't support your use case.
795
807
  */
796
- castTo() {
808
+ $castTo() {
797
809
  return new SelectQueryBuilder(this.#props);
798
810
  }
811
+ /**
812
+ * @deprecated Use `$castTo` instead.
813
+ */
814
+ castTo() {
815
+ return this.$castTo();
816
+ }
799
817
  /**
800
818
  * Asserts that query's output row type equals the given type `T`.
801
819
  *
@@ -823,18 +841,24 @@ export class SelectQueryBuilder {
823
841
  * .with('first_and_last', (qb) => qb
824
842
  * .selectFrom('person')
825
843
  * .select(['first_name', 'last_name'])
826
- * .assertType<{ first_name: string, last_name: string }>()
844
+ * .$assertType<{ first_name: string, last_name: string }>()
827
845
  * )
828
846
  * .with('age', (qb) => qb
829
847
  * .selectFrom('person')
830
848
  * .select('age')
831
- * .assertType<{ age: number }>()
849
+ * .$assertType<{ age: number }>()
832
850
  * )
833
851
  * .selectFrom(['first_and_last', 'age'])
834
852
  * .selectAll()
835
853
  * .executeTakeFirstOrThrow()
836
854
  * ```
837
855
  */
856
+ $assertType() {
857
+ return new SelectQueryBuilder(this.#props);
858
+ }
859
+ /**
860
+ * @deprecated Use `$assertType` instead.
861
+ */
838
862
  assertType() {
839
863
  return new SelectQueryBuilder(this.#props);
840
864
  }
@@ -5,7 +5,7 @@ import { TableExpression, From, FromTables } from '../parser/table-parser.js';
5
5
  import { SelectExpression } from '../parser/select-parser.js';
6
6
  import { ReturningRow } from '../parser/returning-parser.js';
7
7
  import { ReferenceExpression } from '../parser/reference-parser.js';
8
- import { MergePartial, Nullable, SingleResultType } from '../util/type-utils.js';
8
+ import { MergePartial, Nullable, SimplifyResult, SimplifySingleResult } from '../util/type-utils.js';
9
9
  import { UpdateQueryNode } from '../operation-node/update-query-node.js';
10
10
  import { UpdateObject } from '../parser/update-set-parser.js';
11
11
  import { Compilable } from '../util/compilable.js';
@@ -741,7 +741,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
741
741
  * Simply calls the given function passing `this` as the only argument.
742
742
  *
743
743
  * If you want to conditionally call a method on `this`, see
744
- * the {@link if} method.
744
+ * the {@link $if} method.
745
745
  *
746
746
  * ### Examples
747
747
  *
@@ -755,10 +755,14 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
755
755
  *
756
756
  * db.updateTable('person')
757
757
  * .set(values)
758
- * .call(log)
758
+ * .$call(log)
759
759
  * .execute()
760
760
  * ```
761
761
  */
762
+ $call<T>(func: (qb: this) => T): T;
763
+ /**
764
+ * @deprecated Use `$call` instead
765
+ */
762
766
  call<T>(func: (qb: this) => T): T;
763
767
  /**
764
768
  * Call `func(this)` if `condition` is true.
@@ -779,7 +783,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
779
783
  * .set(updates)
780
784
  * .where('id', '=', id)
781
785
  * .returning(['id', 'first_name'])
782
- * .if(returnLastName, (qb) => qb.returning('last_name'))
786
+ * .$if(returnLastName, (qb) => qb.returning('last_name'))
783
787
  * .executeTakeFirstOrThrow()
784
788
  * }
785
789
  * ```
@@ -796,6 +800,10 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
796
800
  * }
797
801
  * ```
798
802
  */
803
+ $if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, UT, TB, O2>): UpdateQueryBuilder<DB, UT, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
804
+ /**
805
+ * @deprecated Use `$if` instead
806
+ */
799
807
  if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, UT, TB, O2>): UpdateQueryBuilder<DB, UT, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
800
808
  /**
801
809
  * Change the output type of the query.
@@ -803,6 +811,10 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
803
811
  * You should only use this method as the last resort if the types
804
812
  * don't support your use case.
805
813
  */
814
+ $castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
815
+ /**
816
+ * @deprecated Use `$castTo` instead.
817
+ */
806
818
  castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
807
819
  /**
808
820
  * Asserts that query's output row type equals the given type `T`.
@@ -833,38 +845,42 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
833
845
  * .set(person)
834
846
  * .where('id', '=', person.id)
835
847
  * .returning('first_name')
836
- * .assertType<{ first_name: string }>()
848
+ * .$assertType<{ first_name: string }>()
837
849
  * )
838
850
  * .with('updated_pet', (qb) => qb
839
851
  * .updateTable('pet')
840
852
  * .set(pet)
841
853
  * .where('owner_id', '=', person.id)
842
854
  * .returning(['name as pet_name', 'species'])
843
- * .assertType<{ pet_name: string, species: Species }>()
855
+ * .$assertType<{ pet_name: string, species: Species }>()
844
856
  * )
845
857
  * .selectFrom(['updated_person', 'updated_pet'])
846
858
  * .selectAll()
847
859
  * .executeTakeFirstOrThrow()
848
860
  * ```
849
861
  */
862
+ $assertType<T extends O>(): O extends T ? UpdateQueryBuilder<DB, UT, TB, T> : KyselyTypeError<`$assertType() call failed: The type passed in is not equal to the output type of the query.`>;
863
+ /**
864
+ * @deprecated Use `$assertType` instead.
865
+ */
850
866
  assertType<T extends O>(): O extends T ? UpdateQueryBuilder<DB, UT, TB, T> : KyselyTypeError<`assertType() call failed: The type passed in is not equal to the output type of the query.`>;
851
867
  /**
852
868
  * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
853
869
  */
854
870
  withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, UT, TB, O>;
855
871
  toOperationNode(): UpdateQueryNode;
856
- compile(): CompiledQuery<O>;
872
+ compile(): CompiledQuery<SimplifyResult<O>>;
857
873
  /**
858
874
  * Executes the query and returns an array of rows.
859
875
  *
860
876
  * Also see the {@link executeTakeFirst} and {@link executeTakeFirstOrThrow} methods.
861
877
  */
862
- execute(): Promise<O[]>;
878
+ execute(): Promise<SimplifyResult<O>[]>;
863
879
  /**
864
880
  * Executes the query and returns the first result or undefined if
865
881
  * the query returned no result.
866
882
  */
867
- executeTakeFirst(): Promise<SingleResultType<O>>;
883
+ executeTakeFirst(): Promise<SimplifySingleResult<O>>;
868
884
  /**
869
885
  * Executes the query and returns the first result or throws if
870
886
  * the query returned no result.
@@ -873,7 +889,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
873
889
  * provide a custom error class as the only argument to throw a different
874
890
  * error.
875
891
  */
876
- executeTakeFirstOrThrow(errorConstructor?: NoResultErrorConstructor): Promise<O>;
892
+ executeTakeFirstOrThrow(errorConstructor?: NoResultErrorConstructor): Promise<SimplifyResult<O>>;
877
893
  /**
878
894
  * Executes query with `explain` statement before `update` keyword.
879
895
  *
@@ -210,7 +210,7 @@ export class UpdateQueryBuilder {
210
210
  * Simply calls the given function passing `this` as the only argument.
211
211
  *
212
212
  * If you want to conditionally call a method on `this`, see
213
- * the {@link if} method.
213
+ * the {@link $if} method.
214
214
  *
215
215
  * ### Examples
216
216
  *
@@ -224,13 +224,19 @@ export class UpdateQueryBuilder {
224
224
  *
225
225
  * db.updateTable('person')
226
226
  * .set(values)
227
- * .call(log)
227
+ * .$call(log)
228
228
  * .execute()
229
229
  * ```
230
230
  */
231
- call(func) {
231
+ $call(func) {
232
232
  return func(this);
233
233
  }
234
+ /**
235
+ * @deprecated Use `$call` instead
236
+ */
237
+ call(func) {
238
+ return this.$call(func);
239
+ }
234
240
  /**
235
241
  * Call `func(this)` if `condition` is true.
236
242
  *
@@ -250,7 +256,7 @@ export class UpdateQueryBuilder {
250
256
  * .set(updates)
251
257
  * .where('id', '=', id)
252
258
  * .returning(['id', 'first_name'])
253
- * .if(returnLastName, (qb) => qb.returning('last_name'))
259
+ * .$if(returnLastName, (qb) => qb.returning('last_name'))
254
260
  * .executeTakeFirstOrThrow()
255
261
  * }
256
262
  * ```
@@ -267,7 +273,7 @@ export class UpdateQueryBuilder {
267
273
  * }
268
274
  * ```
269
275
  */
270
- if(condition, func) {
276
+ $if(condition, func) {
271
277
  if (condition) {
272
278
  return func(this);
273
279
  }
@@ -275,15 +281,27 @@ export class UpdateQueryBuilder {
275
281
  ...this.#props,
276
282
  });
277
283
  }
284
+ /**
285
+ * @deprecated Use `$if` instead
286
+ */
287
+ if(condition, func) {
288
+ return this.$if(condition, func);
289
+ }
278
290
  /**
279
291
  * Change the output type of the query.
280
292
  *
281
293
  * You should only use this method as the last resort if the types
282
294
  * don't support your use case.
283
295
  */
284
- castTo() {
296
+ $castTo() {
285
297
  return new UpdateQueryBuilder(this.#props);
286
298
  }
299
+ /**
300
+ * @deprecated Use `$castTo` instead.
301
+ */
302
+ castTo() {
303
+ return this.$castTo();
304
+ }
287
305
  /**
288
306
  * Asserts that query's output row type equals the given type `T`.
289
307
  *
@@ -313,20 +331,26 @@ export class UpdateQueryBuilder {
313
331
  * .set(person)
314
332
  * .where('id', '=', person.id)
315
333
  * .returning('first_name')
316
- * .assertType<{ first_name: string }>()
334
+ * .$assertType<{ first_name: string }>()
317
335
  * )
318
336
  * .with('updated_pet', (qb) => qb
319
337
  * .updateTable('pet')
320
338
  * .set(pet)
321
339
  * .where('owner_id', '=', person.id)
322
340
  * .returning(['name as pet_name', 'species'])
323
- * .assertType<{ pet_name: string, species: Species }>()
341
+ * .$assertType<{ pet_name: string, species: Species }>()
324
342
  * )
325
343
  * .selectFrom(['updated_person', 'updated_pet'])
326
344
  * .selectAll()
327
345
  * .executeTakeFirstOrThrow()
328
346
  * ```
329
347
  */
348
+ $assertType() {
349
+ return new UpdateQueryBuilder(this.#props);
350
+ }
351
+ /**
352
+ * @deprecated Use `$assertType` instead.
353
+ */
330
354
  assertType() {
331
355
  return new UpdateQueryBuilder(this.#props);
332
356
  }
@@ -360,7 +384,7 @@ export class UpdateQueryBuilder {
360
384
  return [
361
385
  new UpdateResult(
362
386
  // TODO: remove numUpdatedOrDeletedRows.
363
- (result.numAffectedRows ?? result.numUpdatedOrDeletedRows)),
387
+ result.numAffectedRows ?? result.numUpdatedOrDeletedRows ?? 0n),
364
388
  ];
365
389
  }
366
390
  /**
@@ -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 ');
@@ -855,7 +862,7 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
855
862
  if (node.distinct) {
856
863
  this.append('distinct ');
857
864
  }
858
- this.visitNode(node.column);
865
+ this.visitNode(node.aggregated);
859
866
  this.append(')');
860
867
  if (node.filter) {
861
868
  this.append(' filter(');
@@ -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
  }