kysely 0.19.0 → 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/mysql/mysql-introspector.js +2 -6
- 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/migration/migrator.d.ts +2 -0
- 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 +15 -5
- package/dist/cjs/schema/alter-table-builder.js +60 -8
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +0 -5
- package/dist/esm/dialect/mysql/mysql-introspector.js +2 -6
- 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/migration/migrator.d.ts +2 -0
- 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 +15 -5
- package/dist/esm/schema/alter-table-builder.js +59 -8
- 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
|
/**
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MysqlIntrospector = void 0;
|
|
4
4
|
const migrator_js_1 = require("../../migration/migrator.js");
|
|
5
5
|
const object_utils_js_1 = require("../../util/object-utils.js");
|
|
6
|
+
const sql_js_1 = require("../../raw-builder/sql.js");
|
|
6
7
|
class MysqlIntrospector {
|
|
7
8
|
#db;
|
|
8
9
|
constructor(db) {
|
|
@@ -26,12 +27,7 @@ class MysqlIntrospector {
|
|
|
26
27
|
'is_nullable',
|
|
27
28
|
'data_type',
|
|
28
29
|
])
|
|
29
|
-
.where('table_schema', '
|
|
30
|
-
'information_schema',
|
|
31
|
-
'performance_schema',
|
|
32
|
-
'mysql',
|
|
33
|
-
'sys',
|
|
34
|
-
])
|
|
30
|
+
.where('table_schema', '=', (0, sql_js_1.sql) `database()`)
|
|
35
31
|
.castTo();
|
|
36
32
|
if (!options.withInternalKyselyTables) {
|
|
37
33
|
query = query
|
|
@@ -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
|
}
|
|
@@ -188,6 +188,8 @@ export interface MigratorProps {
|
|
|
188
188
|
* If you do specify this, ALWAYS ALWAYS use the same value from the beginning of
|
|
189
189
|
* the project, to the end of time or prepare to manually migrate the migration
|
|
190
190
|
* tables.
|
|
191
|
+
*
|
|
192
|
+
* This only works on postgres.
|
|
191
193
|
*/
|
|
192
194
|
readonly migrationTableSchema?: string;
|
|
193
195
|
}
|
|
@@ -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 ');
|
|
@@ -25,12 +25,8 @@ export declare class AlterTableBuilder {
|
|
|
25
25
|
renameColumn(column: string, newColumn: string): AlterTableExecutor;
|
|
26
26
|
/**
|
|
27
27
|
* See {@link CreateTableBuilder.addColumn}
|
|
28
|
-
*
|
|
29
|
-
* Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
|
|
30
|
-
* and doesn't take a callback as the last argument. This is because you can only
|
|
31
|
-
* add one column per `ALTER TABLE` query.
|
|
32
28
|
*/
|
|
33
|
-
addColumn(columnName: string, dataType: DataTypeExpression): AlterTableAddColumnBuilder;
|
|
29
|
+
addColumn(columnName: string, dataType: DataTypeExpression, build?: AlterTableAddColumnBuilderCallback): AlterTableAddColumnBuilder;
|
|
34
30
|
/**
|
|
35
31
|
* Creates an `alter table modify column` query. The `modify column` statement
|
|
36
32
|
* is only implemeted by MySQL and oracle AFAIK. On other databases you
|
|
@@ -53,6 +49,7 @@ export declare class AlterTableBuilder {
|
|
|
53
49
|
* is because you can only add one column per `ALTER TABLE` query.
|
|
54
50
|
*/
|
|
55
51
|
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[]): AlterTableAddForeignKeyConstraintBuilder;
|
|
52
|
+
dropConstraint(constraintName: string): AlterTableDropConstraintBuilder;
|
|
56
53
|
}
|
|
57
54
|
export interface AlterTableBuilderProps {
|
|
58
55
|
readonly queryId: QueryId;
|
|
@@ -245,6 +242,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
245
242
|
export interface AlterTableAddColumnBuilderProps extends AlterTableBuilderProps {
|
|
246
243
|
readonly columnBuilder: ColumnDefinitionBuilder;
|
|
247
244
|
}
|
|
245
|
+
export declare type AlterTableAddColumnBuilderCallback = (builder: AlterTableAddColumnBuilder) => AlterTableAddColumnBuilder;
|
|
248
246
|
export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBuilderInterface, OperationNodeSource, Compilable {
|
|
249
247
|
#private;
|
|
250
248
|
constructor(props: AlterTableModifyColumnBuilderProps);
|
|
@@ -422,3 +420,15 @@ export declare class AlterTableAddForeignKeyConstraintBuilder implements Foreign
|
|
|
422
420
|
export interface AlterTableAddForeignKeyConstraintBuilderProps extends AlterTableBuilderProps {
|
|
423
421
|
readonly constraintBuilder: ForeignKeyConstraintBuilder;
|
|
424
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
|
*/
|
|
@@ -70,16 +71,12 @@ class AlterTableBuilder {
|
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
73
|
* See {@link CreateTableBuilder.addColumn}
|
|
73
|
-
*
|
|
74
|
-
* Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
|
|
75
|
-
* and doesn't take a callback as the last argument. This is because you can only
|
|
76
|
-
* add one column per `ALTER TABLE` query.
|
|
77
74
|
*/
|
|
78
|
-
addColumn(columnName, dataType) {
|
|
79
|
-
return new AlterTableAddColumnBuilder({
|
|
75
|
+
addColumn(columnName, dataType, build = object_utils_js_1.noop) {
|
|
76
|
+
return build(new AlterTableAddColumnBuilder({
|
|
80
77
|
...this.#props,
|
|
81
78
|
columnBuilder: new column_definition_builder_js_1.ColumnDefinitionBuilder(column_definition_node_js_1.ColumnDefinitionNode.create(columnName, (0, data_type_parser_js_1.parseDataTypeExpression)(dataType))),
|
|
82
|
-
});
|
|
79
|
+
}));
|
|
83
80
|
}
|
|
84
81
|
/**
|
|
85
82
|
* Creates an `alter table modify column` query. The `modify column` statement
|
|
@@ -127,6 +124,14 @@ class AlterTableBuilder {
|
|
|
127
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)),
|
|
128
125
|
});
|
|
129
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
|
+
}
|
|
130
135
|
}
|
|
131
136
|
exports.AlterTableBuilder = AlterTableBuilder;
|
|
132
137
|
class AlterColumnBuilder {
|
|
@@ -436,9 +441,56 @@ class AlterTableAddForeignKeyConstraintBuilder {
|
|
|
436
441
|
}
|
|
437
442
|
}
|
|
438
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;
|
|
439
490
|
(0, prevent_await_js_1.preventAwait)(AlterTableBuilder, "don't await AlterTableBuilder instances");
|
|
440
491
|
(0, prevent_await_js_1.preventAwait)(AlterColumnBuilder, "don't await AlterColumnBuilder instances");
|
|
441
492
|
(0, prevent_await_js_1.preventAwait)(AlterTableExecutor, "don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");
|
|
442
493
|
(0, prevent_await_js_1.preventAwait)(AlterTableAddColumnBuilder, "don't await AlterTableAddColumnBuilder instances directly. To execute the query you need to call `execute`");
|
|
443
494
|
(0, prevent_await_js_1.preventAwait)(AlterTableModifyColumnBuilder, "don't await AlterTableModifyColumnBuilder instances directly. To execute the query you need to call `execute`");
|
|
444
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
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="./mysql-introspector.d.ts" />
|
|
2
2
|
import { DEFAULT_MIGRATION_LOCK_TABLE, DEFAULT_MIGRATION_TABLE, } from '../../migration/migrator.js';
|
|
3
3
|
import { freeze } from '../../util/object-utils.js';
|
|
4
|
+
import { sql } from '../../raw-builder/sql.js';
|
|
4
5
|
export class MysqlIntrospector {
|
|
5
6
|
#db;
|
|
6
7
|
constructor(db) {
|
|
@@ -24,12 +25,7 @@ export class MysqlIntrospector {
|
|
|
24
25
|
'is_nullable',
|
|
25
26
|
'data_type',
|
|
26
27
|
])
|
|
27
|
-
.where('table_schema', '
|
|
28
|
-
'information_schema',
|
|
29
|
-
'performance_schema',
|
|
30
|
-
'mysql',
|
|
31
|
-
'sys',
|
|
32
|
-
])
|
|
28
|
+
.where('table_schema', '=', sql `database()`)
|
|
33
29
|
.castTo();
|
|
34
30
|
if (!options.withInternalKyselyTables) {
|
|
35
31
|
query = query
|
|
@@ -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
|
}
|
|
@@ -188,6 +188,8 @@ export interface MigratorProps {
|
|
|
188
188
|
* If you do specify this, ALWAYS ALWAYS use the same value from the beginning of
|
|
189
189
|
* the project, to the end of time or prepare to manually migrate the migration
|
|
190
190
|
* tables.
|
|
191
|
+
*
|
|
192
|
+
* This only works on postgres.
|
|
191
193
|
*/
|
|
192
194
|
readonly migrationTableSchema?: string;
|
|
193
195
|
}
|
|
@@ -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 ');
|
|
@@ -25,12 +25,8 @@ export declare class AlterTableBuilder {
|
|
|
25
25
|
renameColumn(column: string, newColumn: string): AlterTableExecutor;
|
|
26
26
|
/**
|
|
27
27
|
* See {@link CreateTableBuilder.addColumn}
|
|
28
|
-
*
|
|
29
|
-
* Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
|
|
30
|
-
* and doesn't take a callback as the last argument. This is because you can only
|
|
31
|
-
* add one column per `ALTER TABLE` query.
|
|
32
28
|
*/
|
|
33
|
-
addColumn(columnName: string, dataType: DataTypeExpression): AlterTableAddColumnBuilder;
|
|
29
|
+
addColumn(columnName: string, dataType: DataTypeExpression, build?: AlterTableAddColumnBuilderCallback): AlterTableAddColumnBuilder;
|
|
34
30
|
/**
|
|
35
31
|
* Creates an `alter table modify column` query. The `modify column` statement
|
|
36
32
|
* is only implemeted by MySQL and oracle AFAIK. On other databases you
|
|
@@ -53,6 +49,7 @@ export declare class AlterTableBuilder {
|
|
|
53
49
|
* is because you can only add one column per `ALTER TABLE` query.
|
|
54
50
|
*/
|
|
55
51
|
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[]): AlterTableAddForeignKeyConstraintBuilder;
|
|
52
|
+
dropConstraint(constraintName: string): AlterTableDropConstraintBuilder;
|
|
56
53
|
}
|
|
57
54
|
export interface AlterTableBuilderProps {
|
|
58
55
|
readonly queryId: QueryId;
|
|
@@ -245,6 +242,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
245
242
|
export interface AlterTableAddColumnBuilderProps extends AlterTableBuilderProps {
|
|
246
243
|
readonly columnBuilder: ColumnDefinitionBuilder;
|
|
247
244
|
}
|
|
245
|
+
export declare type AlterTableAddColumnBuilderCallback = (builder: AlterTableAddColumnBuilder) => AlterTableAddColumnBuilder;
|
|
248
246
|
export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBuilderInterface, OperationNodeSource, Compilable {
|
|
249
247
|
#private;
|
|
250
248
|
constructor(props: AlterTableModifyColumnBuilderProps);
|
|
@@ -422,3 +420,15 @@ export declare class AlterTableAddForeignKeyConstraintBuilder implements Foreign
|
|
|
422
420
|
export interface AlterTableAddForeignKeyConstraintBuilderProps extends AlterTableBuilderProps {
|
|
423
421
|
readonly constraintBuilder: ForeignKeyConstraintBuilder;
|
|
424
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
|
+
}
|
|
@@ -7,7 +7,7 @@ import { DataTypeNode, } from '../operation-node/data-type-node.js';
|
|
|
7
7
|
import { DropColumnNode } from '../operation-node/drop-column-node.js';
|
|
8
8
|
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
|
9
9
|
import { RenameColumnNode } from '../operation-node/rename-column-node.js';
|
|
10
|
-
import { freeze } from '../util/object-utils.js';
|
|
10
|
+
import { freeze, noop } from '../util/object-utils.js';
|
|
11
11
|
import { preventAwait } from '../util/prevent-await.js';
|
|
12
12
|
import { ColumnDefinitionBuilder, } from './column-definition-builder.js';
|
|
13
13
|
import { ModifyColumnNode } from '../operation-node/modify-column-node.js';
|
|
@@ -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
|
*/
|
|
@@ -68,16 +69,12 @@ export class AlterTableBuilder {
|
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
71
|
* See {@link CreateTableBuilder.addColumn}
|
|
71
|
-
*
|
|
72
|
-
* Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
|
|
73
|
-
* and doesn't take a callback as the last argument. This is because you can only
|
|
74
|
-
* add one column per `ALTER TABLE` query.
|
|
75
72
|
*/
|
|
76
|
-
addColumn(columnName, dataType) {
|
|
77
|
-
return new AlterTableAddColumnBuilder({
|
|
73
|
+
addColumn(columnName, dataType, build = noop) {
|
|
74
|
+
return build(new AlterTableAddColumnBuilder({
|
|
78
75
|
...this.#props,
|
|
79
76
|
columnBuilder: new ColumnDefinitionBuilder(ColumnDefinitionNode.create(columnName, parseDataTypeExpression(dataType))),
|
|
80
|
-
});
|
|
77
|
+
}));
|
|
81
78
|
}
|
|
82
79
|
/**
|
|
83
80
|
* Creates an `alter table modify column` query. The `modify column` statement
|
|
@@ -125,6 +122,14 @@ export class AlterTableBuilder {
|
|
|
125
122
|
constraintBuilder: new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.create(columns.map(ColumnNode.create), parseTable(targetTable), targetColumns.map(ColumnNode.create), constraintName)),
|
|
126
123
|
});
|
|
127
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
|
+
}
|
|
128
133
|
}
|
|
129
134
|
export class AlterColumnBuilder {
|
|
130
135
|
#props;
|
|
@@ -428,9 +433,55 @@ export class AlterTableAddForeignKeyConstraintBuilder {
|
|
|
428
433
|
await this.#props.executor.executeQuery(this.compile(), this.#props.queryId);
|
|
429
434
|
}
|
|
430
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
|
+
}
|
|
431
481
|
preventAwait(AlterTableBuilder, "don't await AlterTableBuilder instances");
|
|
432
482
|
preventAwait(AlterColumnBuilder, "don't await AlterColumnBuilder instances");
|
|
433
483
|
preventAwait(AlterTableExecutor, "don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");
|
|
434
484
|
preventAwait(AlterTableAddColumnBuilder, "don't await AlterTableAddColumnBuilder instances directly. To execute the query you need to call `execute`");
|
|
435
485
|
preventAwait(AlterTableModifyColumnBuilder, "don't await AlterTableModifyColumnBuilder instances directly. To execute the query you need to call `execute`");
|
|
436
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`");
|