kysely 0.2.2 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/lib/dialect/postgres/postgres-dialect.js +5 -4
- package/lib/index.d.ts +66 -2
- package/lib/index.js +66 -2
- package/lib/kysely.d.ts +15 -14
- package/lib/kysely.js +17 -16
- package/lib/migration/migration.js +4 -4
- package/lib/operation-node/add-column-node.d.ts +6 -19
- package/lib/operation-node/add-column-node.js +5 -14
- package/lib/operation-node/add-constraint-node.d.ts +13 -0
- package/lib/operation-node/add-constraint-node.js +18 -0
- package/lib/operation-node/alias-node.d.ts +4 -2
- package/lib/operation-node/alias-node.js +3 -0
- package/lib/operation-node/alter-column-node.d.ts +24 -0
- package/lib/operation-node/alter-column-node.js +25 -0
- package/lib/operation-node/alter-table-node.d.ts +30 -0
- package/lib/operation-node/alter-table-node.js +25 -0
- package/lib/operation-node/and-node.d.ts +3 -0
- package/lib/operation-node/and-node.js +3 -0
- package/lib/operation-node/check-constraint-node.d.ts +6 -1
- package/lib/operation-node/check-constraint-node.js +6 -1
- package/lib/operation-node/column-definition-node.d.ts +29 -0
- package/lib/operation-node/column-definition-node.js +30 -0
- package/lib/operation-node/column-node.d.ts +3 -0
- package/lib/operation-node/column-node.js +3 -0
- package/lib/operation-node/column-update-node.d.ts +3 -0
- package/lib/operation-node/column-update-node.js +3 -0
- package/lib/operation-node/common-table-expression-node.d.ts +3 -0
- package/lib/operation-node/common-table-expression-node.js +3 -0
- package/lib/operation-node/constraint-node.d.ts +5 -0
- package/lib/operation-node/constraint-node.js +2 -0
- package/lib/operation-node/create-index-node.d.ts +3 -0
- package/lib/operation-node/create-index-node.js +3 -0
- package/lib/operation-node/create-schema-node.d.ts +3 -0
- package/lib/operation-node/create-schema-node.js +3 -0
- package/lib/operation-node/create-table-node.d.ts +12 -12
- package/lib/operation-node/create-table-node.js +30 -12
- package/lib/operation-node/data-type-node.d.ts +4 -1
- package/lib/operation-node/data-type-node.js +3 -0
- package/lib/operation-node/delete-query-node.d.ts +3 -0
- package/lib/operation-node/delete-query-node.js +3 -0
- package/lib/operation-node/drop-column-node.d.ts +13 -0
- package/lib/operation-node/drop-column-node.js +19 -0
- package/lib/operation-node/drop-constraint-node.d.ts +13 -0
- package/lib/operation-node/drop-constraint-node.js +19 -0
- package/lib/operation-node/drop-index-node.d.ts +3 -0
- package/lib/operation-node/drop-index-node.js +3 -0
- package/lib/operation-node/drop-schema-node.d.ts +3 -0
- package/lib/operation-node/drop-schema-node.js +3 -0
- package/lib/operation-node/drop-table-node.d.ts +5 -2
- package/lib/operation-node/drop-table-node.js +3 -0
- package/lib/operation-node/filter-node.d.ts +3 -0
- package/lib/operation-node/filter-node.js +3 -0
- package/lib/operation-node/foreign-key-constraint-node.d.ts +18 -0
- package/lib/operation-node/foreign-key-constraint-node.js +22 -0
- package/lib/operation-node/from-node.d.ts +3 -0
- package/lib/operation-node/from-node.js +3 -0
- package/lib/operation-node/group-by-item-node.d.ts +3 -0
- package/lib/operation-node/group-by-item-node.js +3 -0
- package/lib/operation-node/group-by-node.d.ts +3 -0
- package/lib/operation-node/group-by-node.js +3 -0
- package/lib/operation-node/having-node.d.ts +3 -0
- package/lib/operation-node/having-node.js +3 -0
- package/lib/operation-node/identifier-node.d.ts +3 -0
- package/lib/operation-node/identifier-node.js +3 -0
- package/lib/operation-node/insert-query-node.d.ts +3 -0
- package/lib/operation-node/insert-query-node.js +3 -0
- package/lib/operation-node/join-node.d.ts +3 -0
- package/lib/operation-node/join-node.js +3 -0
- package/lib/operation-node/limit-node.d.ts +3 -0
- package/lib/operation-node/limit-node.js +3 -0
- package/lib/operation-node/list-node.d.ts +3 -0
- package/lib/operation-node/list-node.js +3 -0
- package/lib/operation-node/offset-node.d.ts +3 -0
- package/lib/operation-node/offset-node.js +3 -0
- package/lib/operation-node/on-conflict-node.d.ts +3 -0
- package/lib/operation-node/on-conflict-node.js +3 -0
- package/lib/operation-node/operation-node-transformer.d.ts +20 -4
- package/lib/operation-node/operation-node-transformer.js +86 -12
- package/lib/operation-node/operation-node-visitor.d.ts +20 -4
- package/lib/operation-node/operation-node-visitor.js +75 -5
- package/lib/operation-node/operation-node.d.ts +1 -1
- package/lib/operation-node/operator-node.d.ts +3 -0
- package/lib/operation-node/operator-node.js +3 -0
- package/lib/operation-node/or-node.d.ts +3 -0
- package/lib/operation-node/or-node.js +3 -0
- package/lib/operation-node/order-by-item-node.d.ts +3 -0
- package/lib/operation-node/order-by-item-node.js +3 -0
- package/lib/operation-node/order-by-node.d.ts +3 -0
- package/lib/operation-node/order-by-node.js +3 -0
- package/lib/operation-node/parens-node.d.ts +3 -0
- package/lib/operation-node/parens-node.js +3 -0
- package/lib/operation-node/primary-constraint-node.d.ts +15 -0
- package/lib/operation-node/primary-constraint-node.js +21 -0
- package/lib/operation-node/primitive-value-list-node.d.ts +3 -0
- package/lib/operation-node/primitive-value-list-node.js +3 -0
- package/lib/operation-node/query-node.d.ts +3 -0
- package/lib/operation-node/query-node.js +3 -0
- package/lib/operation-node/raw-node.d.ts +3 -0
- package/lib/operation-node/raw-node.js +3 -0
- package/lib/operation-node/reference-node.d.ts +3 -0
- package/lib/operation-node/reference-node.js +3 -0
- package/lib/operation-node/references-node.d.ts +5 -2
- package/lib/operation-node/references-node.js +5 -2
- package/lib/operation-node/rename-column-node.d.ts +14 -0
- package/lib/operation-node/rename-column-node.js +20 -0
- package/lib/operation-node/returning-node.d.ts +3 -0
- package/lib/operation-node/returning-node.js +3 -0
- package/lib/operation-node/select-all-node.d.ts +3 -0
- package/lib/operation-node/select-all-node.js +3 -0
- package/lib/operation-node/select-query-node.d.ts +3 -0
- package/lib/operation-node/select-query-node.js +3 -0
- package/lib/operation-node/selection-node.d.ts +3 -0
- package/lib/operation-node/selection-node.js +3 -0
- package/lib/operation-node/table-node.d.ts +3 -0
- package/lib/operation-node/table-node.js +3 -0
- package/lib/operation-node/unique-constraint-node.d.ts +15 -0
- package/lib/operation-node/unique-constraint-node.js +21 -0
- package/lib/operation-node/update-query-node.d.ts +3 -0
- package/lib/operation-node/update-query-node.js +3 -0
- package/lib/operation-node/value-list-node.d.ts +3 -0
- package/lib/operation-node/value-list-node.js +3 -0
- package/lib/operation-node/value-node.d.ts +3 -0
- package/lib/operation-node/value-node.js +3 -0
- package/lib/operation-node/where-node.d.ts +3 -0
- package/lib/operation-node/where-node.js +3 -0
- package/lib/operation-node/with-node.d.ts +3 -0
- package/lib/operation-node/with-node.js +3 -0
- package/lib/parser/with-parser.js +1 -1
- package/lib/plugin/camel-case/camel-case-plugin.d.ts +1 -1
- package/lib/plugin/camel-case/camel-case-plugin.js +1 -1
- package/lib/query-builder/query-builder.d.ts +9 -9
- package/lib/query-builder/query-builder.js +6 -6
- package/lib/query-builder/sub-query-builder.d.ts +1 -1
- package/lib/query-builder/sub-query-builder.js +1 -1
- package/lib/query-compiler/default-query-compiler.d.ts +21 -5
- package/lib/query-compiler/default-query-compiler.js +110 -10
- package/lib/query-compiler/query-compiler.d.ts +2 -1
- package/lib/query-creator.d.ts +2 -2
- package/lib/query-creator.js +1 -1
- package/lib/{util → query-executor}/query-executor.d.ts +0 -0
- package/lib/{util → query-executor}/query-executor.js +1 -1
- package/lib/raw-builder/raw-builder.d.ts +2 -2
- package/lib/raw-builder/raw-builder.js +4 -4
- package/lib/schema/alter-table-builder.d.ts +64 -0
- package/lib/schema/alter-table-builder.js +236 -0
- package/lib/schema/{add-column-builder.d.ts → column-definition-builder.d.ts} +25 -15
- package/lib/schema/column-definition-builder.js +66 -0
- package/lib/schema/create-index-builder.d.ts +2 -2
- package/lib/schema/create-index-builder.js +3 -3
- package/lib/schema/create-schema-builder.d.ts +2 -2
- package/lib/schema/create-schema-builder.js +3 -3
- package/lib/schema/create-table-builder.d.ts +28 -13
- package/lib/schema/create-table-builder.js +38 -18
- package/lib/schema/drop-index-builder.d.ts +2 -2
- package/lib/schema/drop-index-builder.js +3 -3
- package/lib/schema/drop-schema-builder.d.ts +2 -2
- package/lib/schema/drop-schema-builder.js +3 -3
- package/lib/schema/drop-table-builder.d.ts +2 -2
- package/lib/schema/drop-table-builder.js +3 -3
- package/lib/schema/schema.d.ts +19 -5
- package/lib/schema/schema.js +24 -4
- package/lib/transformers/with-schema-transformer.d.ts +2 -0
- package/lib/transformers/with-schema-transformer.js +3 -0
- package/lib/util/object-utils.d.ts +1 -0
- package/lib/util/object-utils.js +13 -1
- package/package.json +2 -2
- package/lib/operation-node/table-primary-constraint-node.d.ts +0 -10
- package/lib/operation-node/table-primary-constraint-node.js +0 -16
- package/lib/operation-node/table-unique-constraint-node.d.ts +0 -10
- package/lib/operation-node/table-unique-constraint-node.js +0 -16
- package/lib/schema/add-column-builder.js +0 -116
|
@@ -14,7 +14,7 @@ import { AnyColumn, ManyResultRowType, SingleResultRowType } from './type-utils'
|
|
|
14
14
|
import { OrderByExpression } from '../parser/order-by-parser';
|
|
15
15
|
import { MutationObject } from '../parser/mutation-parser';
|
|
16
16
|
import { Compilable } from '../util/compilable';
|
|
17
|
-
import { QueryExecutor } from '../
|
|
17
|
+
import { QueryExecutor } from '../query-executor/query-executor';
|
|
18
18
|
/**
|
|
19
19
|
* The main query builder class.
|
|
20
20
|
*
|
|
@@ -32,7 +32,7 @@ import { QueryExecutor } from '../util/query-executor';
|
|
|
32
32
|
*/
|
|
33
33
|
export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements OperationNodeSource, Compilable {
|
|
34
34
|
#private;
|
|
35
|
-
constructor(
|
|
35
|
+
constructor(args: QueryBuilderConstructorArgs);
|
|
36
36
|
/**
|
|
37
37
|
* Adds a `where` clause to the query.
|
|
38
38
|
*
|
|
@@ -579,7 +579,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
579
579
|
* person.id
|
|
580
580
|
* ```
|
|
581
581
|
*/
|
|
582
|
-
select<S extends SelectExpression<DB, TB>>(selections: S
|
|
582
|
+
select<S extends SelectExpression<DB, TB>>(selections: ReadonlyArray<S>): QueryBuilderWithSelection<DB, TB, O, S>;
|
|
583
583
|
select<S extends SelectExpression<DB, TB>>(selection: S): QueryBuilderWithSelection<DB, TB, O, S>;
|
|
584
584
|
/**
|
|
585
585
|
* Adds `distinct on` selections to the select clause.
|
|
@@ -603,7 +603,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
603
603
|
* where "pet"."name" = $1
|
|
604
604
|
* ```
|
|
605
605
|
*/
|
|
606
|
-
distinctOn<S extends SelectExpression<DB, TB>>(selections: S
|
|
606
|
+
distinctOn<S extends SelectExpression<DB, TB>>(selections: ReadonlyArray<S>): QueryBuilder<DB, TB, O>;
|
|
607
607
|
distinctOn<S extends SelectExpression<DB, TB>>(selection: S): QueryBuilder<DB, TB, O>;
|
|
608
608
|
/**
|
|
609
609
|
*
|
|
@@ -675,7 +675,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
675
675
|
* select "person".*, "pet".* from "person", "pet"
|
|
676
676
|
* ```
|
|
677
677
|
*/
|
|
678
|
-
selectAll<T extends TB>(table: T
|
|
678
|
+
selectAll<T extends TB>(table: ReadonlyArray<T>): SelectAllQueryBuilder<DB, TB, O, T>;
|
|
679
679
|
selectAll<T extends TB>(table: T): SelectAllQueryBuilder<DB, TB, O, T>;
|
|
680
680
|
selectAll<T extends TB>(): SelectAllQueryBuilder<DB, TB, O, T>;
|
|
681
681
|
/**
|
|
@@ -944,7 +944,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
944
944
|
* ```
|
|
945
945
|
*/
|
|
946
946
|
onConflictDoNothing(column: AnyColumn<DB, TB>): QueryBuilder<DB, TB, O>;
|
|
947
|
-
onConflictDoNothing(columns: AnyColumn<DB, TB
|
|
947
|
+
onConflictDoNothing(columns: ReadonlyArray<AnyColumn<DB, TB>>): QueryBuilder<DB, TB, O>;
|
|
948
948
|
/**
|
|
949
949
|
* Ignores an insert if the column (or columns) given as the first
|
|
950
950
|
* argument conflicts with the current rows in the database and
|
|
@@ -988,7 +988,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
988
988
|
* ```
|
|
989
989
|
*/
|
|
990
990
|
onConflictUpdate(column: AnyColumn<DB, TB>, updates: MutationObject<DB, TB>): QueryBuilder<DB, TB, O>;
|
|
991
|
-
onConflictUpdate(columns: AnyColumn<DB, TB
|
|
991
|
+
onConflictUpdate(columns: ReadonlyArray<AnyColumn<DB, TB>>, updates: MutationObject<DB, TB>): QueryBuilder<DB, TB, O>;
|
|
992
992
|
/**
|
|
993
993
|
* Sets the values to update for an `updateTable` query.
|
|
994
994
|
*
|
|
@@ -1127,7 +1127,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
1127
1127
|
* .executeTakeFirst()
|
|
1128
1128
|
* ```
|
|
1129
1129
|
*/
|
|
1130
|
-
returning<S extends SelectExpression<DB, TB>>(selections: S
|
|
1130
|
+
returning<S extends SelectExpression<DB, TB>>(selections: ReadonlyArray<S>): QueryBuilderWithReturning<DB, TB, O, S>;
|
|
1131
1131
|
returning<S extends SelectExpression<DB, TB>>(selection: S): QueryBuilderWithReturning<DB, TB, O, S>;
|
|
1132
1132
|
/**
|
|
1133
1133
|
* Adds a `returning *` to an insert/update/delete query on databases
|
|
@@ -1319,7 +1319,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
1319
1319
|
* group by "first_name"
|
|
1320
1320
|
* ```
|
|
1321
1321
|
*/
|
|
1322
|
-
groupBy(orderBy: ReferenceExpression<DB, TB
|
|
1322
|
+
groupBy(orderBy: ReadonlyArray<ReferenceExpression<DB, TB>>): QueryBuilder<DB, TB, O>;
|
|
1323
1323
|
groupBy(orderBy: ReferenceExpression<DB, TB>): QueryBuilder<DB, TB, O>;
|
|
1324
1324
|
/**
|
|
1325
1325
|
* Adds a limit clause to the query.
|
|
@@ -18,7 +18,7 @@ const prevent_await_1 = require("../util/prevent-await");
|
|
|
18
18
|
const limit_node_1 = require("../operation-node/limit-node");
|
|
19
19
|
const offset_node_1 = require("../operation-node/offset-node");
|
|
20
20
|
const object_utils_1 = require("../util/object-utils");
|
|
21
|
-
const query_executor_1 = require("../
|
|
21
|
+
const query_executor_1 = require("../query-executor/query-executor");
|
|
22
22
|
/**
|
|
23
23
|
* The main query builder class.
|
|
24
24
|
*
|
|
@@ -37,9 +37,9 @@ const query_executor_1 = require("../util/query-executor");
|
|
|
37
37
|
class QueryBuilder {
|
|
38
38
|
#queryNode;
|
|
39
39
|
#executor;
|
|
40
|
-
constructor(
|
|
41
|
-
this.#queryNode = queryNode;
|
|
42
|
-
this.#executor = executor;
|
|
40
|
+
constructor(args) {
|
|
41
|
+
this.#queryNode = args.queryNode;
|
|
42
|
+
this.#executor = args.executor;
|
|
43
43
|
}
|
|
44
44
|
where(...args) {
|
|
45
45
|
ensureCanHaveWhereClause(this.#queryNode);
|
|
@@ -427,14 +427,14 @@ class QueryBuilder {
|
|
|
427
427
|
ensureCanHaveOnConflict(this.#queryNode);
|
|
428
428
|
return new QueryBuilder({
|
|
429
429
|
executor: this.#executor,
|
|
430
|
-
queryNode: insert_query_node_1.insertQueryNode.cloneWithOnConflictDoNothing(this.#queryNode, object_utils_1.
|
|
430
|
+
queryNode: insert_query_node_1.insertQueryNode.cloneWithOnConflictDoNothing(this.#queryNode, object_utils_1.asReadonlyArray(columns).map(reference_parser_1.parseColumnName)),
|
|
431
431
|
});
|
|
432
432
|
}
|
|
433
433
|
onConflictUpdate(columns, updates) {
|
|
434
434
|
ensureCanHaveOnConflict(this.#queryNode);
|
|
435
435
|
return new QueryBuilder({
|
|
436
436
|
executor: this.#executor,
|
|
437
|
-
queryNode: insert_query_node_1.insertQueryNode.cloneWithOnConflictUpdate(this.#queryNode, object_utils_1.
|
|
437
|
+
queryNode: insert_query_node_1.insertQueryNode.cloneWithOnConflictUpdate(this.#queryNode, object_utils_1.asReadonlyArray(columns).map(reference_parser_1.parseColumnName), update_set_parser_1.parseUpdateObject(updates)),
|
|
438
438
|
});
|
|
439
439
|
}
|
|
440
440
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NeverExecutingQueryExecutor } from '../
|
|
1
|
+
import { NeverExecutingQueryExecutor } from '../query-executor/query-executor';
|
|
2
2
|
import { TableExpression, QueryBuilderWithTable } from '../parser/table-parser';
|
|
3
3
|
export declare class SubQueryBuilder<DB, TB extends keyof DB> {
|
|
4
4
|
#private;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SubQueryBuilder = void 0;
|
|
4
4
|
const query_builder_1 = require("./query-builder");
|
|
5
5
|
const select_query_node_1 = require("../operation-node/select-query-node");
|
|
6
|
-
const query_executor_1 = require("../
|
|
6
|
+
const query_executor_1 = require("../query-executor/query-executor");
|
|
7
7
|
const table_parser_1 = require("../parser/table-parser");
|
|
8
8
|
const with_schema_transformer_1 = require("../transformers/with-schema-transformer");
|
|
9
9
|
class SubQueryBuilder {
|
|
@@ -36,8 +36,8 @@ import { SelectAllNode } from '../operation-node/select-all-node';
|
|
|
36
36
|
import { SelectQueryNode } from '../operation-node/select-query-node';
|
|
37
37
|
import { SelectionNode } from '../operation-node/selection-node';
|
|
38
38
|
import { TableNode } from '../operation-node/table-node';
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
39
|
+
import { PrimaryKeyConstraintNode } from '../operation-node/primary-constraint-node';
|
|
40
|
+
import { UniqueConstraintNode } from '../operation-node/unique-constraint-node';
|
|
41
41
|
import { UpdateQueryNode } from '../operation-node/update-query-node';
|
|
42
42
|
import { ValueListNode } from '../operation-node/value-list-node';
|
|
43
43
|
import { ValueNode } from '../operation-node/value-node';
|
|
@@ -50,6 +50,14 @@ import { CompileEntryPointNode, QueryCompiler } from './query-compiler';
|
|
|
50
50
|
import { HavingNode } from '../operation-node/having-node';
|
|
51
51
|
import { CreateSchemaNode } from '../operation-node/create-schema-node';
|
|
52
52
|
import { DropSchemaNode } from '../operation-node/drop-schema-node';
|
|
53
|
+
import { AlterTableNode } from '../operation-node/alter-table-node';
|
|
54
|
+
import { DropColumnNode } from '../operation-node/drop-column-node';
|
|
55
|
+
import { RenameColumnNode } from '../operation-node/rename-column-node';
|
|
56
|
+
import { AlterColumnNode } from '../operation-node/alter-column-node';
|
|
57
|
+
import { AddConstraintNode } from '../operation-node/add-constraint-node';
|
|
58
|
+
import { DropConstraintNode } from '../operation-node/drop-constraint-node';
|
|
59
|
+
import { ForeignKeyConstraintNode } from '../operation-node/foreign-key-constraint-node';
|
|
60
|
+
import { ColumnDefinitionNode } from '../operation-node/column-definition-node';
|
|
53
61
|
export declare class DefaultQueryCompiler extends OperationNodeVisitor implements QueryCompiler {
|
|
54
62
|
#private;
|
|
55
63
|
compileQuery(node: CompileEntryPointNode): CompiledQuery;
|
|
@@ -81,7 +89,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
81
89
|
protected visitOperator(node: OperatorNode): void;
|
|
82
90
|
protected visitTable(node: TableNode): void;
|
|
83
91
|
protected visitCreateTable(node: CreateTableNode): void;
|
|
84
|
-
protected
|
|
92
|
+
protected visitColumnDefinition(node: ColumnDefinitionNode): void;
|
|
85
93
|
protected visitReferences(node: ReferencesNode): void;
|
|
86
94
|
protected visitDropTable(node: DropTableNode): void;
|
|
87
95
|
protected visitDataType(node: DataTypeNode): void;
|
|
@@ -98,12 +106,20 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
98
106
|
protected visitDropIndex(node: DropIndexNode): void;
|
|
99
107
|
protected visitCreateSchema(node: CreateSchemaNode): void;
|
|
100
108
|
protected visitDropSchema(node: DropSchemaNode): void;
|
|
101
|
-
protected
|
|
102
|
-
protected
|
|
109
|
+
protected visitPrimaryKeyConstraint(node: PrimaryKeyConstraintNode): void;
|
|
110
|
+
protected visitUniqueConstraint(node: UniqueConstraintNode): void;
|
|
103
111
|
protected visitCheckConstraint(node: CheckConstraintNode): void;
|
|
112
|
+
protected visitForeignKeyConstraint(node: ForeignKeyConstraintNode): void;
|
|
104
113
|
protected visitList(node: ListNode): void;
|
|
105
114
|
protected visitWith(node: WithNode): void;
|
|
106
115
|
protected visitCommonTableExpression(node: CommonTableExpressionNode): void;
|
|
116
|
+
protected visitAlterTable(node: AlterTableNode): void;
|
|
117
|
+
protected visitAddColumn(node: AddColumnNode): void;
|
|
118
|
+
protected visitRenameColumn(node: RenameColumnNode): void;
|
|
119
|
+
protected visitDropColumn(node: DropColumnNode): void;
|
|
120
|
+
protected visitAlterColumn(node: AlterColumnNode): void;
|
|
121
|
+
protected visitAddConstraint(node: AddConstraintNode): void;
|
|
122
|
+
protected visitDropConstraint(node: DropConstraintNode): void;
|
|
107
123
|
protected appendLeftIdentifierWrapper(): void;
|
|
108
124
|
protected appendRightIdentifierWrapper(): void;
|
|
109
125
|
protected append(str: string): void;
|
|
@@ -275,15 +275,10 @@ class DefaultQueryCompiler extends operation_node_visitor_1.OperationNodeVisitor
|
|
|
275
275
|
}
|
|
276
276
|
this.visitNode(node.table);
|
|
277
277
|
this.append(' (');
|
|
278
|
-
this.compileList([
|
|
279
|
-
...node.columns,
|
|
280
|
-
...(node.primaryKeyConstraint ? [node.primaryKeyConstraint] : []),
|
|
281
|
-
...(node.uniqueConstraints ?? []),
|
|
282
|
-
...(node.checkConstraints ?? []),
|
|
283
|
-
]);
|
|
278
|
+
this.compileList([...node.columns, ...(node.constraints ?? [])]);
|
|
284
279
|
this.append(')');
|
|
285
280
|
}
|
|
286
|
-
|
|
281
|
+
visitColumnDefinition(node) {
|
|
287
282
|
this.visitNode(node.column);
|
|
288
283
|
this.append(' ');
|
|
289
284
|
if (node.isAutoIncrementing) {
|
|
@@ -325,7 +320,7 @@ class DefaultQueryCompiler extends operation_node_visitor_1.OperationNodeVisitor
|
|
|
325
320
|
this.append('references ');
|
|
326
321
|
this.visitNode(node.table);
|
|
327
322
|
this.append(' (');
|
|
328
|
-
this.
|
|
323
|
+
this.compileList(node.columns);
|
|
329
324
|
this.append(')');
|
|
330
325
|
if (node.onDelete) {
|
|
331
326
|
this.append(' on delete ');
|
|
@@ -463,21 +458,47 @@ class DefaultQueryCompiler extends operation_node_visitor_1.OperationNodeVisitor
|
|
|
463
458
|
}
|
|
464
459
|
this.visitNode(node.schema);
|
|
465
460
|
}
|
|
466
|
-
|
|
461
|
+
visitPrimaryKeyConstraint(node) {
|
|
462
|
+
if (node.name) {
|
|
463
|
+
this.append('constraint ');
|
|
464
|
+
this.visitNode(node.name);
|
|
465
|
+
this.append(' ');
|
|
466
|
+
}
|
|
467
467
|
this.append('primary key (');
|
|
468
468
|
this.compileList(node.columns);
|
|
469
469
|
this.append(')');
|
|
470
470
|
}
|
|
471
|
-
|
|
471
|
+
visitUniqueConstraint(node) {
|
|
472
|
+
if (node.name) {
|
|
473
|
+
this.append('constraint ');
|
|
474
|
+
this.visitNode(node.name);
|
|
475
|
+
this.append(' ');
|
|
476
|
+
}
|
|
472
477
|
this.append('unique (');
|
|
473
478
|
this.compileList(node.columns);
|
|
474
479
|
this.append(')');
|
|
475
480
|
}
|
|
476
481
|
visitCheckConstraint(node) {
|
|
482
|
+
if (node.name) {
|
|
483
|
+
this.append('constraint ');
|
|
484
|
+
this.visitNode(node.name);
|
|
485
|
+
this.append(' ');
|
|
486
|
+
}
|
|
477
487
|
this.append('check (');
|
|
478
488
|
this.visitNode(node.expression);
|
|
479
489
|
this.append(')');
|
|
480
490
|
}
|
|
491
|
+
visitForeignKeyConstraint(node) {
|
|
492
|
+
if (node.name) {
|
|
493
|
+
this.append('constraint ');
|
|
494
|
+
this.visitNode(node.name);
|
|
495
|
+
this.append(' ');
|
|
496
|
+
}
|
|
497
|
+
this.append('foreign key (');
|
|
498
|
+
this.compileList(node.columns);
|
|
499
|
+
this.append(') ');
|
|
500
|
+
this.visitNode(node.references);
|
|
501
|
+
}
|
|
481
502
|
visitList(node) {
|
|
482
503
|
this.compileList(node.items);
|
|
483
504
|
}
|
|
@@ -490,6 +511,85 @@ class DefaultQueryCompiler extends operation_node_visitor_1.OperationNodeVisitor
|
|
|
490
511
|
this.append(' as ');
|
|
491
512
|
this.visitNode(node.expression);
|
|
492
513
|
}
|
|
514
|
+
visitAlterTable(node) {
|
|
515
|
+
this.append('alter table ');
|
|
516
|
+
this.visitNode(node.table);
|
|
517
|
+
this.append(' ');
|
|
518
|
+
if (node.renameTo) {
|
|
519
|
+
this.append('rename to ');
|
|
520
|
+
this.visitNode(node.renameTo);
|
|
521
|
+
}
|
|
522
|
+
if (node.setSchema) {
|
|
523
|
+
this.append('set schema ');
|
|
524
|
+
this.visitNode(node.setSchema);
|
|
525
|
+
}
|
|
526
|
+
if (node.addConstraint) {
|
|
527
|
+
this.visitNode(node.addConstraint);
|
|
528
|
+
}
|
|
529
|
+
if (node.dropConstraint) {
|
|
530
|
+
this.visitNode(node.dropConstraint);
|
|
531
|
+
}
|
|
532
|
+
if (node.renameColumn) {
|
|
533
|
+
this.visitNode(node.renameColumn);
|
|
534
|
+
}
|
|
535
|
+
if (node.addColumn) {
|
|
536
|
+
this.visitNode(node.addColumn);
|
|
537
|
+
}
|
|
538
|
+
if (node.dropColumn) {
|
|
539
|
+
this.visitNode(node.dropColumn);
|
|
540
|
+
}
|
|
541
|
+
if (node.alterColumn) {
|
|
542
|
+
this.visitNode(node.alterColumn);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
visitAddColumn(node) {
|
|
546
|
+
this.append('add column ');
|
|
547
|
+
this.visitNode(node.column);
|
|
548
|
+
}
|
|
549
|
+
visitRenameColumn(node) {
|
|
550
|
+
this.append('rename column ');
|
|
551
|
+
this.visitNode(node.column);
|
|
552
|
+
this.append(' to ');
|
|
553
|
+
this.visitNode(node.renameTo);
|
|
554
|
+
}
|
|
555
|
+
visitDropColumn(node) {
|
|
556
|
+
this.append('drop column ');
|
|
557
|
+
this.visitNode(node.column);
|
|
558
|
+
}
|
|
559
|
+
visitAlterColumn(node) {
|
|
560
|
+
this.append('alter column ');
|
|
561
|
+
this.visitNode(node.column);
|
|
562
|
+
this.append(' ');
|
|
563
|
+
if (node.dataType) {
|
|
564
|
+
this.append('type ');
|
|
565
|
+
this.visitNode(node.dataType);
|
|
566
|
+
if (node.dataTypeExpression) {
|
|
567
|
+
this.append('using ');
|
|
568
|
+
this.visitNode(node.dataTypeExpression);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (node.setDefault) {
|
|
572
|
+
this.append('set default ');
|
|
573
|
+
this.visitNode(node.setDefault);
|
|
574
|
+
}
|
|
575
|
+
if (node.dropDefault) {
|
|
576
|
+
this.append('drop default');
|
|
577
|
+
}
|
|
578
|
+
if (node.setNotNull) {
|
|
579
|
+
this.append('set not null');
|
|
580
|
+
}
|
|
581
|
+
if (node.dropNotNull) {
|
|
582
|
+
this.append('drop not null');
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
visitAddConstraint(node) {
|
|
586
|
+
this.append('add ');
|
|
587
|
+
this.visitNode(node.constraint);
|
|
588
|
+
}
|
|
589
|
+
visitDropConstraint(node) {
|
|
590
|
+
this.append('drop constraint ');
|
|
591
|
+
this.visitNode(node.constraintName);
|
|
592
|
+
}
|
|
493
593
|
appendLeftIdentifierWrapper() {
|
|
494
594
|
this.append('"');
|
|
495
595
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AlterTableNode } from '../operation-node/alter-table-node';
|
|
1
2
|
import { CreateIndexNode } from '../operation-node/create-index-node';
|
|
2
3
|
import { CreateSchemaNode } from '../operation-node/create-schema-node';
|
|
3
4
|
import { CreateTableNode } from '../operation-node/create-table-node';
|
|
@@ -7,7 +8,7 @@ import { DropTableNode } from '../operation-node/drop-table-node';
|
|
|
7
8
|
import { QueryNode } from '../operation-node/query-node';
|
|
8
9
|
import { RawNode } from '../operation-node/raw-node';
|
|
9
10
|
import { CompiledQuery } from './compiled-query';
|
|
10
|
-
export declare type CompileEntryPointNode = QueryNode | CreateTableNode | CreateIndexNode | DropTableNode | DropIndexNode | CreateSchemaNode | DropSchemaNode | RawNode;
|
|
11
|
+
export declare type CompileEntryPointNode = QueryNode | CreateTableNode | CreateIndexNode | AlterTableNode | DropTableNode | DropIndexNode | CreateSchemaNode | DropSchemaNode | RawNode;
|
|
11
12
|
export interface QueryCompiler {
|
|
12
13
|
compileQuery(node: CompileEntryPointNode): CompiledQuery;
|
|
13
14
|
}
|
package/lib/query-creator.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QueryBuilder } from './query-builder/query-builder';
|
|
2
2
|
import { QueryBuilderWithTable, TableExpression, TableReference } from './parser/table-parser';
|
|
3
3
|
import { InsertResultTypeTag, DeleteResultTypeTag, UpdateResultTypeTag } from './query-builder/type-utils';
|
|
4
|
-
import { QueryExecutor } from './
|
|
4
|
+
import { QueryExecutor } from './query-executor/query-executor';
|
|
5
5
|
import { RawBuilder } from './raw-builder/raw-builder';
|
|
6
6
|
import { CommonTableExpression, QueryCreatorWithCommonTableExpression } from './parser/with-parser';
|
|
7
7
|
import { WithNode } from './operation-node/with-node';
|
|
@@ -238,7 +238,7 @@ export declare class QueryCreator<DB> {
|
|
|
238
238
|
* ```
|
|
239
239
|
*
|
|
240
240
|
* @example
|
|
241
|
-
* `withSchema` is smart enough to not add schema for aliases
|
|
241
|
+
* `withSchema` is smart enough to not add schema for aliases,
|
|
242
242
|
* common table expressions or other places where the schema
|
|
243
243
|
* doesn't belong to:
|
|
244
244
|
*
|
package/lib/query-creator.js
CHANGED
|
@@ -163,7 +163,7 @@ class QueryCreator {
|
|
|
163
163
|
* ```
|
|
164
164
|
*
|
|
165
165
|
* @example
|
|
166
|
-
* `withSchema` is smart enough to not add schema for aliases
|
|
166
|
+
* `withSchema` is smart enough to not add schema for aliases,
|
|
167
167
|
* common table expressions or other places where the schema
|
|
168
168
|
* doesn't belong to:
|
|
169
169
|
*
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NeverExecutingQueryExecutor = exports.DefaultQueryExecutor = exports.QueryExecutor = void 0;
|
|
4
|
-
const object_utils_1 = require("
|
|
4
|
+
const object_utils_1 = require("../util/object-utils");
|
|
5
5
|
class QueryExecutor {
|
|
6
6
|
#transformers;
|
|
7
7
|
constructor(transformers = []) {
|
|
@@ -3,10 +3,10 @@ import { AliasNode } from '../operation-node/alias-node';
|
|
|
3
3
|
import { OperationNodeSource } from '../operation-node/operation-node-source';
|
|
4
4
|
import { RawNode } from '../operation-node/raw-node';
|
|
5
5
|
import { CompiledQuery } from '../query-compiler/compiled-query';
|
|
6
|
-
import { QueryExecutor } from '../
|
|
6
|
+
import { QueryExecutor } from '../query-executor/query-executor';
|
|
7
7
|
export declare class RawBuilder<O = unknown> implements OperationNodeSource {
|
|
8
8
|
#private;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(args: RawBuilderConstructorArgs);
|
|
10
10
|
toOperationNode(): RawNode;
|
|
11
11
|
as<A extends string>(alias: A): AliasedRawBuilder<O, A>;
|
|
12
12
|
compile(): CompiledQuery;
|
|
@@ -11,10 +11,10 @@ class RawBuilder {
|
|
|
11
11
|
#sql;
|
|
12
12
|
#params;
|
|
13
13
|
#executor;
|
|
14
|
-
constructor(
|
|
15
|
-
this.#sql = sql;
|
|
16
|
-
this.#params = params;
|
|
17
|
-
this.#executor = executor;
|
|
14
|
+
constructor(args) {
|
|
15
|
+
this.#sql = args.sql;
|
|
16
|
+
this.#params = args.params;
|
|
17
|
+
this.#executor = args.executor;
|
|
18
18
|
}
|
|
19
19
|
toOperationNode() {
|
|
20
20
|
const bindingRegex = /(\?\??)/g;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ColumnDefinitionBuilder, ColumnDefinitionBuilderInterface } from '..';
|
|
2
|
+
import { AlterColumnNode } from '../operation-node/alter-column-node';
|
|
3
|
+
import { AlterTableNode } from '../operation-node/alter-table-node';
|
|
4
|
+
import { ColumnDataType } from '../operation-node/data-type-node';
|
|
5
|
+
import { OperationNodeSource } from '../operation-node/operation-node-source';
|
|
6
|
+
import { OnDelete } from '../operation-node/references-node';
|
|
7
|
+
import { CompiledQuery } from '../query-compiler/compiled-query';
|
|
8
|
+
import { RawBuilder } from '../raw-builder/raw-builder';
|
|
9
|
+
import { Compilable } from '../util/compilable';
|
|
10
|
+
import { PrimitiveValue } from '../util/object-utils';
|
|
11
|
+
import { QueryExecutor } from '../query-executor/query-executor';
|
|
12
|
+
export declare class AlterTableBuilder {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(args: AlterTableBuilderConstructorArgs);
|
|
15
|
+
renameTo(newTableName: string): AlterTableExecutor;
|
|
16
|
+
setSchema(newSchema: string): AlterTableExecutor;
|
|
17
|
+
alterColumn(column: string): AlterColumnBuilder;
|
|
18
|
+
dropColumn(column: string): AlterTableExecutor;
|
|
19
|
+
renameColumn(column: string, newColumn: string): AlterTableExecutor;
|
|
20
|
+
addColumn(columnName: string, dataType: ColumnDataType | RawBuilder): AlterTableAddColumnBuilder;
|
|
21
|
+
}
|
|
22
|
+
export declare class AlterColumnBuilder {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(args: AlterColumnBuilderConstructorArgs);
|
|
25
|
+
setDataType(dataType: ColumnDataType): AlterTableExecutor;
|
|
26
|
+
setDefault(value: PrimitiveValue | RawBuilder<any>): AlterTableExecutor;
|
|
27
|
+
dropDefault(): AlterTableExecutor;
|
|
28
|
+
setNotNull(): AlterTableExecutor;
|
|
29
|
+
dropNotNull(): AlterTableExecutor;
|
|
30
|
+
}
|
|
31
|
+
export declare class AlterTableExecutor implements OperationNodeSource, Compilable {
|
|
32
|
+
#private;
|
|
33
|
+
constructor(args: AlterTableExecutorConstructorArgs);
|
|
34
|
+
toOperationNode(): AlterTableNode;
|
|
35
|
+
compile(): CompiledQuery;
|
|
36
|
+
execute(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuilderInterface<AlterTableAddColumnBuilder> {
|
|
39
|
+
#private;
|
|
40
|
+
constructor(args: AlterTableAddColumnBuilderConstructorArgs);
|
|
41
|
+
increments(): AlterTableAddColumnBuilder;
|
|
42
|
+
primaryKey(): AlterTableAddColumnBuilder;
|
|
43
|
+
references(ref: string): AlterTableAddColumnBuilder;
|
|
44
|
+
onDelete(onDelete: OnDelete): AlterTableAddColumnBuilder;
|
|
45
|
+
unique(): AlterTableAddColumnBuilder;
|
|
46
|
+
notNull(): AlterTableAddColumnBuilder;
|
|
47
|
+
defaultTo(value: PrimitiveValue | RawBuilder<any>): AlterTableAddColumnBuilder;
|
|
48
|
+
check(sql: string): AlterTableAddColumnBuilder;
|
|
49
|
+
toOperationNode(): AlterTableNode;
|
|
50
|
+
compile(): CompiledQuery;
|
|
51
|
+
execute(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export interface AlterTableBuilderConstructorArgs {
|
|
54
|
+
alterTableNode: AlterTableNode;
|
|
55
|
+
executor: QueryExecutor;
|
|
56
|
+
}
|
|
57
|
+
export interface AlterColumnBuilderConstructorArgs extends AlterTableBuilderConstructorArgs {
|
|
58
|
+
alterColumnNode: AlterColumnNode;
|
|
59
|
+
}
|
|
60
|
+
export interface AlterTableExecutorConstructorArgs extends AlterTableBuilderConstructorArgs {
|
|
61
|
+
}
|
|
62
|
+
export interface AlterTableAddColumnBuilderConstructorArgs extends AlterTableBuilderConstructorArgs {
|
|
63
|
+
columnBuilder: ColumnDefinitionBuilder;
|
|
64
|
+
}
|