kysely 0.17.3 → 0.19.0

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 (114) hide show
  1. package/README.md +24 -17
  2. package/dist/cjs/dialect/database-introspector.d.ts +13 -0
  3. package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +24 -207
  4. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +26 -3
  5. package/dist/cjs/dialect/mysql/mysql-dialect.js +27 -5
  6. package/dist/cjs/dialect/mysql/mysql-driver.d.ts +13 -4
  7. package/dist/cjs/dialect/mysql/mysql-driver.js +33 -51
  8. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +11 -1
  9. package/dist/cjs/dialect/mysql/mysql-introspector.js +29 -7
  10. package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +25 -89
  11. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +25 -5
  12. package/dist/cjs/dialect/postgres/postgres-dialect.js +26 -7
  13. package/dist/cjs/dialect/postgres/postgres-driver.d.ts +12 -3
  14. package/dist/cjs/dialect/postgres/postgres-driver.js +21 -39
  15. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +11 -1
  16. package/dist/cjs/dialect/postgres/postgres-introspector.js +15 -4
  17. package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +25 -28
  18. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +19 -3
  19. package/dist/cjs/dialect/sqlite/sqlite-dialect.js +19 -3
  20. package/dist/cjs/dialect/sqlite/sqlite-driver.js +3 -37
  21. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +11 -1
  22. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +11 -4
  23. package/dist/cjs/index.d.ts +153 -2
  24. package/dist/cjs/index.js +147 -3
  25. package/dist/cjs/migration/file-migration-provider.d.ts +21 -5
  26. package/dist/cjs/migration/file-migration-provider.js +14 -13
  27. package/dist/cjs/migration/migrator.d.ts +44 -2
  28. package/dist/cjs/migration/migrator.js +77 -18
  29. package/dist/cjs/operation-node/alias-node.d.ts +2 -2
  30. package/dist/cjs/operation-node/alias-node.js +1 -2
  31. package/dist/cjs/operation-node/operation-node-transformer.js +1 -0
  32. package/dist/cjs/operation-node/update-query-node.d.ts +3 -0
  33. package/dist/cjs/operation-node/update-query-node.js +11 -2
  34. package/dist/cjs/parser/reference-parser.js +2 -1
  35. package/dist/cjs/parser/table-parser.js +2 -1
  36. package/dist/cjs/parser/update-set-parser.d.ts +3 -3
  37. package/dist/cjs/parser/with-parser.d.ts +2 -2
  38. package/dist/cjs/plugin/noop-plugin.d.ts +42 -0
  39. package/dist/cjs/plugin/noop-plugin.js +12 -0
  40. package/dist/cjs/query-builder/insert-query-builder.d.ts +1 -1
  41. package/dist/cjs/query-builder/on-conflict-builder.d.ts +1 -1
  42. package/dist/cjs/query-builder/select-query-builder.d.ts +3 -1
  43. package/dist/cjs/query-builder/select-query-builder.js +5 -5
  44. package/dist/cjs/query-builder/update-query-builder.d.ts +57 -28
  45. package/dist/cjs/query-builder/update-query-builder.js +7 -0
  46. package/dist/cjs/query-compiler/default-query-compiler.js +4 -0
  47. package/dist/cjs/query-creator.d.ts +10 -1
  48. package/dist/cjs/query-creator.js +18 -0
  49. package/dist/cjs/raw-builder/raw-builder.d.ts +32 -2
  50. package/dist/cjs/raw-builder/raw-builder.js +5 -26
  51. package/dist/cjs/schema/schema.d.ts +9 -0
  52. package/dist/cjs/schema/schema.js +12 -0
  53. package/dist/cjs/util/column-type.d.ts +9 -1
  54. package/dist/cjs/util/stack-trace-utils.d.ts +1 -0
  55. package/dist/cjs/util/stack-trace-utils.js +17 -0
  56. package/dist/esm/dialect/database-introspector.d.ts +13 -0
  57. package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +24 -207
  58. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +26 -3
  59. package/dist/esm/dialect/mysql/mysql-dialect.js +27 -5
  60. package/dist/esm/dialect/mysql/mysql-driver.d.ts +13 -4
  61. package/dist/esm/dialect/mysql/mysql-driver.js +33 -51
  62. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +11 -1
  63. package/dist/esm/dialect/mysql/mysql-introspector.js +30 -8
  64. package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +25 -89
  65. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +25 -5
  66. package/dist/esm/dialect/postgres/postgres-dialect.js +26 -7
  67. package/dist/esm/dialect/postgres/postgres-driver.d.ts +12 -3
  68. package/dist/esm/dialect/postgres/postgres-driver.js +21 -39
  69. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +11 -1
  70. package/dist/esm/dialect/postgres/postgres-introspector.js +16 -5
  71. package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +25 -28
  72. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +19 -3
  73. package/dist/esm/dialect/sqlite/sqlite-dialect.js +19 -3
  74. package/dist/esm/dialect/sqlite/sqlite-driver.js +4 -38
  75. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +11 -1
  76. package/dist/esm/dialect/sqlite/sqlite-introspector.js +12 -5
  77. package/dist/esm/index.d.ts +153 -2
  78. package/dist/esm/index.js +142 -2
  79. package/dist/esm/migration/file-migration-provider.d.ts +21 -5
  80. package/dist/esm/migration/file-migration-provider.js +14 -13
  81. package/dist/esm/migration/migrator.d.ts +44 -2
  82. package/dist/esm/migration/migrator.js +76 -17
  83. package/dist/esm/operation-node/alias-node.d.ts +2 -2
  84. package/dist/esm/operation-node/alias-node.js +1 -2
  85. package/dist/esm/operation-node/operation-node-transformer.js +1 -0
  86. package/dist/esm/operation-node/update-query-node.d.ts +3 -0
  87. package/dist/esm/operation-node/update-query-node.js +11 -2
  88. package/dist/esm/parser/reference-parser.js +2 -1
  89. package/dist/esm/parser/table-parser.js +2 -1
  90. package/dist/esm/parser/update-set-parser.d.ts +3 -3
  91. package/dist/esm/parser/with-parser.d.ts +2 -2
  92. package/dist/esm/plugin/noop-plugin.d.ts +42 -0
  93. package/dist/esm/plugin/noop-plugin.js +9 -0
  94. package/dist/esm/query-builder/insert-query-builder.d.ts +1 -1
  95. package/dist/esm/query-builder/on-conflict-builder.d.ts +1 -1
  96. package/dist/esm/query-builder/select-query-builder.d.ts +3 -1
  97. package/dist/esm/query-builder/select-query-builder.js +5 -5
  98. package/dist/esm/query-builder/update-query-builder.d.ts +57 -28
  99. package/dist/esm/query-builder/update-query-builder.js +7 -0
  100. package/dist/esm/query-compiler/default-query-compiler.js +4 -0
  101. package/dist/esm/query-creator.d.ts +10 -1
  102. package/dist/esm/query-creator.js +18 -0
  103. package/dist/esm/raw-builder/raw-builder.d.ts +32 -2
  104. package/dist/esm/raw-builder/raw-builder.js +5 -26
  105. package/dist/esm/schema/schema.d.ts +9 -0
  106. package/dist/esm/schema/schema.js +12 -0
  107. package/dist/esm/util/column-type.d.ts +9 -1
  108. package/dist/esm/util/stack-trace-utils.d.ts +1 -0
  109. package/dist/esm/util/stack-trace-utils.js +14 -0
  110. package/package.json +10 -15
  111. package/dist/cjs/index-nodeless.d.ts +0 -152
  112. package/dist/cjs/index-nodeless.js +0 -153
  113. package/dist/esm/index-nodeless.d.ts +0 -152
  114. package/dist/esm/index-nodeless.js +0 -142
@@ -19,7 +19,7 @@ import { JoinInterface } from './join-interface.js';
19
19
  import { ReturningInterface } from './returning-interface.js';
20
20
  import { NoResultErrorConstructor } from './no-result-error.js';
21
21
  import { Selectable } from '../util/column-type.js';
22
- export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
22
+ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
23
23
  #private;
24
24
  constructor(props: UpdateQueryBuilderProps);
25
25
  /**
@@ -206,9 +206,9 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
206
206
  * .execute()
207
207
  * ```
208
208
  */
209
- where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, TB, O>;
210
- where(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
211
- where(raw: AnyRawBuilder): UpdateQueryBuilder<DB, TB, O>;
209
+ where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, UT, TB, O>;
210
+ where(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
211
+ where(raw: AnyRawBuilder): UpdateQueryBuilder<DB, UT, TB, O>;
212
212
  /**
213
213
  * Adds a `where` clause where both sides of the operator are references
214
214
  * to columns.
@@ -260,7 +260,7 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
260
260
  * ) as "pet_name"
261
261
  * from "person"
262
262
  */
263
- whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
263
+ whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
264
264
  /**
265
265
  * Adds an `or where` clause to the query. Otherwise works just like {@link where}.
266
266
  *
@@ -324,15 +324,15 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
324
324
  * select * from "person" (where "id" = 1 or "id" = 2)
325
325
  * ```
326
326
  */
327
- orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, TB, O>;
328
- orWhere(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
329
- orWhere(raw: AnyRawBuilder): UpdateQueryBuilder<DB, TB, O>;
327
+ orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, UT, TB, O>;
328
+ orWhere(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
329
+ orWhere(raw: AnyRawBuilder): UpdateQueryBuilder<DB, UT, TB, O>;
330
330
  /**
331
331
  * Adds an `or where` clause to the query. Otherwise works just like {@link whereRef}.
332
332
  *
333
333
  * Also see {@link orWhere} and {@link where}.
334
334
  */
335
- orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
335
+ orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
336
336
  /**
337
337
  * Adds a `where exists` clause to the query.
338
338
  *
@@ -393,19 +393,48 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
393
393
  * )
394
394
  * ```
395
395
  */
396
- whereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
396
+ whereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
397
397
  /**
398
398
  * Just like {@link whereExists} but creates a `not exists` clause.
399
399
  */
400
- whereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
400
+ whereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
401
401
  /**
402
402
  * Just like {@link whereExists} but creates a `or exists` clause.
403
403
  */
404
- orWhereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
404
+ orWhereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
405
405
  /**
406
406
  * Just like {@link whereExists} but creates a `or not exists` clause.
407
407
  */
408
- orWhereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
408
+ orWhereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
409
+ /**
410
+ * Adds a from clause to the update query.
411
+ *
412
+ * This is supported only on some databases like PostgreSQL.
413
+ *
414
+ * The API is the same as {@link QueryCreator.selectFrom}.
415
+ *
416
+ * ### Examples
417
+ *
418
+ * ```ts
419
+ * db.updateTable('person')
420
+ * .from('pet')
421
+ * .set({
422
+ * first_name: (eb) => eb.ref('pet.name')
423
+ * })
424
+ * .whereRef('pet.owner_id', '=', 'person.id')
425
+ * ```
426
+ *
427
+ * The generated SQL (PostgreSQL):
428
+ *
429
+ * ```sql
430
+ * update "person"
431
+ * set "first_name" = "pet"."name"
432
+ * from "pet"
433
+ * where "pet"."owner_id" = "person"."id"
434
+ * ```
435
+ */
436
+ from<TE extends TableExpression<DB, TB>>(table: TE): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
437
+ from<TE extends TableExpression<DB, TB>>(table: TE[]): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
409
438
  /**
410
439
  * Joins another table to the query using an inner join.
411
440
  *
@@ -515,23 +544,23 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
515
544
  * on "doggos"."owner_id" = "person"."id"
516
545
  * ```
517
546
  */
518
- innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
519
- innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
547
+ innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
548
+ innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
520
549
  /**
521
550
  * Just like {@link innerJoin} but adds a left join nstead of an inner join.
522
551
  */
523
- leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
524
- leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
552
+ leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
553
+ leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
525
554
  /**
526
555
  * Just like {@link innerJoin} but adds a right join instead of an inner join.
527
556
  */
528
- rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
529
- rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
557
+ rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
558
+ rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
530
559
  /**
531
560
  * Just like {@link innerJoin} but adds a full join instead of an inner join.
532
561
  */
533
- fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
534
- fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
562
+ fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
563
+ fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
535
564
  /**
536
565
  * Sets the values to update for an {@link Kysely.updateTable | update} query.
537
566
  *
@@ -619,7 +648,7 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
619
648
  * where "id" = $4
620
649
  * ```
621
650
  */
622
- set(row: MutationObject<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
651
+ set(row: MutationObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>;
623
652
  /**
624
653
  * Allows you to return data from modified rows.
625
654
  *
@@ -679,13 +708,13 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
679
708
  * .executeTakeFirst()
680
709
  * ```
681
710
  */
682
- returning<SE extends SelectExpression<DB, TB>>(selections: ReadonlyArray<SE>): UpdateQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
683
- returning<SE extends SelectExpression<DB, TB>>(selection: SE): UpdateQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
711
+ returning<SE extends SelectExpression<DB, TB>>(selections: ReadonlyArray<SE>): UpdateQueryBuilder<DB, UT, TB, ReturningRow<DB, TB, O, SE>>;
712
+ returning<SE extends SelectExpression<DB, TB>>(selection: SE): UpdateQueryBuilder<DB, UT, TB, ReturningRow<DB, TB, O, SE>>;
684
713
  /**
685
714
  * Adds a `returning *` to an insert/update/delete query on databases
686
715
  * that support `returning` such as PostgreSQL.
687
716
  */
688
- returningAll(): UpdateQueryBuilder<DB, TB, Selectable<DB[TB]>>;
717
+ returningAll(): UpdateQueryBuilder<DB, UT, TB, Selectable<DB[TB]>>;
689
718
  /**
690
719
  * Simply calls the given function passing `this` as the only argument.
691
720
  *
@@ -745,18 +774,18 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
745
774
  * }
746
775
  * ```
747
776
  */
748
- if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, TB, O2>): UpdateQueryBuilder<DB, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
777
+ 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>>;
749
778
  /**
750
779
  * Change the output type of the query.
751
780
  *
752
781
  * You should only use this method as the last resort if the types
753
782
  * don't support your use case.
754
783
  */
755
- castTo<T>(): UpdateQueryBuilder<DB, TB, T>;
784
+ castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
756
785
  /**
757
786
  * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
758
787
  */
759
- withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, TB, O>;
788
+ withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, UT, TB, O>;
760
789
  toOperationNode(): UpdateQueryNode;
761
790
  compile(): CompiledQuery;
762
791
  /**
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UpdateQueryBuilder = void 0;
4
4
  const join_parser_js_1 = require("../parser/join-parser.js");
5
+ const table_parser_js_1 = require("../parser/table-parser.js");
5
6
  const select_parser_js_1 = require("../parser/select-parser.js");
6
7
  const filter_parser_js_1 = require("../parser/filter-parser.js");
7
8
  const query_node_js_1 = require("../operation-node/query-node.js");
@@ -64,6 +65,12 @@ class UpdateQueryBuilder {
64
65
  queryNode: query_node_js_1.QueryNode.cloneWithOrWhere(this.#props.queryNode, (0, filter_parser_js_1.parseNotExistFilter)(arg)),
65
66
  });
66
67
  }
68
+ from(from) {
69
+ return new UpdateQueryBuilder({
70
+ ...this.#props,
71
+ queryNode: update_query_node_js_1.UpdateQueryNode.cloneWithFromItems(this.#props.queryNode, (0, table_parser_js_1.parseTableExpressionOrList)(from)),
72
+ });
73
+ }
67
74
  innerJoin(...args) {
68
75
  return new UpdateQueryBuilder({
69
76
  ...this.#props,
@@ -427,6 +427,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
427
427
  if (node.updates) {
428
428
  this.compileList(node.updates);
429
429
  }
430
+ if (node.from) {
431
+ this.append(' ');
432
+ this.visitNode(node.from);
433
+ }
430
434
  if (node.joins) {
431
435
  this.append(' ');
432
436
  this.compileList(node.joins, ' ');
@@ -9,6 +9,7 @@ import { WithNode } from './operation-node/with-node.js';
9
9
  import { InsertResult } from './query-builder/insert-result.js';
10
10
  import { DeleteResult } from './query-builder/delete-result.js';
11
11
  import { UpdateResult } from './query-builder/update-result.js';
12
+ import { KyselyPlugin } from './plugin/kysely-plugin.js';
12
13
  export declare class QueryCreator<DB> {
13
14
  #private;
14
15
  constructor(props: QueryCreatorProps);
@@ -203,7 +204,7 @@ export declare class QueryCreator<DB> {
203
204
  * console.log(result.numUpdatedRows)
204
205
  * ```
205
206
  */
206
- updateTable<TR extends TableReference<DB>>(table: TR): UpdateQueryBuilder<TableExpressionDatabase<DB, TR>, TableExpressionTables<DB, never, TR>, UpdateResult>;
207
+ updateTable<TR extends TableReference<DB>>(table: TR): UpdateQueryBuilder<TableExpressionDatabase<DB, TR>, TableExpressionTables<DB, never, TR>, TableExpressionTables<DB, never, TR>, UpdateResult>;
207
208
  /**
208
209
  * Creates a `with` query (Common Table Expression).
209
210
  *
@@ -252,6 +253,14 @@ export declare class QueryCreator<DB> {
252
253
  * See the {@link with} method for examples and more documentation.
253
254
  */
254
255
  withRecursive<N extends string, E extends RecursiveCommonTableExpression<DB, N>>(name: N, expression: E): QueryCreatorWithCommonTableExpression<DB, N, E>;
256
+ /**
257
+ * Returns a copy of this query creator instance with the given plugin installed.
258
+ */
259
+ withPlugin(plugin: KyselyPlugin): QueryCreator<DB>;
260
+ /**
261
+ * Returns a copy of this query creator instance without any plugins.
262
+ */
263
+ withoutPlugins(): QueryCreator<DB>;
255
264
  /**
256
265
  * Sets the schema to be used for all table references that don't explicitly
257
266
  * specify a schema.
@@ -192,6 +192,24 @@ class QueryCreator {
192
192
  : with_node_js_1.WithNode.create(cte, { recursive: true }),
193
193
  });
194
194
  }
195
+ /**
196
+ * Returns a copy of this query creator instance with the given plugin installed.
197
+ */
198
+ withPlugin(plugin) {
199
+ return new QueryCreator({
200
+ ...this.#props,
201
+ executor: this.#props.executor.withPlugin(plugin),
202
+ });
203
+ }
204
+ /**
205
+ * Returns a copy of this query creator instance without any plugins.
206
+ */
207
+ withoutPlugins() {
208
+ return new QueryCreator({
209
+ ...this.#props,
210
+ executor: this.#props.executor.withoutPlugins(),
211
+ });
212
+ }
195
213
  /**
196
214
  * Sets the schema to be used for all table references that don't explicitly
197
215
  * specify a schema.
@@ -5,6 +5,7 @@ import { RawNode } from '../operation-node/raw-node.js';
5
5
  import { KyselyPlugin } from '../plugin/kysely-plugin.js';
6
6
  import { QueryExecutorProvider } from '../query-executor/query-executor-provider.js';
7
7
  import { QueryId } from '../util/query-id.js';
8
+ import { AnyRawBuilder } from '../util/type-utils.js';
8
9
  /**
9
10
  * An instance of this class can be used to create raw SQL snippets or queries.
10
11
  *
@@ -38,8 +39,37 @@ export declare class RawBuilder<O = unknown> implements OperationNodeSource {
38
39
  * select concat(first_name, ' ', last_name) as "full_name"
39
40
  * from "person"
40
41
  * ```
42
+ *
43
+ * You can also pass in a raw SQL snippet but in that case you must
44
+ * provide the alias as the only type argument:
45
+ *
46
+ * ```ts
47
+ * const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
48
+ *
49
+ * // The alias is `t(a, b)` which specifies the column names
50
+ * // in addition to the table name. We must tell kysely that
51
+ * // columns of the table can be referenced through `t`
52
+ * // by providing an explicit type argument.
53
+ * const aliasedValues = values.as<'t'>(sql`t(a, b)`)
54
+ *
55
+ * await db
56
+ * .insertInto('person')
57
+ * .columns(['first_name', 'last_name'])
58
+ * .expression(
59
+ * db.selectFrom(aliasedValues).select(['t.a', 't.b'])
60
+ * )
61
+ * ```
62
+ *
63
+ * The generated SQL (PostgreSQL):
64
+ *
65
+ * ```ts
66
+ * insert into "person" ("first_name", "last_name")
67
+ * from (values (1, 'foo')) as t(a, b)
68
+ * select "t"."a", "t"."b"
69
+ * ```
41
70
  */
42
71
  as<A extends string>(alias: A): AliasedRawBuilder<O, A>;
72
+ as<A extends string = never>(alias: AnyRawBuilder): AliasedRawBuilder<O, A>;
43
73
  /**
44
74
  * Change the output type of the raw expression.
45
75
  *
@@ -67,9 +97,9 @@ export declare class AliasedRawBuilder<O = unknown, A extends string = never> im
67
97
  * which causes this type to be equal to AliasedRawBuilder with any A
68
98
  * as long as O is the same.
69
99
  */
70
- protected get alias(): A;
100
+ protected get alias(): A | AnyRawBuilder;
71
101
  toOperationNode(): AliasNode;
72
- constructor(rawBuilder: RawBuilder<O>, alias: A);
102
+ constructor(rawBuilder: RawBuilder<O>, alias: A | AnyRawBuilder);
73
103
  }
74
104
  export interface RawBuilderProps {
75
105
  readonly queryId: QueryId;
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AliasedRawBuilder = exports.RawBuilder = void 0;
4
4
  const alias_node_js_1 = require("../operation-node/alias-node.js");
5
+ const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
5
6
  const prevent_await_js_1 = require("../util/prevent-await.js");
6
7
  const object_utils_js_1 = require("../util/object-utils.js");
7
8
  const noop_query_executor_js_1 = require("../query-executor/noop-query-executor.js");
9
+ const identifier_node_js_1 = require("../operation-node/identifier-node.js");
8
10
  /**
9
11
  * An instance of this class can be used to create raw SQL snippets or queries.
10
12
  *
@@ -16,31 +18,6 @@ class RawBuilder {
16
18
  constructor(props) {
17
19
  this.#props = (0, object_utils_js_1.freeze)(props);
18
20
  }
19
- /**
20
- * Returns an aliased version of the SQL expression.
21
- *
22
- * In addition to slapping `as "the_alias"` to the end of the SQL,
23
- * this method also provides strict typing:
24
- *
25
- * ```ts
26
- * const result = await db
27
- * .selectFrom('person')
28
- * .select(
29
- * sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
30
- * )
31
- * .executeTakeFirstOrThrow()
32
- *
33
- * // `full_name: string` field exists in the result type.
34
- * console.log(result.full_name)
35
- * ```
36
- *
37
- * The generated SQL (PostgreSQL):
38
- *
39
- * ```ts
40
- * select concat(first_name, ' ', last_name) as "full_name"
41
- * from "person"
42
- * ```
43
- */
44
21
  as(alias) {
45
22
  return new AliasedRawBuilder(this, alias);
46
23
  }
@@ -103,7 +80,9 @@ class AliasedRawBuilder {
103
80
  return this.#alias;
104
81
  }
105
82
  toOperationNode() {
106
- return alias_node_js_1.AliasNode.create(this.#rawBuilder.toOperationNode(), this.#alias);
83
+ return alias_node_js_1.AliasNode.create(this.#rawBuilder.toOperationNode(), (0, operation_node_source_js_1.isOperationNodeSource)(this.#alias)
84
+ ? this.#alias.toOperationNode()
85
+ : identifier_node_js_1.IdentifierNode.create(this.#alias));
107
86
  }
108
87
  constructor(rawBuilder, alias) {
109
88
  this.#rawBuilder = rawBuilder;
@@ -8,6 +8,7 @@ import { DropSchemaBuilder } from './drop-schema-builder.js';
8
8
  import { DropTableBuilder } from './drop-table-builder.js';
9
9
  import { CreateViewBuilder } from './create-view-builder.js';
10
10
  import { DropViewBuilder } from './drop-view-builder.js';
11
+ import { KyselyPlugin } from '../plugin/kysely-plugin.js';
11
12
  /**
12
13
  * Provides methods for building database schema.
13
14
  */
@@ -169,6 +170,14 @@ export declare class SchemaModule {
169
170
  * ```
170
171
  */
171
172
  dropView(viewName: string): DropViewBuilder;
173
+ /**
174
+ * Returns a copy of this schema module with the given plugin installed.
175
+ */
176
+ withPlugin(plugin: KyselyPlugin): SchemaModule;
177
+ /**
178
+ * Returns a copy of this schema module without any plugins.
179
+ */
180
+ withoutPlugins(): SchemaModule;
172
181
  /**
173
182
  * See {@link QueryCreator.withSchema}
174
183
  */
@@ -239,6 +239,18 @@ class SchemaModule {
239
239
  dropViewNode: drop_view_node_js_1.DropViewNode.create(viewName),
240
240
  });
241
241
  }
242
+ /**
243
+ * Returns a copy of this schema module with the given plugin installed.
244
+ */
245
+ withPlugin(plugin) {
246
+ return new SchemaModule(this.#executor.withPlugin(plugin));
247
+ }
248
+ /**
249
+ * Returns a copy of this schema module without any plugins.
250
+ */
251
+ withoutPlugins() {
252
+ return new SchemaModule(this.#executor.withoutPlugins());
253
+ }
242
254
  /**
243
255
  * See {@link QueryCreator.withSchema}
244
256
  */
@@ -43,13 +43,21 @@ export declare type ColumnType<SelectType, InsertType = SelectType, UpdateType =
43
43
  * is the same for all selects, inserts and updates but the
44
44
  * column is optional for inserts and updates.
45
45
  *
46
- * This is implemented using {@link ColumnType} like this:
46
+ * The implementation:
47
47
  *
48
48
  * ```ts
49
+ * // The update type is `S` instead of `S | undefined` because
50
+ * // updates are always optional --> no need to specify optionality.
49
51
  * type Generated<S> = ColumnType<S, S | undefined, S>
50
52
  * ```
51
53
  */
52
54
  export declare type Generated<S> = ColumnType<S, S | undefined, S>;
55
+ /**
56
+ * A shortcut for defining columns that are only database-generated
57
+ * (like postgres GENERATED ALWAYS AS IDENTITY). No insert/update
58
+ * is allowed.
59
+ */
60
+ export declare type GeneratedAlways<S> = ColumnType<S, never, never>;
53
61
  /**
54
62
  * Evaluates to `K` if `T` can be `null` or `undefined`.
55
63
  */
@@ -0,0 +1 @@
1
+ export declare function extendStackTrace(err: unknown, stackError: Error): unknown;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extendStackTrace = void 0;
4
+ const object_utils_js_1 = require("./object-utils.js");
5
+ function extendStackTrace(err, stackError) {
6
+ if (isStackHolder(err) && stackError.stack) {
7
+ // Remove the first line that just says `Error`.
8
+ const stackExtension = stackError.stack.split('\n').slice(1).join('\n');
9
+ err.stack += `\n${stackExtension}`;
10
+ return err;
11
+ }
12
+ return err;
13
+ }
14
+ exports.extendStackTrace = extendStackTrace;
15
+ function isStackHolder(obj) {
16
+ return (0, object_utils_js_1.isObject)(obj) && (0, object_utils_js_1.isString)(obj.stack);
17
+ }
@@ -3,8 +3,18 @@ import { ColumnDataType } from '../operation-node/data-type-node.js';
3
3
  * An interface for getting the database metadata (names of the tables and columns etc.)
4
4
  */
5
5
  export interface DatabaseIntrospector {
6
+ /**
7
+ * Get schema metadata.
8
+ */
9
+ getSchemas(): Promise<SchemaMetadata[]>;
10
+ /**
11
+ * Get table metadata.
12
+ */
13
+ getTables(options?: DatabaseMetadataOptions): Promise<TableMetadata[]>;
6
14
  /**
7
15
  * Get the database metadata such as table and column names.
16
+ *
17
+ * @deprecated Use getTables() instead.
8
18
  */
9
19
  getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
10
20
  }
@@ -15,6 +25,9 @@ export interface DatabaseMetadataOptions {
15
25
  */
16
26
  withInternalKyselyTables: boolean;
17
27
  }
28
+ export interface SchemaMetadata {
29
+ readonly name: string;
30
+ }
18
31
  export interface DatabaseMetadata {
19
32
  /**
20
33
  * The tables found in the database.