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
|
@@ -6,9 +6,9 @@ const prevent_await_1 = require("../util/prevent-await");
|
|
|
6
6
|
class DropIndexBuilder {
|
|
7
7
|
#dropIndexNode;
|
|
8
8
|
#executor;
|
|
9
|
-
constructor(
|
|
10
|
-
this.#dropIndexNode = dropIndexNode;
|
|
11
|
-
this.#executor = executor;
|
|
9
|
+
constructor(args) {
|
|
10
|
+
this.#dropIndexNode = args.dropIndexNode;
|
|
11
|
+
this.#executor = args.executor;
|
|
12
12
|
}
|
|
13
13
|
ifExists() {
|
|
14
14
|
return new DropIndexBuilder({
|
|
@@ -2,10 +2,10 @@ import { DropSchemaNode } from '../operation-node/drop-schema-node';
|
|
|
2
2
|
import { OperationNodeSource } from '../operation-node/operation-node-source';
|
|
3
3
|
import { CompiledQuery } from '../query-compiler/compiled-query';
|
|
4
4
|
import { Compilable } from '../util/compilable';
|
|
5
|
-
import { QueryExecutor } from '../
|
|
5
|
+
import { QueryExecutor } from '../query-executor/query-executor';
|
|
6
6
|
export declare class DropSchemaBuilder implements OperationNodeSource, Compilable {
|
|
7
7
|
#private;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(args: DropSchemaBuilderConstructorArgs);
|
|
9
9
|
ifExists(): DropSchemaBuilder;
|
|
10
10
|
toOperationNode(): DropSchemaNode;
|
|
11
11
|
compile(): CompiledQuery;
|
|
@@ -6,9 +6,9 @@ const prevent_await_1 = require("../util/prevent-await");
|
|
|
6
6
|
class DropSchemaBuilder {
|
|
7
7
|
#dropSchemaNode;
|
|
8
8
|
#executor;
|
|
9
|
-
constructor(
|
|
10
|
-
this.#dropSchemaNode = dropSchemaNode;
|
|
11
|
-
this.#executor = executor;
|
|
9
|
+
constructor(args) {
|
|
10
|
+
this.#dropSchemaNode = args.dropSchemaNode;
|
|
11
|
+
this.#executor = args.executor;
|
|
12
12
|
}
|
|
13
13
|
ifExists() {
|
|
14
14
|
return new DropSchemaBuilder({
|
|
@@ -2,10 +2,10 @@ import { DropTableNode } from '../operation-node/drop-table-node';
|
|
|
2
2
|
import { OperationNodeSource } from '../operation-node/operation-node-source';
|
|
3
3
|
import { CompiledQuery } from '../query-compiler/compiled-query';
|
|
4
4
|
import { Compilable } from '../util/compilable';
|
|
5
|
-
import { QueryExecutor } from '../
|
|
5
|
+
import { QueryExecutor } from '../query-executor/query-executor';
|
|
6
6
|
export declare class DropTableBuilder implements OperationNodeSource, Compilable {
|
|
7
7
|
#private;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(args: DropTableBuilderConstructorArgs);
|
|
9
9
|
ifExists(): DropTableBuilder;
|
|
10
10
|
toOperationNode(): DropTableNode;
|
|
11
11
|
compile(): CompiledQuery;
|
|
@@ -6,9 +6,9 @@ const prevent_await_1 = require("../util/prevent-await");
|
|
|
6
6
|
class DropTableBuilder {
|
|
7
7
|
#dropTableNode;
|
|
8
8
|
#executor;
|
|
9
|
-
constructor(
|
|
10
|
-
this.#dropTableNode = dropTableNode;
|
|
11
|
-
this.#executor = executor;
|
|
9
|
+
constructor(args) {
|
|
10
|
+
this.#dropTableNode = args.dropTableNode;
|
|
11
|
+
this.#executor = args.executor;
|
|
12
12
|
}
|
|
13
13
|
ifExists() {
|
|
14
14
|
return new DropTableBuilder({
|
package/lib/schema/schema.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { QueryExecutor } from '../
|
|
1
|
+
import { QueryExecutor } from '../query-executor/query-executor';
|
|
2
|
+
import { AlterTableBuilder } from './alter-table-builder';
|
|
2
3
|
import { CreateIndexBuilder } from './create-index-builder';
|
|
3
4
|
import { CreateSchemaBuilder } from './create-schema-builder';
|
|
4
5
|
import { CreateTableBuilder } from './create-table-builder';
|
|
@@ -21,10 +22,10 @@ export declare class SchemaModule {
|
|
|
21
22
|
* ```ts
|
|
22
23
|
* await db.schema
|
|
23
24
|
* .createTable('person')
|
|
24
|
-
* .addColumn('
|
|
25
|
-
* .addColumn('
|
|
26
|
-
* .addColumn('
|
|
27
|
-
* .addColumn('
|
|
25
|
+
* .addColumn('id', 'int', col => col.primaryKey().increments())
|
|
26
|
+
* .addColumn('first_name', 'varchar', col => col.notNull())
|
|
27
|
+
* .addColumn('last_name', 'varchar', col => col.notNull())
|
|
28
|
+
* .addColumn('gender', 'varchar')
|
|
28
29
|
* .execute()
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
@@ -86,6 +87,19 @@ export declare class SchemaModule {
|
|
|
86
87
|
* ```
|
|
87
88
|
*/
|
|
88
89
|
dropSchema(schema: string): DropSchemaBuilder;
|
|
90
|
+
/**
|
|
91
|
+
* Alter a table.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* await db.schema
|
|
96
|
+
* .alterTable('person')
|
|
97
|
+
* .alterColumn('first_name')
|
|
98
|
+
* .setDataType('text')
|
|
99
|
+
* .execute()
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
alterTable(table: string): AlterTableBuilder;
|
|
89
103
|
/**
|
|
90
104
|
* See {@link QueryCreator.withSchema}
|
|
91
105
|
*/
|
package/lib/schema/schema.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SchemaModule = void 0;
|
|
4
|
+
const alter_table_node_1 = require("../operation-node/alter-table-node");
|
|
4
5
|
const create_index_node_1 = require("../operation-node/create-index-node");
|
|
5
6
|
const create_schema_node_1 = require("../operation-node/create-schema-node");
|
|
6
7
|
const create_table_node_1 = require("../operation-node/create-table-node");
|
|
@@ -9,6 +10,7 @@ const drop_schema_node_1 = require("../operation-node/drop-schema-node");
|
|
|
9
10
|
const drop_table_node_1 = require("../operation-node/drop-table-node");
|
|
10
11
|
const table_parser_1 = require("../parser/table-parser");
|
|
11
12
|
const with_schema_transformer_1 = require("../transformers/with-schema-transformer");
|
|
13
|
+
const alter_table_builder_1 = require("./alter-table-builder");
|
|
12
14
|
const create_index_builder_1 = require("./create-index-builder");
|
|
13
15
|
const create_schema_builder_1 = require("./create-schema-builder");
|
|
14
16
|
const create_table_builder_1 = require("./create-table-builder");
|
|
@@ -33,10 +35,10 @@ class SchemaModule {
|
|
|
33
35
|
* ```ts
|
|
34
36
|
* await db.schema
|
|
35
37
|
* .createTable('person')
|
|
36
|
-
* .addColumn('
|
|
37
|
-
* .addColumn('
|
|
38
|
-
* .addColumn('
|
|
39
|
-
* .addColumn('
|
|
38
|
+
* .addColumn('id', 'int', col => col.primaryKey().increments())
|
|
39
|
+
* .addColumn('first_name', 'varchar', col => col.notNull())
|
|
40
|
+
* .addColumn('last_name', 'varchar', col => col.notNull())
|
|
41
|
+
* .addColumn('gender', 'varchar')
|
|
40
42
|
* .execute()
|
|
41
43
|
* ```
|
|
42
44
|
*/
|
|
@@ -128,6 +130,24 @@ class SchemaModule {
|
|
|
128
130
|
dropSchemaNode: drop_schema_node_1.dropSchemaNode.create(schema),
|
|
129
131
|
});
|
|
130
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Alter a table.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* await db.schema
|
|
139
|
+
* .alterTable('person')
|
|
140
|
+
* .alterColumn('first_name')
|
|
141
|
+
* .setDataType('text')
|
|
142
|
+
* .execute()
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
alterTable(table) {
|
|
146
|
+
return new alter_table_builder_1.AlterTableBuilder({
|
|
147
|
+
executor: this.#executor,
|
|
148
|
+
alterTableNode: alter_table_node_1.alterTableNode.create(table),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
131
151
|
/**
|
|
132
152
|
* See {@link QueryCreator.withSchema}
|
|
133
153
|
*/
|
|
@@ -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 { CreateTableNode } from '../operation-node/create-table-node';
|
|
3
4
|
import { DeleteQueryNode } from '../operation-node/delete-query-node';
|
|
@@ -19,6 +20,7 @@ export declare class WithSchemaTransformer extends OperationNodeTransformer {
|
|
|
19
20
|
protected transformDropTable(node: DropTableNode): DropTableNode;
|
|
20
21
|
protected transformCreateIndex(node: CreateIndexNode): CreateIndexNode;
|
|
21
22
|
protected transformDropIndex(node: DropIndexNode): DropIndexNode;
|
|
23
|
+
protected transformAlterTable(node: AlterTableNode): AlterTableNode;
|
|
22
24
|
protected transformTable(node: TableNode): TableNode;
|
|
23
25
|
private transformEntryPoint;
|
|
24
26
|
private collectTables;
|
|
@@ -35,6 +35,9 @@ class WithSchemaTransformer extends operation_node_transformer_1.OperationNodeTr
|
|
|
35
35
|
transformDropIndex(node) {
|
|
36
36
|
return this.transformEntryPoint(node, (node) => super.transformDropIndex(node));
|
|
37
37
|
}
|
|
38
|
+
transformAlterTable(node) {
|
|
39
|
+
return this.transformEntryPoint(node, (node) => super.transformAlterTable(node));
|
|
40
|
+
}
|
|
38
41
|
transformTable(node) {
|
|
39
42
|
const transformed = super.transformTable(node);
|
|
40
43
|
if (transformed.schema || !this.#tables.has(node.table.identifier)) {
|
|
@@ -14,3 +14,4 @@ export declare function isObject(obj: any): obj is Record<string, any>;
|
|
|
14
14
|
export declare function getLast<T>(arr: ArrayLike<T>): T | undefined;
|
|
15
15
|
export declare function freeze<T>(obj: T): Readonly<T>;
|
|
16
16
|
export declare function asArray<T>(arg: T | T[]): T[];
|
|
17
|
+
export declare function asReadonlyArray<T>(arg: T | ReadonlyArray<T>): ReadonlyArray<T>;
|
package/lib/util/object-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.asArray = exports.freeze = exports.getLast = exports.isObject = exports.isFunction = exports.isPrimitive = exports.isBigInt = exports.isBuffer = exports.isDate = exports.isNull = exports.isBoolean = exports.isNumber = exports.isString = exports.isEmpty = void 0;
|
|
3
|
+
exports.asReadonlyArray = exports.asArray = exports.freeze = exports.getLast = exports.isObject = exports.isFunction = exports.isPrimitive = exports.isBigInt = exports.isBuffer = exports.isDate = exports.isNull = exports.isBoolean = exports.isNumber = exports.isString = exports.isEmpty = void 0;
|
|
4
4
|
function isEmpty(obj) {
|
|
5
5
|
if (Array.isArray(obj) || isString(obj) || Buffer.isBuffer(obj)) {
|
|
6
6
|
return obj.length === 0;
|
|
@@ -74,3 +74,15 @@ function asArray(arg) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
exports.asArray = asArray;
|
|
77
|
+
function asReadonlyArray(arg) {
|
|
78
|
+
if (isReadonlyArray(arg)) {
|
|
79
|
+
return arg;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return freeze([arg]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.asReadonlyArray = asReadonlyArray;
|
|
86
|
+
function isReadonlyArray(arg) {
|
|
87
|
+
return Array.isArray(arg);
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kysely",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Type safe SQL query builder",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"test:typings": "npm run build && tsd test/typings",
|
|
11
11
|
"prettier": "prettier --write src/**/*.ts test/**/*.ts",
|
|
12
12
|
"build": "rm -rf lib && tsc",
|
|
13
|
-
"docs:build": "typedoc
|
|
13
|
+
"docs:build": "typedoc --excludePrivate --excludeInternal src/index.ts && npm run docs:postprocess",
|
|
14
14
|
"docs:postprocess": "node post-process-docs.js",
|
|
15
15
|
"prepublish": "npm run build"
|
|
16
16
|
},
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ColumnNode } from './column-node';
|
|
2
|
-
import { OperationNode } from './operation-node';
|
|
3
|
-
export interface TablePrimaryConstraintNode extends OperationNode {
|
|
4
|
-
readonly kind: 'TablePrimaryConstraintNode';
|
|
5
|
-
readonly columns: ReadonlyArray<ColumnNode>;
|
|
6
|
-
}
|
|
7
|
-
export declare const tablePrimaryConstraintNode: Readonly<{
|
|
8
|
-
is(node: OperationNode): node is TablePrimaryConstraintNode;
|
|
9
|
-
create(columns: string[]): TablePrimaryConstraintNode;
|
|
10
|
-
}>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tablePrimaryConstraintNode = void 0;
|
|
4
|
-
const object_utils_1 = require("../util/object-utils");
|
|
5
|
-
const column_node_1 = require("./column-node");
|
|
6
|
-
exports.tablePrimaryConstraintNode = object_utils_1.freeze({
|
|
7
|
-
is(node) {
|
|
8
|
-
return node.kind === 'TablePrimaryConstraintNode';
|
|
9
|
-
},
|
|
10
|
-
create(columns) {
|
|
11
|
-
return {
|
|
12
|
-
kind: 'TablePrimaryConstraintNode',
|
|
13
|
-
columns: columns.map(column_node_1.columnNode.create),
|
|
14
|
-
};
|
|
15
|
-
},
|
|
16
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ColumnNode } from './column-node';
|
|
2
|
-
import { OperationNode } from './operation-node';
|
|
3
|
-
export interface TableUniqueConstraintNode extends OperationNode {
|
|
4
|
-
readonly kind: 'TableUniqueConstraintNode';
|
|
5
|
-
readonly columns: ReadonlyArray<ColumnNode>;
|
|
6
|
-
}
|
|
7
|
-
export declare const tableUniqueConstraintNode: Readonly<{
|
|
8
|
-
is(node: OperationNode): node is TableUniqueConstraintNode;
|
|
9
|
-
create(columns: string[]): TableUniqueConstraintNode;
|
|
10
|
-
}>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tableUniqueConstraintNode = void 0;
|
|
4
|
-
const object_utils_1 = require("../util/object-utils");
|
|
5
|
-
const column_node_1 = require("./column-node");
|
|
6
|
-
exports.tableUniqueConstraintNode = object_utils_1.freeze({
|
|
7
|
-
is(node) {
|
|
8
|
-
return node.kind === 'TableUniqueConstraintNode';
|
|
9
|
-
},
|
|
10
|
-
create(columns) {
|
|
11
|
-
return {
|
|
12
|
-
kind: 'TableUniqueConstraintNode',
|
|
13
|
-
columns: columns.map(column_node_1.columnNode.create),
|
|
14
|
-
};
|
|
15
|
-
},
|
|
16
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AddColumnBuilder = void 0;
|
|
4
|
-
const check_constraint_node_1 = require("../operation-node/check-constraint-node");
|
|
5
|
-
const add_column_node_1 = require("../operation-node/add-column-node");
|
|
6
|
-
const operation_node_source_1 = require("../operation-node/operation-node-source");
|
|
7
|
-
const reference_node_1 = require("../operation-node/reference-node");
|
|
8
|
-
const references_node_1 = require("../operation-node/references-node");
|
|
9
|
-
const select_all_node_1 = require("../operation-node/select-all-node");
|
|
10
|
-
const value_node_1 = require("../operation-node/value-node");
|
|
11
|
-
const reference_parser_1 = require("../parser/reference-parser");
|
|
12
|
-
const prevent_await_1 = require("../util/prevent-await");
|
|
13
|
-
class AddColumnBuilder {
|
|
14
|
-
#node;
|
|
15
|
-
constructor(node) {
|
|
16
|
-
this.#node = node;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Makes the column automatically incrementing.
|
|
20
|
-
*
|
|
21
|
-
* On some dialects this may change the column type as well. For example
|
|
22
|
-
* on postgres this sets the column type to `serial` no matter what you
|
|
23
|
-
* have specified before.
|
|
24
|
-
*/
|
|
25
|
-
increments() {
|
|
26
|
-
return new AddColumnBuilder(add_column_node_1.addColumnNode.cloneWith(this.#node, { isAutoIncrementing: true }));
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Makes the column the primary key.
|
|
30
|
-
*
|
|
31
|
-
* If you want to specify a composite primary key use the
|
|
32
|
-
* {@link TableBuilder.addPrimaryKeyConstraint} method.
|
|
33
|
-
*/
|
|
34
|
-
primaryKey() {
|
|
35
|
-
return new AddColumnBuilder(add_column_node_1.addColumnNode.cloneWith(this.#node, { isPrimaryKey: true }));
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Adds a foreign key constraint for the column.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* col.references('person.id')
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
references(ref) {
|
|
46
|
-
const references = reference_parser_1.parseStringReference(ref);
|
|
47
|
-
if (!reference_node_1.referenceNode.is(references) || select_all_node_1.selectAllNode.is(references.column)) {
|
|
48
|
-
throw new Error(`invalid call references('${ref}'). The reference must have format table.column or schema.table.column`);
|
|
49
|
-
}
|
|
50
|
-
return new AddColumnBuilder(add_column_node_1.addColumnNode.cloneWith(this.#node, {
|
|
51
|
-
references: references_node_1.referencesNode.create(references.table, references.column),
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Adds an `on delete` constraint for the foreign key column.
|
|
56
|
-
*/
|
|
57
|
-
onDelete(onDelete) {
|
|
58
|
-
if (!this.#node.references) {
|
|
59
|
-
throw new Error('on delete constraint can only be added for foreign keys');
|
|
60
|
-
}
|
|
61
|
-
return new AddColumnBuilder(add_column_node_1.addColumnNode.cloneWith(this.#node, {
|
|
62
|
-
references: references_node_1.referencesNode.cloneWithOnDelete(this.#node.references, onDelete),
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Adds a unique constraint for the column.
|
|
67
|
-
*/
|
|
68
|
-
unique() {
|
|
69
|
-
return new AddColumnBuilder(add_column_node_1.addColumnNode.cloneWith(this.#node, { isUnique: true }));
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Adds a `not null` constraint for the column.
|
|
73
|
-
*/
|
|
74
|
-
notNullable() {
|
|
75
|
-
return new AddColumnBuilder(add_column_node_1.addColumnNode.cloneWith(this.#node, { isNullable: false }));
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Adds a default value constraint for the column.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* db.schema
|
|
83
|
-
* .createTable('pet')
|
|
84
|
-
* .addColumn('integer', 'number_of_legs', (col) => col.defaultTo(4))
|
|
85
|
-
* .execute()
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
defaultTo(value) {
|
|
89
|
-
return new AddColumnBuilder(add_column_node_1.addColumnNode.cloneWith(this.#node, {
|
|
90
|
-
defaultTo: operation_node_source_1.isOperationNodeSource(value)
|
|
91
|
-
? value.toOperationNode()
|
|
92
|
-
: value_node_1.valueNode.createImmediate(value),
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Adds a check constraint for the column.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```ts
|
|
100
|
-
* db.schema
|
|
101
|
-
* .createTable('pet')
|
|
102
|
-
* .addColumn('integer', 'number_of_legs', (col) => col.check('number_of_legs < 5'))
|
|
103
|
-
* .execute()
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
check(sql) {
|
|
107
|
-
return new AddColumnBuilder(add_column_node_1.addColumnNode.cloneWith(this.#node, {
|
|
108
|
-
check: check_constraint_node_1.checkConstraintNode.create(sql),
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
toOperationNode() {
|
|
112
|
-
return this.#node;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.AddColumnBuilder = AddColumnBuilder;
|
|
116
|
-
prevent_await_1.preventAwait(AddColumnBuilder, "don't await ColumnBuilder instances directly.");
|