kysely 0.23.1 → 0.23.2

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 (56) hide show
  1. package/README.md +5 -0
  2. package/dist/cjs/operation-node/on-conflict-node.d.ts +2 -0
  3. package/dist/cjs/operation-node/on-conflict-node.js +12 -0
  4. package/dist/cjs/operation-node/query-node.d.ts +1 -0
  5. package/dist/cjs/operation-node/query-node.js +6 -0
  6. package/dist/cjs/operation-node/select-query-node.d.ts +4 -0
  7. package/dist/cjs/operation-node/select-query-node.js +24 -0
  8. package/dist/cjs/query-builder/delete-query-builder.d.ts +63 -1
  9. package/dist/cjs/query-builder/delete-query-builder.js +51 -1
  10. package/dist/cjs/query-builder/insert-query-builder.d.ts +44 -1
  11. package/dist/cjs/query-builder/insert-query-builder.js +45 -1
  12. package/dist/cjs/query-builder/on-conflict-builder.d.ts +38 -0
  13. package/dist/cjs/query-builder/on-conflict-builder.js +12 -0
  14. package/dist/cjs/query-builder/select-query-builder.d.ts +138 -1
  15. package/dist/cjs/query-builder/select-query-builder.js +146 -1
  16. package/dist/cjs/query-builder/update-query-builder.d.ts +65 -1
  17. package/dist/cjs/query-builder/update-query-builder.js +53 -1
  18. package/dist/cjs/query-builder/where-interface.d.ts +19 -0
  19. package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.d.ts +23 -0
  20. package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.js +38 -0
  21. package/dist/cjs/schema/alter-table-builder.d.ts +3 -35
  22. package/dist/cjs/schema/alter-table-builder.js +10 -102
  23. package/dist/cjs/schema/alter-table-drop-constraint-builder.d.ts +21 -0
  24. package/dist/cjs/schema/alter-table-drop-constraint-builder.js +54 -0
  25. package/dist/cjs/schema/alter-table-executor.d.ts +18 -0
  26. package/dist/cjs/schema/alter-table-executor.js +22 -0
  27. package/dist/cjs/util/type-error.d.ts +3 -0
  28. package/dist/cjs/util/type-error.js +2 -0
  29. package/dist/esm/operation-node/on-conflict-node.d.ts +2 -0
  30. package/dist/esm/operation-node/on-conflict-node.js +12 -0
  31. package/dist/esm/operation-node/query-node.d.ts +1 -0
  32. package/dist/esm/operation-node/query-node.js +6 -0
  33. package/dist/esm/operation-node/select-query-node.d.ts +4 -0
  34. package/dist/esm/operation-node/select-query-node.js +24 -0
  35. package/dist/esm/query-builder/delete-query-builder.d.ts +63 -1
  36. package/dist/esm/query-builder/delete-query-builder.js +51 -1
  37. package/dist/esm/query-builder/insert-query-builder.d.ts +44 -1
  38. package/dist/esm/query-builder/insert-query-builder.js +45 -1
  39. package/dist/esm/query-builder/on-conflict-builder.d.ts +38 -0
  40. package/dist/esm/query-builder/on-conflict-builder.js +12 -0
  41. package/dist/esm/query-builder/select-query-builder.d.ts +138 -1
  42. package/dist/esm/query-builder/select-query-builder.js +146 -1
  43. package/dist/esm/query-builder/update-query-builder.d.ts +65 -1
  44. package/dist/esm/query-builder/update-query-builder.js +53 -1
  45. package/dist/esm/query-builder/where-interface.d.ts +19 -0
  46. package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.d.ts +23 -0
  47. package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.js +35 -0
  48. package/dist/esm/schema/alter-table-builder.d.ts +3 -35
  49. package/dist/esm/schema/alter-table-builder.js +4 -93
  50. package/dist/esm/schema/alter-table-drop-constraint-builder.d.ts +21 -0
  51. package/dist/esm/schema/alter-table-drop-constraint-builder.js +51 -0
  52. package/dist/esm/schema/alter-table-executor.d.ts +18 -0
  53. package/dist/esm/schema/alter-table-executor.js +19 -0
  54. package/dist/esm/util/type-error.d.ts +3 -0
  55. package/dist/esm/util/type-error.js +2 -0
  56. package/package.json +2 -2
@@ -581,6 +581,109 @@ 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
+ * Clears all select clauses from the query.
586
+ *
587
+ * ### Examples
588
+ *
589
+ * ```ts
590
+ * db.selectFrom('person')
591
+ * .select(['id', 'first_name'])
592
+ * .clearSelect()
593
+ * .select(['id','gender'])
594
+ * ```
595
+ *
596
+ * The generated SQL(PostgreSQL):
597
+ *
598
+ * ```sql
599
+ * select "id", "gender" from "person"
600
+ * ```
601
+ */
602
+ clearSelect() {
603
+ return new SelectQueryBuilder({
604
+ ...this.#props,
605
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithoutSelections(this.#props.queryNode),
606
+ });
607
+ }
608
+ clearWhere() {
609
+ return new SelectQueryBuilder({
610
+ ...this.#props,
611
+ queryNode: query_node_js_1.QueryNode.cloneWithoutWhere(this.#props.queryNode),
612
+ });
613
+ }
614
+ /**
615
+ * Clears limit clause from the query.
616
+ *
617
+ * ### Examples
618
+ *
619
+ * ```ts
620
+ * db.selectFrom('person')
621
+ * .selectAll()
622
+ * .limit(10)
623
+ * .clearLimit()
624
+ * ```
625
+ *
626
+ * The generated SQL(PostgreSQL):
627
+ *
628
+ * ```sql
629
+ * select * from "person"
630
+ * ```
631
+ */
632
+ clearLimit() {
633
+ return new SelectQueryBuilder({
634
+ ...this.#props,
635
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithoutLimit(this.#props.queryNode),
636
+ });
637
+ }
638
+ /**
639
+ * Clears offset clause from the query.
640
+ *
641
+ * ### Examples
642
+ *
643
+ * ```ts
644
+ * db.selectFrom('person')
645
+ * .selectAll()
646
+ * .limit(10)
647
+ * .offset(20)
648
+ * .clearOffset()
649
+ * ```
650
+ *
651
+ * The generated SQL(PostgreSQL):
652
+ *
653
+ * ```sql
654
+ * select * from "person" limit 10
655
+ * ```
656
+ */
657
+ clearOffset() {
658
+ return new SelectQueryBuilder({
659
+ ...this.#props,
660
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithoutOffset(this.#props.queryNode),
661
+ });
662
+ }
663
+ /**
664
+ * Clears all `order by` clauses from the query.
665
+ *
666
+ * ### Examples
667
+ *
668
+ * ```ts
669
+ * db.selectFrom('person')
670
+ * .selectAll()
671
+ * .orderBy('id')
672
+ * .clearOrderBy()
673
+ * ```
674
+ *
675
+ * The generated SQL(PostgreSQL):
676
+ *
677
+ * ```sql
678
+ * select * from "person"
679
+ * ```
680
+ */
681
+ clearOrderBy() {
682
+ return new SelectQueryBuilder({
683
+ ...this.#props,
684
+ queryNode: select_query_node_js_1.SelectQueryNode.cloneWithoutOrderBy(this.#props.queryNode),
685
+ });
686
+ }
584
687
  /**
585
688
  * Simply calls the given function passing `this` as the only argument.
586
689
  *
@@ -589,7 +692,7 @@ class SelectQueryBuilder {
589
692
  *
590
693
  * ### Examples
591
694
  *
592
- * The next example uses a helper funtion `log` to log a query:
695
+ * The next example uses a helper function `log` to log a query:
593
696
  *
594
697
  * ```ts
595
698
  * function log<T extends Compilable>(qb: T): T {
@@ -695,6 +798,48 @@ class SelectQueryBuilder {
695
798
  castTo() {
696
799
  return new SelectQueryBuilder(this.#props);
697
800
  }
801
+ /**
802
+ * Asserts that query's output row type equals the given type `T`.
803
+ *
804
+ * This method can be used to simplify excessively complex types to make typescript happy
805
+ * and much faster.
806
+ *
807
+ * Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
808
+ * for typescript and you get errors like this:
809
+ *
810
+ * ```
811
+ * error TS2589: Type instantiation is excessively deep and possibly infinite.
812
+ * ```
813
+ *
814
+ * In these case you can often use this method to help typescript a little bit. When you use this
815
+ * method to assert the output type of a query, Kysely can drop the complex output type that
816
+ * consists of multiple nested helper types and replace it with the simple asserted type.
817
+ *
818
+ * Using this method doesn't reduce type safety at all. You have to pass in a type that is
819
+ * structurally equal to the current type.
820
+ *
821
+ * ### Examples
822
+ *
823
+ * ```ts
824
+ * const result = await db
825
+ * .with('first_and_last', (qb) => qb
826
+ * .selectFrom('person')
827
+ * .select(['first_name', 'last_name'])
828
+ * .assertType<{ first_name: string, last_name: string }>()
829
+ * )
830
+ * .with('age', (qb) => qb
831
+ * .selectFrom('person')
832
+ * .select('age')
833
+ * .assertType<{ age: number }>()
834
+ * )
835
+ * .selectFrom(['first_and_last', 'age'])
836
+ * .selectAll()
837
+ * .executeTakeFirstOrThrow()
838
+ * ```
839
+ */
840
+ assertType() {
841
+ return new SelectQueryBuilder(this.#props);
842
+ }
698
843
  /**
699
844
  * Returns a copy of this SelectQueryBuilder instance with the given plugin installed.
700
845
  */
@@ -21,6 +21,7 @@ import { Explainable, ExplainFormat } from '../util/explainable.js';
21
21
  import { AliasedExpression, Expression } from '../expression/expression.js';
22
22
  import { ComparisonOperatorExpression, OperandValueExpressionOrList, WhereGrouper } from '../parser/binary-operation-parser.js';
23
23
  import { ExistsExpression } from '../parser/unary-operation-parser.js';
24
+ import { KyselyTypeError } from '../util/type-error.js';
24
25
  export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable<O>, Explainable {
25
26
  #private;
26
27
  constructor(props: UpdateQueryBuilderProps);
@@ -408,6 +409,25 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
408
409
  * Just like {@link whereExists} but creates an `or not exists` clause.
409
410
  */
410
411
  orWhereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
412
+ /**
413
+ * Clears all where clauses from the query.
414
+ *
415
+ * ### Examples
416
+ *
417
+ * ```ts
418
+ * db.selectFrom('person')
419
+ * .selectAll()
420
+ * .where('id','=',42)
421
+ * .clearWhere()
422
+ * ```
423
+ *
424
+ * The generated SQL(PostgreSQL):
425
+ *
426
+ * ```sql
427
+ * select * from "person"
428
+ * ```
429
+ */
430
+ clearWhere(): UpdateQueryBuilder<DB, UT, TB, O>;
411
431
  /**
412
432
  * Adds a from clause to the update query.
413
433
  *
@@ -725,7 +745,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
725
745
  *
726
746
  * ### Examples
727
747
  *
728
- * The next example uses a helper funtion `log` to log a query:
748
+ * The next example uses a helper function `log` to log a query:
729
749
  *
730
750
  * ```ts
731
751
  * function log<T extends Compilable>(qb: T): T {
@@ -784,6 +804,50 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
784
804
  * don't support your use case.
785
805
  */
786
806
  castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
807
+ /**
808
+ * Asserts that query's output row type equals the given type `T`.
809
+ *
810
+ * This method can be used to simplify excessively complex types to make typescript happy
811
+ * and much faster.
812
+ *
813
+ * Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
814
+ * for typescript and you get errors like this:
815
+ *
816
+ * ```
817
+ * error TS2589: Type instantiation is excessively deep and possibly infinite.
818
+ * ```
819
+ *
820
+ * In these case you can often use this method to help typescript a little bit. When you use this
821
+ * method to assert the output type of a query, Kysely can drop the complex output type that
822
+ * consists of multiple nested helper types and replace it with the simple asserted type.
823
+ *
824
+ * Using this method doesn't reduce type safety at all. You have to pass in a type that is
825
+ * structurally equal to the current type.
826
+ *
827
+ * ### Examples
828
+ *
829
+ * ```ts
830
+ * const result = await db
831
+ * .with('updated_person', (qb) => qb
832
+ * .updateTable('person')
833
+ * .set(person)
834
+ * .where('id', '=', person.id)
835
+ * .returning('first_name')
836
+ * .assertType<{ first_name: string }>()
837
+ * )
838
+ * .with('updated_pet', (qb) => qb
839
+ * .updateTable('pet')
840
+ * .set(pet)
841
+ * .where('owner_id', '=', person.id)
842
+ * .returning(['name as pet_name', 'species'])
843
+ * .assertType<{ pet_name: string, species: Species }>()
844
+ * )
845
+ * .selectFrom(['updated_person', 'updated_pet'])
846
+ * .selectAll()
847
+ * .executeTakeFirstOrThrow()
848
+ * ```
849
+ */
850
+ 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.`>;
787
851
  /**
788
852
  * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
789
853
  */
@@ -67,6 +67,12 @@ class UpdateQueryBuilder {
67
67
  queryNode: query_node_js_1.QueryNode.cloneWithOrWhere(this.#props.queryNode, (0, unary_operation_parser_js_1.parseNotExists)(arg)),
68
68
  });
69
69
  }
70
+ clearWhere() {
71
+ return new UpdateQueryBuilder({
72
+ ...this.#props,
73
+ queryNode: query_node_js_1.QueryNode.cloneWithoutWhere(this.#props.queryNode),
74
+ });
75
+ }
70
76
  from(from) {
71
77
  return new UpdateQueryBuilder({
72
78
  ...this.#props,
@@ -210,7 +216,7 @@ class UpdateQueryBuilder {
210
216
  *
211
217
  * ### Examples
212
218
  *
213
- * The next example uses a helper funtion `log` to log a query:
219
+ * The next example uses a helper function `log` to log a query:
214
220
  *
215
221
  * ```ts
216
222
  * function log<T extends Compilable>(qb: T): T {
@@ -280,6 +286,52 @@ class UpdateQueryBuilder {
280
286
  castTo() {
281
287
  return new UpdateQueryBuilder(this.#props);
282
288
  }
289
+ /**
290
+ * Asserts that query's output row type equals the given type `T`.
291
+ *
292
+ * This method can be used to simplify excessively complex types to make typescript happy
293
+ * and much faster.
294
+ *
295
+ * Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
296
+ * for typescript and you get errors like this:
297
+ *
298
+ * ```
299
+ * error TS2589: Type instantiation is excessively deep and possibly infinite.
300
+ * ```
301
+ *
302
+ * In these case you can often use this method to help typescript a little bit. When you use this
303
+ * method to assert the output type of a query, Kysely can drop the complex output type that
304
+ * consists of multiple nested helper types and replace it with the simple asserted type.
305
+ *
306
+ * Using this method doesn't reduce type safety at all. You have to pass in a type that is
307
+ * structurally equal to the current type.
308
+ *
309
+ * ### Examples
310
+ *
311
+ * ```ts
312
+ * const result = await db
313
+ * .with('updated_person', (qb) => qb
314
+ * .updateTable('person')
315
+ * .set(person)
316
+ * .where('id', '=', person.id)
317
+ * .returning('first_name')
318
+ * .assertType<{ first_name: string }>()
319
+ * )
320
+ * .with('updated_pet', (qb) => qb
321
+ * .updateTable('pet')
322
+ * .set(pet)
323
+ * .where('owner_id', '=', person.id)
324
+ * .returning(['name as pet_name', 'species'])
325
+ * .assertType<{ pet_name: string, species: Species }>()
326
+ * )
327
+ * .selectFrom(['updated_person', 'updated_pet'])
328
+ * .selectAll()
329
+ * .executeTakeFirstOrThrow()
330
+ * ```
331
+ */
332
+ assertType() {
333
+ return new UpdateQueryBuilder(this.#props);
334
+ }
283
335
  /**
284
336
  * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
285
337
  */
@@ -387,4 +387,23 @@ export interface WhereInterface<DB, TB extends keyof DB> {
387
387
  * Just like {@link whereExists} but creates an `or not exists` clause.
388
388
  */
389
389
  orWhereNotExists(arg: ExistsExpression<DB, TB>): WhereInterface<DB, TB>;
390
+ /**
391
+ * Clears all where clauses from the query.
392
+ *
393
+ * ### Examples
394
+ *
395
+ * ```ts
396
+ * db.selectFrom('person')
397
+ * .selectAll()
398
+ * .where('id','=',42)
399
+ * .clearWhere()
400
+ * ```
401
+ *
402
+ * The generated SQL(PostgreSQL):
403
+ *
404
+ * ```sql
405
+ * select * from "person"
406
+ * ```
407
+ */
408
+ clearWhere(): WhereInterface<DB, TB>;
390
409
  }
@@ -0,0 +1,23 @@
1
+ import { AlterTableNode } from '../operation-node/alter-table-node.js';
2
+ import { OperationNodeSource } from '../operation-node/operation-node-source.js';
3
+ import { OnModifyForeignAction } from '../operation-node/references-node.js';
4
+ import { CompiledQuery } from '../query-compiler/compiled-query.js';
5
+ import { QueryExecutor } from '../query-executor/query-executor.js';
6
+ import { Compilable } from '../util/compilable.js';
7
+ import { QueryId } from '../util/query-id.js';
8
+ import { ForeignKeyConstraintBuilder, ForeignKeyConstraintBuilderInterface } from './foreign-key-constraint-builder.js';
9
+ export declare class AlterTableAddForeignKeyConstraintBuilder implements ForeignKeyConstraintBuilderInterface<AlterTableAddForeignKeyConstraintBuilder>, OperationNodeSource, Compilable {
10
+ #private;
11
+ constructor(props: AlterTableAddForeignKeyConstraintBuilderProps);
12
+ onDelete(onDelete: OnModifyForeignAction): AlterTableAddForeignKeyConstraintBuilder;
13
+ onUpdate(onUpdate: OnModifyForeignAction): AlterTableAddForeignKeyConstraintBuilder;
14
+ toOperationNode(): AlterTableNode;
15
+ compile(): CompiledQuery;
16
+ execute(): Promise<void>;
17
+ }
18
+ export interface AlterTableAddForeignKeyConstraintBuilderProps {
19
+ readonly queryId: QueryId;
20
+ readonly executor: QueryExecutor;
21
+ readonly node: AlterTableNode;
22
+ readonly constraintBuilder: ForeignKeyConstraintBuilder;
23
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlterTableAddForeignKeyConstraintBuilder = void 0;
4
+ const add_constraint_node_js_1 = require("../operation-node/add-constraint-node.js");
5
+ const alter_table_node_js_1 = require("../operation-node/alter-table-node.js");
6
+ const object_utils_js_1 = require("../util/object-utils.js");
7
+ const prevent_await_js_1 = require("../util/prevent-await.js");
8
+ class AlterTableAddForeignKeyConstraintBuilder {
9
+ #props;
10
+ constructor(props) {
11
+ this.#props = (0, object_utils_js_1.freeze)(props);
12
+ }
13
+ onDelete(onDelete) {
14
+ return new AlterTableAddForeignKeyConstraintBuilder({
15
+ ...this.#props,
16
+ constraintBuilder: this.#props.constraintBuilder.onDelete(onDelete),
17
+ });
18
+ }
19
+ onUpdate(onUpdate) {
20
+ return new AlterTableAddForeignKeyConstraintBuilder({
21
+ ...this.#props,
22
+ constraintBuilder: this.#props.constraintBuilder.onUpdate(onUpdate),
23
+ });
24
+ }
25
+ toOperationNode() {
26
+ return this.#props.executor.transformQuery(alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
27
+ addConstraint: add_constraint_node_js_1.AddConstraintNode.create(this.#props.constraintBuilder.toOperationNode()),
28
+ }), this.#props.queryId);
29
+ }
30
+ compile() {
31
+ return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
32
+ }
33
+ async execute() {
34
+ await this.#props.executor.executeQuery(this.compile(), this.#props.queryId);
35
+ }
36
+ }
37
+ exports.AlterTableAddForeignKeyConstraintBuilder = AlterTableAddForeignKeyConstraintBuilder;
38
+ (0, prevent_await_js_1.preventAwait)(AlterTableAddForeignKeyConstraintBuilder, "don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");
@@ -1,15 +1,16 @@
1
1
  import { AlterTableNode } from '../operation-node/alter-table-node.js';
2
2
  import { OperationNodeSource } from '../operation-node/operation-node-source.js';
3
- import { OnModifyForeignAction } from '../operation-node/references-node.js';
4
3
  import { CompiledQuery } from '../query-compiler/compiled-query.js';
5
4
  import { Compilable } from '../util/compilable.js';
6
5
  import { ColumnDefinitionBuilderCallback } from './column-definition-builder.js';
7
6
  import { QueryId } from '../util/query-id.js';
8
7
  import { QueryExecutor } from '../query-executor/query-executor.js';
9
8
  import { DataTypeExpression } from '../parser/data-type-parser.js';
10
- import { ForeignKeyConstraintBuilder, ForeignKeyConstraintBuilderInterface } from './foreign-key-constraint-builder.js';
11
9
  import { Expression } from '../expression/expression.js';
12
10
  import { AlterColumnBuilderCallback } from './alter-column-builder.js';
11
+ import { AlterTableExecutor } from './alter-table-executor.js';
12
+ import { AlterTableAddForeignKeyConstraintBuilder } from './alter-table-add-foreign-key-constraint-builder.js';
13
+ import { AlterTableDropConstraintBuilder } from './alter-table-drop-constraint-builder.js';
13
14
  /**
14
15
  * This builder can be used to create a `alter table` query.
15
16
  */
@@ -60,15 +61,6 @@ export interface AlterTableBuilderProps {
60
61
  readonly executor: QueryExecutor;
61
62
  readonly node: AlterTableNode;
62
63
  }
63
- export declare class AlterTableExecutor implements OperationNodeSource, Compilable {
64
- #private;
65
- constructor(props: AlterTableExecutorProps);
66
- toOperationNode(): AlterTableNode;
67
- compile(): CompiledQuery;
68
- execute(): Promise<void>;
69
- }
70
- export interface AlterTableExecutorProps extends AlterTableBuilderProps {
71
- }
72
64
  export interface ColumnAlteringInterface {
73
65
  alterColumn(column: string, alteration: AlterColumnBuilderCallback): ColumnAlteringInterface;
74
66
  dropColumn(column: string): ColumnAlteringInterface;
@@ -106,27 +98,3 @@ export declare class AlterTableColumnAlteringBuilder implements ColumnAlteringIn
106
98
  }
107
99
  export interface AlterTableColumnAlteringBuilderProps extends AlterTableBuilderProps {
108
100
  }
109
- export declare class AlterTableAddForeignKeyConstraintBuilder implements ForeignKeyConstraintBuilderInterface<AlterTableAddForeignKeyConstraintBuilder>, OperationNodeSource, Compilable {
110
- #private;
111
- constructor(props: AlterTableAddForeignKeyConstraintBuilderProps);
112
- onDelete(onDelete: OnModifyForeignAction): AlterTableAddForeignKeyConstraintBuilder;
113
- onUpdate(onUpdate: OnModifyForeignAction): AlterTableAddForeignKeyConstraintBuilder;
114
- toOperationNode(): AlterTableNode;
115
- compile(): CompiledQuery;
116
- execute(): Promise<void>;
117
- }
118
- export interface AlterTableAddForeignKeyConstraintBuilderProps extends AlterTableBuilderProps {
119
- readonly constraintBuilder: ForeignKeyConstraintBuilder;
120
- }
121
- export declare class AlterTableDropConstraintBuilder implements OperationNodeSource, Compilable {
122
- #private;
123
- constructor(props: AlterTableDropConstraintBuilderProps);
124
- ifExists(): AlterTableDropConstraintBuilder;
125
- cascade(): AlterTableDropConstraintBuilder;
126
- restrict(): AlterTableDropConstraintBuilder;
127
- toOperationNode(): AlterTableNode;
128
- compile(): CompiledQuery;
129
- execute(): Promise<void>;
130
- }
131
- export interface AlterTableDropConstraintBuilderProps extends AlterTableBuilderProps {
132
- }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AlterTableDropConstraintBuilder = exports.AlterTableAddForeignKeyConstraintBuilder = exports.AlterTableColumnAlteringBuilder = exports.AlterTableExecutor = exports.AlterTableBuilder = void 0;
3
+ exports.AlterTableColumnAlteringBuilder = exports.AlterTableBuilder = void 0;
4
4
  const add_column_node_js_1 = require("../operation-node/add-column-node.js");
5
5
  const alter_column_node_js_1 = require("../operation-node/alter-column-node.js");
6
6
  const alter_table_node_js_1 = require("../operation-node/alter-table-node.js");
@@ -22,6 +22,9 @@ const column_node_js_1 = require("../operation-node/column-node.js");
22
22
  const table_parser_js_1 = require("../parser/table-parser.js");
23
23
  const drop_constraint_node_js_1 = require("../operation-node/drop-constraint-node.js");
24
24
  const alter_column_builder_js_1 = require("./alter-column-builder.js");
25
+ const alter_table_executor_js_1 = require("./alter-table-executor.js");
26
+ const alter_table_add_foreign_key_constraint_builder_js_1 = require("./alter-table-add-foreign-key-constraint-builder.js");
27
+ const alter_table_drop_constraint_builder_js_1 = require("./alter-table-drop-constraint-builder.js");
25
28
  /**
26
29
  * This builder can be used to create a `alter table` query.
27
30
  */
@@ -31,7 +34,7 @@ class AlterTableBuilder {
31
34
  this.#props = (0, object_utils_js_1.freeze)(props);
32
35
  }
33
36
  renameTo(newTableName) {
34
- return new AlterTableExecutor({
37
+ return new alter_table_executor_js_1.AlterTableExecutor({
35
38
  ...this.#props,
36
39
  node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
37
40
  renameTo: (0, table_parser_js_1.parseTable)(newTableName),
@@ -39,7 +42,7 @@ class AlterTableBuilder {
39
42
  });
40
43
  }
41
44
  setSchema(newSchema) {
42
- return new AlterTableExecutor({
45
+ return new alter_table_executor_js_1.AlterTableExecutor({
43
46
  ...this.#props,
44
47
  node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
45
48
  setSchema: identifier_node_js_1.IdentifierNode.create(newSchema),
@@ -83,7 +86,7 @@ class AlterTableBuilder {
83
86
  * See {@link CreateTableBuilder.addUniqueConstraint}
84
87
  */
85
88
  addUniqueConstraint(constraintName, columns) {
86
- return new AlterTableExecutor({
89
+ return new alter_table_executor_js_1.AlterTableExecutor({
87
90
  ...this.#props,
88
91
  node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
89
92
  addConstraint: add_constraint_node_js_1.AddConstraintNode.create(unique_constraint_node_js_1.UniqueConstraintNode.create(columns, constraintName)),
@@ -94,7 +97,7 @@ class AlterTableBuilder {
94
97
  * See {@link CreateTableBuilder.addCheckConstraint}
95
98
  */
96
99
  addCheckConstraint(constraintName, checkExpression) {
97
- return new AlterTableExecutor({
100
+ return new alter_table_executor_js_1.AlterTableExecutor({
98
101
  ...this.#props,
99
102
  node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
100
103
  addConstraint: add_constraint_node_js_1.AddConstraintNode.create(check_constraint_node_js_1.CheckConstraintNode.create(checkExpression.toOperationNode(), constraintName)),
@@ -109,13 +112,13 @@ class AlterTableBuilder {
109
112
  * is because you can only add one column per `ALTER TABLE` query.
110
113
  */
111
114
  addForeignKeyConstraint(constraintName, columns, targetTable, targetColumns) {
112
- return new AlterTableAddForeignKeyConstraintBuilder({
115
+ return new alter_table_add_foreign_key_constraint_builder_js_1.AlterTableAddForeignKeyConstraintBuilder({
113
116
  ...this.#props,
114
117
  constraintBuilder: new foreign_key_constraint_builder_js_1.ForeignKeyConstraintBuilder(foreign_key_constraint_node_js_1.ForeignKeyConstraintNode.create(columns.map(column_node_js_1.ColumnNode.create), (0, table_parser_js_1.parseTable)(targetTable), targetColumns.map(column_node_js_1.ColumnNode.create), constraintName)),
115
118
  });
116
119
  }
117
120
  dropConstraint(constraintName) {
118
- return new AlterTableDropConstraintBuilder({
121
+ return new alter_table_drop_constraint_builder_js_1.AlterTableDropConstraintBuilder({
119
122
  ...this.#props,
120
123
  node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
121
124
  dropConstraint: drop_constraint_node_js_1.DropConstraintNode.create(constraintName),
@@ -132,22 +135,6 @@ class AlterTableBuilder {
132
135
  }
133
136
  }
134
137
  exports.AlterTableBuilder = AlterTableBuilder;
135
- class AlterTableExecutor {
136
- #props;
137
- constructor(props) {
138
- this.#props = (0, object_utils_js_1.freeze)(props);
139
- }
140
- toOperationNode() {
141
- return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
142
- }
143
- compile() {
144
- return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
145
- }
146
- async execute() {
147
- await this.#props.executor.executeQuery(this.compile(), this.#props.queryId);
148
- }
149
- }
150
- exports.AlterTableExecutor = AlterTableExecutor;
151
138
  class AlterTableColumnAlteringBuilder {
152
139
  #props;
153
140
  constructor(props) {
@@ -197,85 +184,6 @@ class AlterTableColumnAlteringBuilder {
197
184
  }
198
185
  }
199
186
  exports.AlterTableColumnAlteringBuilder = AlterTableColumnAlteringBuilder;
200
- class AlterTableAddForeignKeyConstraintBuilder {
201
- #props;
202
- constructor(props) {
203
- this.#props = (0, object_utils_js_1.freeze)(props);
204
- }
205
- onDelete(onDelete) {
206
- return new AlterTableAddForeignKeyConstraintBuilder({
207
- ...this.#props,
208
- constraintBuilder: this.#props.constraintBuilder.onDelete(onDelete),
209
- });
210
- }
211
- onUpdate(onUpdate) {
212
- return new AlterTableAddForeignKeyConstraintBuilder({
213
- ...this.#props,
214
- constraintBuilder: this.#props.constraintBuilder.onUpdate(onUpdate),
215
- });
216
- }
217
- toOperationNode() {
218
- return this.#props.executor.transformQuery(alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
219
- addConstraint: add_constraint_node_js_1.AddConstraintNode.create(this.#props.constraintBuilder.toOperationNode()),
220
- }), this.#props.queryId);
221
- }
222
- compile() {
223
- return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
224
- }
225
- async execute() {
226
- await this.#props.executor.executeQuery(this.compile(), this.#props.queryId);
227
- }
228
- }
229
- exports.AlterTableAddForeignKeyConstraintBuilder = AlterTableAddForeignKeyConstraintBuilder;
230
- class AlterTableDropConstraintBuilder {
231
- #props;
232
- constructor(props) {
233
- this.#props = (0, object_utils_js_1.freeze)(props);
234
- }
235
- ifExists() {
236
- return new AlterTableDropConstraintBuilder({
237
- ...this.#props,
238
- node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
239
- dropConstraint: drop_constraint_node_js_1.DropConstraintNode.cloneWith(this.#props.node.dropConstraint, {
240
- ifExists: true,
241
- }),
242
- }),
243
- });
244
- }
245
- cascade() {
246
- return new AlterTableDropConstraintBuilder({
247
- ...this.#props,
248
- node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
249
- dropConstraint: drop_constraint_node_js_1.DropConstraintNode.cloneWith(this.#props.node.dropConstraint, {
250
- modifier: 'cascade',
251
- }),
252
- }),
253
- });
254
- }
255
- restrict() {
256
- return new AlterTableDropConstraintBuilder({
257
- ...this.#props,
258
- node: alter_table_node_js_1.AlterTableNode.cloneWithTableProps(this.#props.node, {
259
- dropConstraint: drop_constraint_node_js_1.DropConstraintNode.cloneWith(this.#props.node.dropConstraint, {
260
- modifier: 'restrict',
261
- }),
262
- }),
263
- });
264
- }
265
- toOperationNode() {
266
- return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
267
- }
268
- compile() {
269
- return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
270
- }
271
- async execute() {
272
- await this.#props.executor.executeQuery(this.compile(), this.#props.queryId);
273
- }
274
- }
275
- exports.AlterTableDropConstraintBuilder = AlterTableDropConstraintBuilder;
276
187
  (0, prevent_await_js_1.preventAwait)(AlterTableBuilder, "don't await AlterTableBuilder instances");
277
188
  (0, prevent_await_js_1.preventAwait)(alter_column_builder_js_1.AlterColumnBuilder, "don't await AlterColumnBuilder instances");
278
- (0, prevent_await_js_1.preventAwait)(AlterTableExecutor, "don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");
279
189
  (0, prevent_await_js_1.preventAwait)(AlterTableColumnAlteringBuilder, "don't await AlterTableColumnAlteringBuilder instances directly. To execute the query you need to call `execute`");
280
- (0, prevent_await_js_1.preventAwait)(AlterTableAddForeignKeyConstraintBuilder, "don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");
281
- (0, prevent_await_js_1.preventAwait)(AlterTableDropConstraintBuilder, "don't await AlterTableDropConstraintBuilder instances directly. To execute the query you need to call `execute`");
@@ -0,0 +1,21 @@
1
+ import { AlterTableNode } from '../operation-node/alter-table-node.js';
2
+ import { OperationNodeSource } from '../operation-node/operation-node-source.js';
3
+ import { CompiledQuery } from '../query-compiler/compiled-query.js';
4
+ import { QueryExecutor } from '../query-executor/query-executor.js';
5
+ import { Compilable } from '../util/compilable.js';
6
+ import { QueryId } from '../util/query-id.js';
7
+ export declare class AlterTableDropConstraintBuilder implements OperationNodeSource, Compilable {
8
+ #private;
9
+ constructor(props: AlterTableDropConstraintBuilderProps);
10
+ ifExists(): AlterTableDropConstraintBuilder;
11
+ cascade(): AlterTableDropConstraintBuilder;
12
+ restrict(): AlterTableDropConstraintBuilder;
13
+ toOperationNode(): AlterTableNode;
14
+ compile(): CompiledQuery;
15
+ execute(): Promise<void>;
16
+ }
17
+ export interface AlterTableDropConstraintBuilderProps {
18
+ readonly queryId: QueryId;
19
+ readonly executor: QueryExecutor;
20
+ readonly node: AlterTableNode;
21
+ }