kysely 0.19.2 → 0.19.3
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 +2 -2
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +0 -5
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +0 -5
- package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +0 -5
- package/dist/cjs/driver/driver.d.ts +0 -5
- package/dist/cjs/driver/dummy-driver.d.ts +0 -5
- package/dist/cjs/driver/runtime-driver.d.ts +0 -5
- package/dist/cjs/migration/file-migration-provider.js +3 -2
- package/dist/cjs/operation-node/drop-constraint-node.d.ts +4 -0
- package/dist/cjs/operation-node/drop-constraint-node.js +6 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +2 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/query-compiler/default-query-compiler.js +9 -0
- package/dist/cjs/schema/alter-table-builder.d.ts +13 -0
- package/dist/cjs/schema/alter-table-builder.js +57 -1
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +0 -5
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +0 -5
- package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +0 -5
- package/dist/esm/driver/driver.d.ts +0 -5
- package/dist/esm/driver/dummy-driver.d.ts +0 -5
- package/dist/esm/driver/runtime-driver.d.ts +0 -5
- package/dist/esm/migration/file-migration-provider.js +3 -2
- package/dist/esm/operation-node/drop-constraint-node.d.ts +4 -0
- package/dist/esm/operation-node/drop-constraint-node.js +6 -0
- package/dist/esm/operation-node/operation-node-transformer.js +2 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/query-compiler/default-query-compiler.js +9 -0
- package/dist/esm/schema/alter-table-builder.d.ts +13 -0
- package/dist/esm/schema/alter-table-builder.js +55 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -95,7 +95,7 @@ interface PersonTable {
|
|
|
95
95
|
// automatically by Kysely.
|
|
96
96
|
last_name: string | null
|
|
97
97
|
|
|
98
|
-
// You can
|
|
98
|
+
// You can specify a different type for each operation (select, insert and
|
|
99
99
|
// update) using the `ColumnType<SelectType, InsertType, UpdateType>`
|
|
100
100
|
// wrapper. Here we define a column `modified_at` that is selected as
|
|
101
101
|
// a `Date`, can optionally be provided as a `string` in inserts and
|
|
@@ -324,7 +324,7 @@ have. You will probably want to add a simple migration script to your projects l
|
|
|
324
324
|
```ts
|
|
325
325
|
import * as path from 'path'
|
|
326
326
|
import { Pool } from 'pg'
|
|
327
|
-
import { promises
|
|
327
|
+
import { promises as fs } from 'fs'
|
|
328
328
|
import {
|
|
329
329
|
Kysely,
|
|
330
330
|
Migrator,
|
|
@@ -11,11 +11,6 @@ export declare class MysqlDriver implements Driver {
|
|
|
11
11
|
*
|
|
12
12
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
13
13
|
* methods should be callable.
|
|
14
|
-
*
|
|
15
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
16
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
17
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
18
|
-
* it supports.
|
|
19
14
|
*/
|
|
20
15
|
init(): Promise<void>;
|
|
21
16
|
/**
|
|
@@ -11,11 +11,6 @@ export declare class PostgresDriver implements Driver {
|
|
|
11
11
|
*
|
|
12
12
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
13
13
|
* methods should be callable.
|
|
14
|
-
*
|
|
15
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
16
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
17
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
18
|
-
* it supports.
|
|
19
14
|
*/
|
|
20
15
|
init(): Promise<void>;
|
|
21
16
|
/**
|
|
@@ -9,11 +9,6 @@ export declare class SqliteDriver implements Driver {
|
|
|
9
9
|
*
|
|
10
10
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
11
11
|
* methods should be callable.
|
|
12
|
-
*
|
|
13
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
14
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
15
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
16
|
-
* it supports.
|
|
17
12
|
*/
|
|
18
13
|
init(): Promise<void>;
|
|
19
14
|
/**
|
|
@@ -10,11 +10,6 @@ export interface Driver {
|
|
|
10
10
|
*
|
|
11
11
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
12
12
|
* methods should be callable.
|
|
13
|
-
*
|
|
14
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
15
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
16
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
17
|
-
* it supports.
|
|
18
13
|
*/
|
|
19
14
|
init(): Promise<void>;
|
|
20
15
|
/**
|
|
@@ -42,11 +42,6 @@ export declare class DummyDriver implements Driver {
|
|
|
42
42
|
*
|
|
43
43
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
44
44
|
* methods should be callable.
|
|
45
|
-
*
|
|
46
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
47
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
48
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
49
|
-
* it supports.
|
|
50
45
|
*/
|
|
51
46
|
init(): Promise<void>;
|
|
52
47
|
/**
|
|
@@ -14,11 +14,6 @@ export declare class RuntimeDriver implements Driver {
|
|
|
14
14
|
*
|
|
15
15
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
16
16
|
* methods should be callable.
|
|
17
|
-
*
|
|
18
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
19
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
20
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
21
|
-
* it supports.
|
|
22
17
|
*/
|
|
23
18
|
init(): Promise<void>;
|
|
24
19
|
/**
|
|
@@ -27,9 +27,10 @@ class FileMigrationProvider {
|
|
|
27
27
|
const migrations = {};
|
|
28
28
|
const files = await this.#props.fs.readdir(this.#props.migrationFolder);
|
|
29
29
|
for (const fileName of files) {
|
|
30
|
-
if ((fileName.endsWith('.js') || fileName.endsWith('.ts')) &&
|
|
30
|
+
if ((fileName.endsWith('.js') || fileName.endsWith('.ts') || fileName.endsWith('.mjs')) &&
|
|
31
31
|
!fileName.endsWith('.d.ts')) {
|
|
32
|
-
const migration = await Promise.resolve().then(() => require(
|
|
32
|
+
const migration = await Promise.resolve().then(() => require(
|
|
33
|
+
/* webpackIgnore: true */ this.#props.path.join(this.#props.migrationFolder, fileName)));
|
|
33
34
|
if (isMigration(migration)) {
|
|
34
35
|
migrations[fileName.substring(0, fileName.length - 3)] = migration;
|
|
35
36
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
2
|
import { IdentifierNode } from './identifier-node.js';
|
|
3
|
+
export declare type DropConstraintNodeProps = Omit<DropConstraintNode, 'kind' | 'constraintName'>;
|
|
3
4
|
export interface DropConstraintNode extends OperationNode {
|
|
4
5
|
readonly kind: 'DropConstraintNode';
|
|
5
6
|
readonly constraintName: IdentifierNode;
|
|
7
|
+
readonly ifExists?: boolean;
|
|
8
|
+
readonly modifier?: 'cascade' | 'restrict';
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* @internal
|
|
@@ -10,4 +13,5 @@ export interface DropConstraintNode extends OperationNode {
|
|
|
10
13
|
export declare const DropConstraintNode: Readonly<{
|
|
11
14
|
is(node: OperationNode): node is DropConstraintNode;
|
|
12
15
|
create(constraintName: string): DropConstraintNode;
|
|
16
|
+
cloneWith(dropConstraint: DropConstraintNode, props: DropConstraintNodeProps): DropConstraintNode;
|
|
13
17
|
}>;
|
|
@@ -16,4 +16,10 @@ exports.DropConstraintNode = (0, object_utils_js_1.freeze)({
|
|
|
16
16
|
constraintName: identifier_node_js_1.IdentifierNode.create(constraintName),
|
|
17
17
|
});
|
|
18
18
|
},
|
|
19
|
+
cloneWith(dropConstraint, props) {
|
|
20
|
+
return (0, object_utils_js_1.freeze)({
|
|
21
|
+
...dropConstraint,
|
|
22
|
+
...props,
|
|
23
|
+
});
|
|
24
|
+
},
|
|
19
25
|
});
|
package/dist/cjs/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
|
1
|
+
{"type":"commonjs","sideEffects":false}
|
|
@@ -704,7 +704,16 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
704
704
|
}
|
|
705
705
|
visitDropConstraint(node) {
|
|
706
706
|
this.append('drop constraint ');
|
|
707
|
+
if (node.ifExists) {
|
|
708
|
+
this.append('if exists ');
|
|
709
|
+
}
|
|
707
710
|
this.visitNode(node.constraintName);
|
|
711
|
+
if (node.modifier === 'cascade') {
|
|
712
|
+
this.append(' cascade');
|
|
713
|
+
}
|
|
714
|
+
else if (node.modifier === 'restrict') {
|
|
715
|
+
this.append(' restrict');
|
|
716
|
+
}
|
|
708
717
|
}
|
|
709
718
|
visitUnion(node) {
|
|
710
719
|
this.append('union ');
|
|
@@ -49,6 +49,7 @@ export declare class AlterTableBuilder {
|
|
|
49
49
|
* is because you can only add one column per `ALTER TABLE` query.
|
|
50
50
|
*/
|
|
51
51
|
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[]): AlterTableAddForeignKeyConstraintBuilder;
|
|
52
|
+
dropConstraint(constraintName: string): AlterTableDropConstraintBuilder;
|
|
52
53
|
}
|
|
53
54
|
export interface AlterTableBuilderProps {
|
|
54
55
|
readonly queryId: QueryId;
|
|
@@ -419,3 +420,15 @@ export declare class AlterTableAddForeignKeyConstraintBuilder implements Foreign
|
|
|
419
420
|
export interface AlterTableAddForeignKeyConstraintBuilderProps extends AlterTableBuilderProps {
|
|
420
421
|
readonly constraintBuilder: ForeignKeyConstraintBuilder;
|
|
421
422
|
}
|
|
423
|
+
export declare class AlterTableDropConstraintBuilder implements OperationNodeSource, Compilable {
|
|
424
|
+
#private;
|
|
425
|
+
constructor(props: AlterTableDropConstraintBuilderProps);
|
|
426
|
+
ifExists(): AlterTableDropConstraintBuilder;
|
|
427
|
+
cascade(): AlterTableDropConstraintBuilder;
|
|
428
|
+
restrict(): AlterTableDropConstraintBuilder;
|
|
429
|
+
toOperationNode(): AlterTableNode;
|
|
430
|
+
compile(): CompiledQuery;
|
|
431
|
+
execute(): Promise<void>;
|
|
432
|
+
}
|
|
433
|
+
export interface AlterTableDropConstraintBuilderProps extends AlterTableBuilderProps {
|
|
434
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AlterTableAddForeignKeyConstraintBuilder = exports.AlterTableModifyColumnBuilder = exports.AlterTableAddColumnBuilder = exports.AlterTableExecutor = exports.AlterColumnBuilder = exports.AlterTableBuilder = void 0;
|
|
3
|
+
exports.AlterTableDropConstraintBuilder = exports.AlterTableAddForeignKeyConstraintBuilder = exports.AlterTableModifyColumnBuilder = exports.AlterTableAddColumnBuilder = exports.AlterTableExecutor = exports.AlterColumnBuilder = 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,7 @@ const foreign_key_constraint_node_js_1 = require("../operation-node/foreign-key-
|
|
|
22
22
|
const column_node_js_1 = require("../operation-node/column-node.js");
|
|
23
23
|
const default_value_parser_js_1 = require("../parser/default-value-parser.js");
|
|
24
24
|
const table_parser_js_1 = require("../parser/table-parser.js");
|
|
25
|
+
const drop_constraint_node_js_1 = require("../operation-node/drop-constraint-node.js");
|
|
25
26
|
/**
|
|
26
27
|
* This builder can be used to create a `alter table` query.
|
|
27
28
|
*/
|
|
@@ -123,6 +124,14 @@ class AlterTableBuilder {
|
|
|
123
124
|
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)),
|
|
124
125
|
});
|
|
125
126
|
}
|
|
127
|
+
dropConstraint(constraintName) {
|
|
128
|
+
return new AlterTableDropConstraintBuilder({
|
|
129
|
+
...this.#props,
|
|
130
|
+
alterTableNode: alter_table_node_js_1.AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
131
|
+
dropConstraint: drop_constraint_node_js_1.DropConstraintNode.create(constraintName),
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
126
135
|
}
|
|
127
136
|
exports.AlterTableBuilder = AlterTableBuilder;
|
|
128
137
|
class AlterColumnBuilder {
|
|
@@ -432,9 +441,56 @@ class AlterTableAddForeignKeyConstraintBuilder {
|
|
|
432
441
|
}
|
|
433
442
|
}
|
|
434
443
|
exports.AlterTableAddForeignKeyConstraintBuilder = AlterTableAddForeignKeyConstraintBuilder;
|
|
444
|
+
class AlterTableDropConstraintBuilder {
|
|
445
|
+
#props;
|
|
446
|
+
constructor(props) {
|
|
447
|
+
this.#props = (0, object_utils_js_1.freeze)(props);
|
|
448
|
+
}
|
|
449
|
+
ifExists() {
|
|
450
|
+
return new AlterTableDropConstraintBuilder({
|
|
451
|
+
...this.#props,
|
|
452
|
+
alterTableNode: alter_table_node_js_1.AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
453
|
+
dropConstraint: drop_constraint_node_js_1.DropConstraintNode.cloneWith(this.#props.alterTableNode.dropConstraint, {
|
|
454
|
+
ifExists: true,
|
|
455
|
+
}),
|
|
456
|
+
}),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
cascade() {
|
|
460
|
+
return new AlterTableDropConstraintBuilder({
|
|
461
|
+
...this.#props,
|
|
462
|
+
alterTableNode: alter_table_node_js_1.AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
463
|
+
dropConstraint: drop_constraint_node_js_1.DropConstraintNode.cloneWith(this.#props.alterTableNode.dropConstraint, {
|
|
464
|
+
modifier: 'cascade',
|
|
465
|
+
}),
|
|
466
|
+
}),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
restrict() {
|
|
470
|
+
return new AlterTableDropConstraintBuilder({
|
|
471
|
+
...this.#props,
|
|
472
|
+
alterTableNode: alter_table_node_js_1.AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
473
|
+
dropConstraint: drop_constraint_node_js_1.DropConstraintNode.cloneWith(this.#props.alterTableNode.dropConstraint, {
|
|
474
|
+
modifier: 'restrict',
|
|
475
|
+
}),
|
|
476
|
+
}),
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
toOperationNode() {
|
|
480
|
+
return this.#props.executor.transformQuery(this.#props.alterTableNode, this.#props.queryId);
|
|
481
|
+
}
|
|
482
|
+
compile() {
|
|
483
|
+
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
484
|
+
}
|
|
485
|
+
async execute() {
|
|
486
|
+
await this.#props.executor.executeQuery(this.compile(), this.#props.queryId);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
exports.AlterTableDropConstraintBuilder = AlterTableDropConstraintBuilder;
|
|
435
490
|
(0, prevent_await_js_1.preventAwait)(AlterTableBuilder, "don't await AlterTableBuilder instances");
|
|
436
491
|
(0, prevent_await_js_1.preventAwait)(AlterColumnBuilder, "don't await AlterColumnBuilder instances");
|
|
437
492
|
(0, prevent_await_js_1.preventAwait)(AlterTableExecutor, "don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");
|
|
438
493
|
(0, prevent_await_js_1.preventAwait)(AlterTableAddColumnBuilder, "don't await AlterTableAddColumnBuilder instances directly. To execute the query you need to call `execute`");
|
|
439
494
|
(0, prevent_await_js_1.preventAwait)(AlterTableModifyColumnBuilder, "don't await AlterTableModifyColumnBuilder instances directly. To execute the query you need to call `execute`");
|
|
440
495
|
(0, prevent_await_js_1.preventAwait)(AlterTableAddForeignKeyConstraintBuilder, "don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");
|
|
496
|
+
(0, prevent_await_js_1.preventAwait)(AlterTableDropConstraintBuilder, "don't await AlterTableDropConstraintBuilder instances directly. To execute the query you need to call `execute`");
|
|
@@ -11,11 +11,6 @@ export declare class MysqlDriver implements Driver {
|
|
|
11
11
|
*
|
|
12
12
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
13
13
|
* methods should be callable.
|
|
14
|
-
*
|
|
15
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
16
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
17
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
18
|
-
* it supports.
|
|
19
14
|
*/
|
|
20
15
|
init(): Promise<void>;
|
|
21
16
|
/**
|
|
@@ -11,11 +11,6 @@ export declare class PostgresDriver implements Driver {
|
|
|
11
11
|
*
|
|
12
12
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
13
13
|
* methods should be callable.
|
|
14
|
-
*
|
|
15
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
16
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
17
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
18
|
-
* it supports.
|
|
19
14
|
*/
|
|
20
15
|
init(): Promise<void>;
|
|
21
16
|
/**
|
|
@@ -9,11 +9,6 @@ export declare class SqliteDriver implements Driver {
|
|
|
9
9
|
*
|
|
10
10
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
11
11
|
* methods should be callable.
|
|
12
|
-
*
|
|
13
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
14
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
15
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
16
|
-
* it supports.
|
|
17
12
|
*/
|
|
18
13
|
init(): Promise<void>;
|
|
19
14
|
/**
|
|
@@ -10,11 +10,6 @@ export interface Driver {
|
|
|
10
10
|
*
|
|
11
11
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
12
12
|
* methods should be callable.
|
|
13
|
-
*
|
|
14
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
15
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
16
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
17
|
-
* it supports.
|
|
18
13
|
*/
|
|
19
14
|
init(): Promise<void>;
|
|
20
15
|
/**
|
|
@@ -42,11 +42,6 @@ export declare class DummyDriver implements Driver {
|
|
|
42
42
|
*
|
|
43
43
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
44
44
|
* methods should be callable.
|
|
45
|
-
*
|
|
46
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
47
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
48
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
49
|
-
* it supports.
|
|
50
45
|
*/
|
|
51
46
|
init(): Promise<void>;
|
|
52
47
|
/**
|
|
@@ -14,11 +14,6 @@ export declare class RuntimeDriver implements Driver {
|
|
|
14
14
|
*
|
|
15
15
|
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
16
16
|
* methods should be callable.
|
|
17
|
-
*
|
|
18
|
-
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
19
|
-
* should be imported inside this function, not at the top of the driver file! This is
|
|
20
|
-
* important so that Kysely is usable without installing all database driver libraries
|
|
21
|
-
* it supports.
|
|
22
17
|
*/
|
|
23
18
|
init(): Promise<void>;
|
|
24
19
|
/**
|
|
@@ -25,9 +25,10 @@ export class FileMigrationProvider {
|
|
|
25
25
|
const migrations = {};
|
|
26
26
|
const files = await this.#props.fs.readdir(this.#props.migrationFolder);
|
|
27
27
|
for (const fileName of files) {
|
|
28
|
-
if ((fileName.endsWith('.js') || fileName.endsWith('.ts')) &&
|
|
28
|
+
if ((fileName.endsWith('.js') || fileName.endsWith('.ts') || fileName.endsWith('.mjs')) &&
|
|
29
29
|
!fileName.endsWith('.d.ts')) {
|
|
30
|
-
const migration = await import(
|
|
30
|
+
const migration = await import(
|
|
31
|
+
/* webpackIgnore: true */ this.#props.path.join(this.#props.migrationFolder, fileName));
|
|
31
32
|
if (isMigration(migration)) {
|
|
32
33
|
migrations[fileName.substring(0, fileName.length - 3)] = migration;
|
|
33
34
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
2
|
import { IdentifierNode } from './identifier-node.js';
|
|
3
|
+
export declare type DropConstraintNodeProps = Omit<DropConstraintNode, 'kind' | 'constraintName'>;
|
|
3
4
|
export interface DropConstraintNode extends OperationNode {
|
|
4
5
|
readonly kind: 'DropConstraintNode';
|
|
5
6
|
readonly constraintName: IdentifierNode;
|
|
7
|
+
readonly ifExists?: boolean;
|
|
8
|
+
readonly modifier?: 'cascade' | 'restrict';
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* @internal
|
|
@@ -10,4 +13,5 @@ export interface DropConstraintNode extends OperationNode {
|
|
|
10
13
|
export declare const DropConstraintNode: Readonly<{
|
|
11
14
|
is(node: OperationNode): node is DropConstraintNode;
|
|
12
15
|
create(constraintName: string): DropConstraintNode;
|
|
16
|
+
cloneWith(dropConstraint: DropConstraintNode, props: DropConstraintNodeProps): DropConstraintNode;
|
|
13
17
|
}>;
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module"}
|
|
1
|
+
{"type":"module","sideEffects":false}
|
|
@@ -702,7 +702,16 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
702
702
|
}
|
|
703
703
|
visitDropConstraint(node) {
|
|
704
704
|
this.append('drop constraint ');
|
|
705
|
+
if (node.ifExists) {
|
|
706
|
+
this.append('if exists ');
|
|
707
|
+
}
|
|
705
708
|
this.visitNode(node.constraintName);
|
|
709
|
+
if (node.modifier === 'cascade') {
|
|
710
|
+
this.append(' cascade');
|
|
711
|
+
}
|
|
712
|
+
else if (node.modifier === 'restrict') {
|
|
713
|
+
this.append(' restrict');
|
|
714
|
+
}
|
|
706
715
|
}
|
|
707
716
|
visitUnion(node) {
|
|
708
717
|
this.append('union ');
|
|
@@ -49,6 +49,7 @@ export declare class AlterTableBuilder {
|
|
|
49
49
|
* is because you can only add one column per `ALTER TABLE` query.
|
|
50
50
|
*/
|
|
51
51
|
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[]): AlterTableAddForeignKeyConstraintBuilder;
|
|
52
|
+
dropConstraint(constraintName: string): AlterTableDropConstraintBuilder;
|
|
52
53
|
}
|
|
53
54
|
export interface AlterTableBuilderProps {
|
|
54
55
|
readonly queryId: QueryId;
|
|
@@ -419,3 +420,15 @@ export declare class AlterTableAddForeignKeyConstraintBuilder implements Foreign
|
|
|
419
420
|
export interface AlterTableAddForeignKeyConstraintBuilderProps extends AlterTableBuilderProps {
|
|
420
421
|
readonly constraintBuilder: ForeignKeyConstraintBuilder;
|
|
421
422
|
}
|
|
423
|
+
export declare class AlterTableDropConstraintBuilder implements OperationNodeSource, Compilable {
|
|
424
|
+
#private;
|
|
425
|
+
constructor(props: AlterTableDropConstraintBuilderProps);
|
|
426
|
+
ifExists(): AlterTableDropConstraintBuilder;
|
|
427
|
+
cascade(): AlterTableDropConstraintBuilder;
|
|
428
|
+
restrict(): AlterTableDropConstraintBuilder;
|
|
429
|
+
toOperationNode(): AlterTableNode;
|
|
430
|
+
compile(): CompiledQuery;
|
|
431
|
+
execute(): Promise<void>;
|
|
432
|
+
}
|
|
433
|
+
export interface AlterTableDropConstraintBuilderProps extends AlterTableBuilderProps {
|
|
434
|
+
}
|
|
@@ -20,6 +20,7 @@ import { ForeignKeyConstraintNode } from '../operation-node/foreign-key-constrai
|
|
|
20
20
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
21
21
|
import { parseDefaultValueExpression, } from '../parser/default-value-parser.js';
|
|
22
22
|
import { parseTable } from '../parser/table-parser.js';
|
|
23
|
+
import { DropConstraintNode } from '../operation-node/drop-constraint-node.js';
|
|
23
24
|
/**
|
|
24
25
|
* This builder can be used to create a `alter table` query.
|
|
25
26
|
*/
|
|
@@ -121,6 +122,14 @@ export class AlterTableBuilder {
|
|
|
121
122
|
constraintBuilder: new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.create(columns.map(ColumnNode.create), parseTable(targetTable), targetColumns.map(ColumnNode.create), constraintName)),
|
|
122
123
|
});
|
|
123
124
|
}
|
|
125
|
+
dropConstraint(constraintName) {
|
|
126
|
+
return new AlterTableDropConstraintBuilder({
|
|
127
|
+
...this.#props,
|
|
128
|
+
alterTableNode: AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
129
|
+
dropConstraint: DropConstraintNode.create(constraintName),
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
124
133
|
}
|
|
125
134
|
export class AlterColumnBuilder {
|
|
126
135
|
#props;
|
|
@@ -424,9 +433,55 @@ export class AlterTableAddForeignKeyConstraintBuilder {
|
|
|
424
433
|
await this.#props.executor.executeQuery(this.compile(), this.#props.queryId);
|
|
425
434
|
}
|
|
426
435
|
}
|
|
436
|
+
export class AlterTableDropConstraintBuilder {
|
|
437
|
+
#props;
|
|
438
|
+
constructor(props) {
|
|
439
|
+
this.#props = freeze(props);
|
|
440
|
+
}
|
|
441
|
+
ifExists() {
|
|
442
|
+
return new AlterTableDropConstraintBuilder({
|
|
443
|
+
...this.#props,
|
|
444
|
+
alterTableNode: AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
445
|
+
dropConstraint: DropConstraintNode.cloneWith(this.#props.alterTableNode.dropConstraint, {
|
|
446
|
+
ifExists: true,
|
|
447
|
+
}),
|
|
448
|
+
}),
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
cascade() {
|
|
452
|
+
return new AlterTableDropConstraintBuilder({
|
|
453
|
+
...this.#props,
|
|
454
|
+
alterTableNode: AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
455
|
+
dropConstraint: DropConstraintNode.cloneWith(this.#props.alterTableNode.dropConstraint, {
|
|
456
|
+
modifier: 'cascade',
|
|
457
|
+
}),
|
|
458
|
+
}),
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
restrict() {
|
|
462
|
+
return new AlterTableDropConstraintBuilder({
|
|
463
|
+
...this.#props,
|
|
464
|
+
alterTableNode: AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
465
|
+
dropConstraint: DropConstraintNode.cloneWith(this.#props.alterTableNode.dropConstraint, {
|
|
466
|
+
modifier: 'restrict',
|
|
467
|
+
}),
|
|
468
|
+
}),
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
toOperationNode() {
|
|
472
|
+
return this.#props.executor.transformQuery(this.#props.alterTableNode, this.#props.queryId);
|
|
473
|
+
}
|
|
474
|
+
compile() {
|
|
475
|
+
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
476
|
+
}
|
|
477
|
+
async execute() {
|
|
478
|
+
await this.#props.executor.executeQuery(this.compile(), this.#props.queryId);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
427
481
|
preventAwait(AlterTableBuilder, "don't await AlterTableBuilder instances");
|
|
428
482
|
preventAwait(AlterColumnBuilder, "don't await AlterColumnBuilder instances");
|
|
429
483
|
preventAwait(AlterTableExecutor, "don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");
|
|
430
484
|
preventAwait(AlterTableAddColumnBuilder, "don't await AlterTableAddColumnBuilder instances directly. To execute the query you need to call `execute`");
|
|
431
485
|
preventAwait(AlterTableModifyColumnBuilder, "don't await AlterTableModifyColumnBuilder instances directly. To execute the query you need to call `execute`");
|
|
432
486
|
preventAwait(AlterTableAddForeignKeyConstraintBuilder, "don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");
|
|
487
|
+
preventAwait(AlterTableDropConstraintBuilder, "don't await AlterTableDropConstraintBuilder instances directly. To execute the query you need to call `execute`");
|