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
  *
@@ -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
- * .call(log)
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
- * .if(withLastName, (qb) => qb.select('last_name'))
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
- * .if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
755
- * .if(filterByPetCount, (qb) => qb
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
- * Gives an alias for the query. This method is only useful for sub queries.
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
- as(alias) {
790
- return new AliasedSelectQueryBuilder(this, alias);
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
- * .assertType<{ first_name: string, last_name: string }>()
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
- * .assertType<{ age: number }>()
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
  }
@@ -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
  *
@@ -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
- * .call(log)
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
- * .if(returnLastName, (qb) => qb.returning('last_name'))
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
- * .assertType<{ first_name: string }>()
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
- * .assertType<{ pet_name: string, species: Species }>()
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
  }
@@ -362,7 +386,7 @@ class UpdateQueryBuilder {
362
386
  return [
363
387
  new update_result_js_1.UpdateResult(
364
388
  // TODO: remove numUpdatedOrDeletedRows.
365
- (result.numAffectedRows ?? result.numUpdatedOrDeletedRows)),
389
+ result.numAffectedRows ?? result.numUpdatedOrDeletedRows ?? 0n),
366
390
  ];
367
391
  }
368
392
  /**
@@ -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 ');
@@ -857,7 +864,7 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
857
864
  if (node.distinct) {
858
865
  this.append('distinct ');
859
866
  }
860
- this.visitNode(node.column);
867
+ this.visitNode(node.aggregated);
861
868
  this.append(')');
862
869
  if (node.filter) {
863
870
  this.append(' filter(');
@@ -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
  }