kysely 0.20.1 → 0.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +7 -7
- package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +5 -12
- package/dist/cjs/dialect/postgres/postgres-driver.js +16 -11
- package/dist/cjs/operation-node/create-type-node.d.ts +2 -2
- package/dist/cjs/operation-node/create-type-node.js +2 -2
- package/dist/cjs/operation-node/create-view-node.d.ts +2 -2
- package/dist/cjs/operation-node/create-view-node.js +2 -2
- package/dist/cjs/operation-node/drop-index-node.d.ts +2 -2
- package/dist/cjs/operation-node/drop-index-node.js +2 -2
- package/dist/cjs/operation-node/drop-type-node.d.ts +2 -2
- package/dist/cjs/operation-node/drop-type-node.js +2 -2
- package/dist/cjs/operation-node/drop-view-node.d.ts +2 -2
- package/dist/cjs/operation-node/drop-view-node.js +2 -2
- package/dist/cjs/operation-node/identifier-node.d.ts +2 -2
- package/dist/cjs/operation-node/identifier-node.js +2 -2
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +7 -5
- package/dist/cjs/operation-node/operation-node-transformer.js +24 -14
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +6 -4
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/schemable-identifier-node.d.ts +15 -0
- package/dist/cjs/operation-node/schemable-identifier-node.js +26 -0
- package/dist/cjs/operation-node/table-node.d.ts +2 -3
- package/dist/cjs/operation-node/table-node.js +3 -4
- package/dist/cjs/parser/group-by-parser.d.ts +4 -2
- package/dist/cjs/plugin/camel-case/camel-case-transformer.js +1 -1
- package/dist/cjs/plugin/with-schema/with-schema-transformer.d.ts +4 -28
- package/dist/cjs/plugin/with-schema/with-schema-transformer.js +71 -79
- package/dist/cjs/query-builder/select-query-builder.d.ts +3 -2
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +6 -3
- package/dist/cjs/schema/alter-table-builder.d.ts +6 -6
- package/dist/cjs/schema/column-definition-builder.d.ts +6 -6
- package/dist/esm/dialect/mysql/mysql-introspector.js +7 -7
- package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +5 -12
- package/dist/esm/dialect/postgres/postgres-driver.js +16 -11
- package/dist/esm/operation-node/create-type-node.d.ts +2 -2
- package/dist/esm/operation-node/create-type-node.js +2 -2
- package/dist/esm/operation-node/create-view-node.d.ts +2 -2
- package/dist/esm/operation-node/create-view-node.js +2 -2
- package/dist/esm/operation-node/drop-index-node.d.ts +2 -2
- package/dist/esm/operation-node/drop-index-node.js +2 -2
- package/dist/esm/operation-node/drop-type-node.d.ts +2 -2
- package/dist/esm/operation-node/drop-type-node.js +2 -2
- package/dist/esm/operation-node/drop-view-node.d.ts +2 -2
- package/dist/esm/operation-node/drop-view-node.js +2 -2
- package/dist/esm/operation-node/identifier-node.d.ts +2 -2
- package/dist/esm/operation-node/identifier-node.js +2 -2
- package/dist/esm/operation-node/operation-node-transformer.d.ts +7 -5
- package/dist/esm/operation-node/operation-node-transformer.js +24 -14
- package/dist/esm/operation-node/operation-node-visitor.d.ts +6 -4
- package/dist/esm/operation-node/operation-node-visitor.js +1 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/schemable-identifier-node.d.ts +15 -0
- package/dist/esm/operation-node/schemable-identifier-node.js +24 -0
- package/dist/esm/operation-node/table-node.d.ts +2 -3
- package/dist/esm/operation-node/table-node.js +3 -4
- package/dist/esm/parser/group-by-parser.d.ts +4 -2
- package/dist/esm/plugin/camel-case/camel-case-transformer.js +1 -1
- package/dist/esm/plugin/with-schema/with-schema-transformer.d.ts +4 -28
- package/dist/esm/plugin/with-schema/with-schema-transformer.js +71 -79
- package/dist/esm/query-builder/select-query-builder.d.ts +3 -2
- package/dist/esm/query-builder/select-query-builder.js +1 -1
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/esm/query-compiler/default-query-compiler.js +6 -3
- package/dist/esm/schema/alter-table-builder.d.ts +6 -6
- package/dist/esm/schema/column-definition-builder.d.ts +6 -6
- package/package.json +2 -1
|
@@ -2,120 +2,112 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WithSchemaTransformer = void 0;
|
|
4
4
|
const alias_node_js_1 = require("../../operation-node/alias-node.js");
|
|
5
|
+
const identifier_node_js_1 = require("../../operation-node/identifier-node.js");
|
|
5
6
|
const operation_node_transformer_js_1 = require("../../operation-node/operation-node-transformer.js");
|
|
7
|
+
const schemable_identifier_node_js_1 = require("../../operation-node/schemable-identifier-node.js");
|
|
6
8
|
const table_node_js_1 = require("../../operation-node/table-node.js");
|
|
9
|
+
const object_utils_js_1 = require("../../util/object-utils.js");
|
|
10
|
+
// This object exist only so that we get a type error when a new RootOperationNode
|
|
11
|
+
// is added. If you get a type error here, make sure to add the new root node and
|
|
12
|
+
// handle it correctly in the transformer.
|
|
13
|
+
//
|
|
14
|
+
// DO NOT REFACTOR THIS EVEN IF IT SEEMS USELESS TO YOU!
|
|
15
|
+
const ROOT_OPERATION_NODES = (0, object_utils_js_1.freeze)({
|
|
16
|
+
AlterTableNode: true,
|
|
17
|
+
CreateIndexNode: true,
|
|
18
|
+
CreateSchemaNode: true,
|
|
19
|
+
CreateTableNode: true,
|
|
20
|
+
CreateTypeNode: true,
|
|
21
|
+
CreateViewNode: true,
|
|
22
|
+
DeleteQueryNode: true,
|
|
23
|
+
DropIndexNode: true,
|
|
24
|
+
DropSchemaNode: true,
|
|
25
|
+
DropTableNode: true,
|
|
26
|
+
DropTypeNode: true,
|
|
27
|
+
DropViewNode: true,
|
|
28
|
+
InsertQueryNode: true,
|
|
29
|
+
RawNode: true,
|
|
30
|
+
SelectQueryNode: true,
|
|
31
|
+
UpdateQueryNode: true,
|
|
32
|
+
});
|
|
7
33
|
class WithSchemaTransformer extends operation_node_transformer_js_1.OperationNodeTransformer {
|
|
8
34
|
#schema;
|
|
9
|
-
#
|
|
35
|
+
#schemableIds = new Set();
|
|
10
36
|
constructor(schema) {
|
|
11
37
|
super();
|
|
12
38
|
this.#schema = schema;
|
|
13
39
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return this.#transformRoot(node, (node) => super.transformCreateTable(node));
|
|
28
|
-
}
|
|
29
|
-
transformDropTable(node) {
|
|
30
|
-
return this.#transformRoot(node, (node) => super.transformDropTable(node));
|
|
31
|
-
}
|
|
32
|
-
transformCreateIndex(node) {
|
|
33
|
-
return this.#transformRoot(node, (node) => super.transformCreateIndex(node));
|
|
34
|
-
}
|
|
35
|
-
transformDropIndex(node) {
|
|
36
|
-
return this.#transformRoot(node, (node) => super.transformDropIndex(node));
|
|
37
|
-
}
|
|
38
|
-
transformCreateView(node) {
|
|
39
|
-
return this.#transformRoot(node, (node) => super.transformCreateView(node));
|
|
40
|
-
}
|
|
41
|
-
transformDropView(node) {
|
|
42
|
-
return this.#transformRoot(node, (node) => super.transformDropView(node));
|
|
43
|
-
}
|
|
44
|
-
transformCreateType(node) {
|
|
45
|
-
return this.#transformRoot(node, (node) => super.transformCreateType(node));
|
|
46
|
-
}
|
|
47
|
-
transformDropType(node) {
|
|
48
|
-
return this.#transformRoot(node, (node) => super.transformDropType(node));
|
|
49
|
-
}
|
|
50
|
-
transformAlterTable(node) {
|
|
51
|
-
return this.#transformRoot(node, (node) => super.transformAlterTable(node));
|
|
40
|
+
transformNodeImpl(node) {
|
|
41
|
+
if (!this.#isRootOperationNode(node)) {
|
|
42
|
+
return super.transformNodeImpl(node);
|
|
43
|
+
}
|
|
44
|
+
const tables = this.#collectSchemableIds(node);
|
|
45
|
+
for (const table of tables) {
|
|
46
|
+
this.#schemableIds.add(table);
|
|
47
|
+
}
|
|
48
|
+
const transformed = super.transformNodeImpl(node);
|
|
49
|
+
for (const table of tables) {
|
|
50
|
+
this.#schemableIds.delete(table);
|
|
51
|
+
}
|
|
52
|
+
return transformed;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
const transformed = super.
|
|
55
|
-
if (transformed.schema || !this.#
|
|
54
|
+
transformSchemableIdentifier(node) {
|
|
55
|
+
const transformed = super.transformSchemableIdentifier(node);
|
|
56
|
+
if (transformed.schema || !this.#schemableIds.has(node.identifier.name)) {
|
|
56
57
|
return transformed;
|
|
57
58
|
}
|
|
58
59
|
return {
|
|
59
60
|
...transformed,
|
|
60
|
-
schema:
|
|
61
|
-
kind: 'IdentifierNode',
|
|
62
|
-
identifier: this.#schema,
|
|
63
|
-
},
|
|
61
|
+
schema: identifier_node_js_1.IdentifierNode.create(this.#schema),
|
|
64
62
|
};
|
|
65
63
|
}
|
|
66
|
-
#
|
|
67
|
-
|
|
68
|
-
for (const table of tables) {
|
|
69
|
-
this.#tables.add(table);
|
|
70
|
-
}
|
|
71
|
-
const transformed = transform(node);
|
|
72
|
-
for (const table of tables) {
|
|
73
|
-
this.#tables.delete(table);
|
|
74
|
-
}
|
|
75
|
-
return transformed;
|
|
64
|
+
#isRootOperationNode(node) {
|
|
65
|
+
return node.kind in ROOT_OPERATION_NODES;
|
|
76
66
|
}
|
|
77
|
-
#
|
|
78
|
-
const
|
|
67
|
+
#collectSchemableIds(node) {
|
|
68
|
+
const schemableIds = new Set();
|
|
69
|
+
if ('name' in node && node.name && schemable_identifier_node_js_1.SchemableIdentifierNode.is(node.name)) {
|
|
70
|
+
this.#collectSchemableId(node.name, schemableIds);
|
|
71
|
+
}
|
|
79
72
|
if ('from' in node && node.from) {
|
|
80
|
-
|
|
73
|
+
for (const from of node.from.froms) {
|
|
74
|
+
this.#collectSchemableIdsFromTableExpr(from, schemableIds);
|
|
75
|
+
}
|
|
81
76
|
}
|
|
82
77
|
if ('into' in node && node.into) {
|
|
83
|
-
this.#
|
|
78
|
+
this.#collectSchemableIdsFromTableExpr(node.into, schemableIds);
|
|
84
79
|
}
|
|
85
80
|
if ('table' in node && node.table) {
|
|
86
|
-
this.#
|
|
81
|
+
this.#collectSchemableIdsFromTableExpr(node.table, schemableIds);
|
|
87
82
|
}
|
|
88
83
|
if ('joins' in node && node.joins) {
|
|
89
|
-
|
|
84
|
+
for (const join of node.joins) {
|
|
85
|
+
this.#collectSchemableIdsFromTableExpr(join.table, schemableIds);
|
|
86
|
+
}
|
|
90
87
|
}
|
|
91
88
|
if ('with' in node && node.with) {
|
|
92
|
-
this.#removeCommonTableExpressionTables(node.with,
|
|
93
|
-
}
|
|
94
|
-
return tables;
|
|
95
|
-
}
|
|
96
|
-
#collectTablesFromTableExpressionNodes(nodes, tables) {
|
|
97
|
-
for (const node of nodes) {
|
|
98
|
-
this.#collectTablesFromTableExpressionNode(node, tables);
|
|
89
|
+
this.#removeCommonTableExpressionTables(node.with, schemableIds);
|
|
99
90
|
}
|
|
91
|
+
return schemableIds;
|
|
100
92
|
}
|
|
101
|
-
#
|
|
102
|
-
for (const node of nodes) {
|
|
103
|
-
this.#collectTablesFromTableExpressionNode(node.table, tables);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
#collectTablesFromTableExpressionNode(node, tables) {
|
|
93
|
+
#collectSchemableIdsFromTableExpr(node, schemableIds) {
|
|
107
94
|
const table = table_node_js_1.TableNode.is(node)
|
|
108
95
|
? node
|
|
109
96
|
: alias_node_js_1.AliasNode.is(node) && table_node_js_1.TableNode.is(node.node)
|
|
110
97
|
? node.node
|
|
111
98
|
: null;
|
|
112
|
-
if (table
|
|
113
|
-
|
|
99
|
+
if (table) {
|
|
100
|
+
this.#collectSchemableId(table.table, schemableIds);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
#collectSchemableId(node, schemableIds) {
|
|
104
|
+
if (!this.#schemableIds.has(node.identifier.name)) {
|
|
105
|
+
schemableIds.add(node.identifier.name);
|
|
114
106
|
}
|
|
115
107
|
}
|
|
116
|
-
#removeCommonTableExpressionTables(node,
|
|
108
|
+
#removeCommonTableExpressionTables(node, schemableIds) {
|
|
117
109
|
for (const expr of node.expressions) {
|
|
118
|
-
|
|
110
|
+
schemableIds.delete(expr.name.table.table.identifier.name);
|
|
119
111
|
}
|
|
120
112
|
}
|
|
121
113
|
}
|
|
@@ -12,6 +12,7 @@ import { OrderByDirectionExpression, OrderByExpression } from '../parser/order-b
|
|
|
12
12
|
import { Compilable } from '../util/compilable.js';
|
|
13
13
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
14
14
|
import { QueryId } from '../util/query-id.js';
|
|
15
|
+
import { GroupByExpression } from '../parser/group-by-parser.js';
|
|
15
16
|
import { UnionExpression } from '../parser/union-parser.js';
|
|
16
17
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
17
18
|
import { WhereInterface } from './where-interface.js';
|
|
@@ -1144,8 +1145,8 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1144
1145
|
* group by "first_name"
|
|
1145
1146
|
* ```
|
|
1146
1147
|
*/
|
|
1147
|
-
groupBy(groupBy: ReadonlyArray<
|
|
1148
|
-
groupBy(groupBy:
|
|
1148
|
+
groupBy(groupBy: ReadonlyArray<GroupByExpression<DB, TB, O>>): SelectQueryBuilder<DB, TB, O>;
|
|
1149
|
+
groupBy(groupBy: GroupByExpression<DB, TB, O>): SelectQueryBuilder<DB, TB, O>;
|
|
1149
1150
|
/**
|
|
1150
1151
|
* Adds a limit clause to the query.
|
|
1151
1152
|
*
|
|
@@ -72,6 +72,7 @@ import { SelectModifierNode } from '../operation-node/select-modifier-node.js';
|
|
|
72
72
|
import { CreateTypeNode } from '../operation-node/create-type-node.js';
|
|
73
73
|
import { DropTypeNode } from '../operation-node/drop-type-node.js';
|
|
74
74
|
import { ExplainNode } from '../operation-node/explain-node.js';
|
|
75
|
+
import { SchemableIdentifierNode } from '../operation-node/schemable-identifier-node.js';
|
|
75
76
|
export declare class DefaultQueryCompiler extends OperationNodeVisitor implements QueryCompiler {
|
|
76
77
|
#private;
|
|
77
78
|
protected get numParameters(): number;
|
|
@@ -106,6 +107,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
106
107
|
protected visitRaw(node: RawNode): void;
|
|
107
108
|
protected visitOperator(node: OperatorNode): void;
|
|
108
109
|
protected visitTable(node: TableNode): void;
|
|
110
|
+
protected visitSchemableIdentifier(node: SchemableIdentifierNode): void;
|
|
109
111
|
protected visitCreateTable(node: CreateTableNode): void;
|
|
110
112
|
protected visitColumnDefinition(node: ColumnDefinitionNode): void;
|
|
111
113
|
protected getAutoIncrement(): string;
|
|
@@ -239,10 +239,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
239
239
|
this.append(this.getRightIdentifierWrapper());
|
|
240
240
|
}
|
|
241
241
|
compileUnwrappedIdentifier(node) {
|
|
242
|
-
if (!(0, object_utils_js_1.isString)(node.
|
|
242
|
+
if (!(0, object_utils_js_1.isString)(node.name)) {
|
|
243
243
|
throw new Error('a non-string identifier was passed to compileUnwrappedIdentifier.');
|
|
244
244
|
}
|
|
245
|
-
this.append(this.sanitizeIdentifier(node.
|
|
245
|
+
this.append(this.sanitizeIdentifier(node.name));
|
|
246
246
|
}
|
|
247
247
|
visitFilter(node) {
|
|
248
248
|
if (node.left) {
|
|
@@ -318,11 +318,14 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
318
318
|
this.append(node.operator);
|
|
319
319
|
}
|
|
320
320
|
visitTable(node) {
|
|
321
|
+
this.visitNode(node.table);
|
|
322
|
+
}
|
|
323
|
+
visitSchemableIdentifier(node) {
|
|
321
324
|
if (node.schema) {
|
|
322
325
|
this.visitNode(node.schema);
|
|
323
326
|
this.append('.');
|
|
324
327
|
}
|
|
325
|
-
this.visitNode(node.
|
|
328
|
+
this.visitNode(node.identifier);
|
|
326
329
|
}
|
|
327
330
|
visitCreateTable(node) {
|
|
328
331
|
this.append('create ');
|
|
@@ -92,7 +92,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
92
92
|
* Makes the column the primary key.
|
|
93
93
|
*
|
|
94
94
|
* If you want to specify a composite primary key use the
|
|
95
|
-
* {@link
|
|
95
|
+
* {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
|
|
96
96
|
*/
|
|
97
97
|
primaryKey(): AlterTableAddColumnBuilder;
|
|
98
98
|
/**
|
|
@@ -100,7 +100,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
100
100
|
*
|
|
101
101
|
* If your database engine doesn't support foreign key constraints in the
|
|
102
102
|
* column definition (like MySQL 5) you need to call the table level
|
|
103
|
-
* {@link
|
|
103
|
+
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
|
104
104
|
*
|
|
105
105
|
* ### Examples
|
|
106
106
|
*
|
|
@@ -114,7 +114,7 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
114
114
|
*
|
|
115
115
|
* If your database engine doesn't support foreign key constraints in the
|
|
116
116
|
* column definition (like MySQL 5) you need to call the table level
|
|
117
|
-
* {@link
|
|
117
|
+
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
|
118
118
|
*
|
|
119
119
|
* ### Examples
|
|
120
120
|
*
|
|
@@ -258,7 +258,7 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
|
|
|
258
258
|
* Makes the column the primary key.
|
|
259
259
|
*
|
|
260
260
|
* If you want to specify a composite primary key use the
|
|
261
|
-
* {@link
|
|
261
|
+
* {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
|
|
262
262
|
*/
|
|
263
263
|
primaryKey(): AlterTableModifyColumnBuilder;
|
|
264
264
|
/**
|
|
@@ -266,7 +266,7 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
|
|
|
266
266
|
*
|
|
267
267
|
* If your database engine doesn't support foreign key constraints in the
|
|
268
268
|
* column definition (like MySQL 5) you need to call the table level
|
|
269
|
-
* {@link
|
|
269
|
+
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
|
270
270
|
*
|
|
271
271
|
* ### Examples
|
|
272
272
|
*
|
|
@@ -280,7 +280,7 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
|
|
|
280
280
|
*
|
|
281
281
|
* If your database engine doesn't support foreign key constraints in the
|
|
282
282
|
* column definition (like MySQL 5) you need to call the table level
|
|
283
|
-
* {@link
|
|
283
|
+
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
|
284
284
|
*
|
|
285
285
|
* ### Examples
|
|
286
286
|
*
|
|
@@ -16,7 +16,7 @@ export interface ColumnDefinitionBuilderInterface {
|
|
|
16
16
|
* Makes the column the primary key.
|
|
17
17
|
*
|
|
18
18
|
* If you want to specify a composite primary key use the
|
|
19
|
-
* {@link
|
|
19
|
+
* {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
|
|
20
20
|
*/
|
|
21
21
|
primaryKey(): ColumnDefinitionBuilderInterface;
|
|
22
22
|
/**
|
|
@@ -24,7 +24,7 @@ export interface ColumnDefinitionBuilderInterface {
|
|
|
24
24
|
*
|
|
25
25
|
* If your database engine doesn't support foreign key constraints in the
|
|
26
26
|
* column definition (like MySQL 5) you need to call the table level
|
|
27
|
-
* {@link
|
|
27
|
+
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
|
28
28
|
*
|
|
29
29
|
* ### Examples
|
|
30
30
|
*
|
|
@@ -38,7 +38,7 @@ export interface ColumnDefinitionBuilderInterface {
|
|
|
38
38
|
*
|
|
39
39
|
* If your database engine doesn't support foreign key constraints in the
|
|
40
40
|
* column definition (like MySQL 5) you need to call the table level
|
|
41
|
-
* {@link
|
|
41
|
+
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
|
42
42
|
*
|
|
43
43
|
* ### Examples
|
|
44
44
|
*
|
|
@@ -175,7 +175,7 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
|
|
|
175
175
|
* Makes the column the primary key.
|
|
176
176
|
*
|
|
177
177
|
* If you want to specify a composite primary key use the
|
|
178
|
-
* {@link
|
|
178
|
+
* {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
|
|
179
179
|
*/
|
|
180
180
|
primaryKey(): ColumnDefinitionBuilder;
|
|
181
181
|
/**
|
|
@@ -183,7 +183,7 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
|
|
|
183
183
|
*
|
|
184
184
|
* If your database engine doesn't support foreign key constraints in the
|
|
185
185
|
* column definition (like MySQL 5) you need to call the table level
|
|
186
|
-
* {@link
|
|
186
|
+
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
|
187
187
|
*
|
|
188
188
|
* ### Examples
|
|
189
189
|
*
|
|
@@ -197,7 +197,7 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
|
|
|
197
197
|
*
|
|
198
198
|
* If your database engine doesn't support foreign key constraints in the
|
|
199
199
|
* column definition (like MySQL 5) you need to call the table level
|
|
200
|
-
* {@link
|
|
200
|
+
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
|
201
201
|
*
|
|
202
202
|
* ### Examples
|
|
203
203
|
*
|
|
@@ -19,13 +19,13 @@ export class MysqlIntrospector {
|
|
|
19
19
|
let query = this.#db
|
|
20
20
|
.selectFrom('information_schema.columns')
|
|
21
21
|
.select([
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
22
|
+
'COLUMN_NAME',
|
|
23
|
+
'COLUMN_DEFAULT',
|
|
24
|
+
'TABLE_NAME',
|
|
25
|
+
'TABLE_SCHEMA',
|
|
26
|
+
'IS_NULLABLE',
|
|
27
|
+
'DATA_TYPE',
|
|
28
|
+
'EXTRA',
|
|
29
29
|
])
|
|
30
30
|
.where('table_schema', '=', sql `database()`)
|
|
31
31
|
.orderBy('table_name')
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
2
|
-
export declare type PostgresCursorConstructor = new <T>(sql: string, parameters: readonly unknown[]) => PostgresCursor<T>;
|
|
3
|
-
export declare type PostgresCursor<T> = {
|
|
4
|
-
state: 'initialized' | 'idle' | 'submitted' | 'busy';
|
|
5
|
-
read: (rowsCount: number) => Promise<T[]>;
|
|
6
|
-
} | {
|
|
7
|
-
state: 'done';
|
|
8
|
-
} | {
|
|
9
|
-
state: 'error';
|
|
10
|
-
_error: Error;
|
|
11
|
-
};
|
|
12
2
|
/**
|
|
13
3
|
* Config for the PostgreSQL dialect.
|
|
14
4
|
*/
|
|
@@ -56,13 +46,16 @@ export interface PostgresPoolClient {
|
|
|
56
46
|
query<R>(cursor: PostgresCursor<R>): PostgresCursor<R>;
|
|
57
47
|
release(): void;
|
|
58
48
|
}
|
|
49
|
+
export interface PostgresCursor<T> {
|
|
50
|
+
read(rowsCount: number): Promise<T[]>;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export declare type PostgresCursorConstructor = new <T>(sql: string, parameters: unknown[]) => PostgresCursor<T>;
|
|
59
54
|
export interface PostgresQueryResult<R> {
|
|
60
55
|
command: 'UPDATE' | 'DELETE' | 'INSERT' | 'SELECT';
|
|
61
56
|
rowCount: number;
|
|
62
57
|
rows: R[];
|
|
63
58
|
}
|
|
64
|
-
export interface PostgresStreamOptions {
|
|
65
|
-
}
|
|
66
59
|
export interface PostgresStream<T> {
|
|
67
60
|
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
68
61
|
}
|
|
@@ -87,18 +87,23 @@ class PostgresConnection {
|
|
|
87
87
|
if (!this.#options.cursor) {
|
|
88
88
|
throw new Error("'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.");
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
if (!Number.isInteger(chunkSize) || chunkSize <= 0) {
|
|
91
|
+
throw new Error('chunkSize must be a positive integer');
|
|
92
|
+
}
|
|
93
|
+
const cursor = this.#client.query(new this.#options.cursor(compiledQuery.sql, compiledQuery.parameters.slice()));
|
|
94
|
+
try {
|
|
95
|
+
while (true) {
|
|
96
|
+
const rows = await cursor.read(chunkSize);
|
|
97
|
+
if (rows.length === 0) {
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
yield {
|
|
101
|
+
rows,
|
|
102
|
+
};
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
await cursor.close();
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
109
|
[PRIVATE_RELEASE_METHOD]() {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IdentifierNode } from './identifier-node.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
3
3
|
import { ValueListNode } from './value-list-node.js';
|
|
4
4
|
export declare type CreateTypeNodeParams = Omit<Partial<CreateTypeNode>, 'kind'>;
|
|
5
5
|
export interface CreateTypeNode extends OperationNode {
|
|
6
6
|
readonly kind: 'CreateTypeNode';
|
|
7
|
-
readonly name:
|
|
7
|
+
readonly name: SchemableIdentifierNode;
|
|
8
8
|
readonly enum?: ValueListNode;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="./create-type-node.d.ts" />
|
|
2
2
|
import { freeze } from '../util/object-utils.js';
|
|
3
|
-
import {
|
|
3
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
4
4
|
import { ValueListNode } from './value-list-node.js';
|
|
5
5
|
import { ValueNode } from './value-node.js';
|
|
6
6
|
/**
|
|
@@ -13,7 +13,7 @@ export const CreateTypeNode = freeze({
|
|
|
13
13
|
create(name) {
|
|
14
14
|
return freeze({
|
|
15
15
|
kind: 'CreateTypeNode',
|
|
16
|
-
name:
|
|
16
|
+
name: SchemableIdentifierNode.create(name),
|
|
17
17
|
});
|
|
18
18
|
},
|
|
19
19
|
cloneWithEnum(createType, values) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ColumnNode } from './column-node.js';
|
|
2
|
-
import { IdentifierNode } from './identifier-node.js';
|
|
3
2
|
import { OperationNode } from './operation-node.js';
|
|
4
3
|
import { RawNode } from './raw-node.js';
|
|
4
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
5
5
|
import { SelectQueryNode } from './select-query-node.js';
|
|
6
6
|
export declare type CreateViewNodeParams = Omit<Partial<CreateViewNode>, 'kind' | 'name'>;
|
|
7
7
|
export interface CreateViewNode extends OperationNode {
|
|
8
8
|
readonly kind: 'CreateViewNode';
|
|
9
|
-
readonly name:
|
|
9
|
+
readonly name: SchemableIdentifierNode;
|
|
10
10
|
readonly temporary?: boolean;
|
|
11
11
|
readonly materialized?: boolean;
|
|
12
12
|
readonly orReplace?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="./create-view-node.d.ts" />
|
|
2
2
|
import { freeze } from '../util/object-utils.js';
|
|
3
|
-
import {
|
|
3
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
@@ -11,7 +11,7 @@ export const CreateViewNode = freeze({
|
|
|
11
11
|
create(name) {
|
|
12
12
|
return freeze({
|
|
13
13
|
kind: 'CreateViewNode',
|
|
14
|
-
name:
|
|
14
|
+
name: SchemableIdentifierNode.create(name),
|
|
15
15
|
});
|
|
16
16
|
},
|
|
17
17
|
cloneWith(createView, params) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IdentifierNode } from './identifier-node.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
3
3
|
import { TableNode } from './table-node.js';
|
|
4
4
|
export declare type DropIndexNodeProps = Omit<DropIndexNode, 'kind' | 'name'>;
|
|
5
5
|
export interface DropIndexNode extends OperationNode {
|
|
6
6
|
readonly kind: 'DropIndexNode';
|
|
7
|
-
readonly name:
|
|
7
|
+
readonly name: SchemableIdentifierNode;
|
|
8
8
|
readonly table?: TableNode;
|
|
9
9
|
readonly ifExists?: boolean;
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="./drop-index-node.d.ts" />
|
|
2
2
|
import { freeze } from '../util/object-utils.js';
|
|
3
|
-
import {
|
|
3
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
@@ -11,7 +11,7 @@ export const DropIndexNode = freeze({
|
|
|
11
11
|
create(name, params) {
|
|
12
12
|
return freeze({
|
|
13
13
|
kind: 'DropIndexNode',
|
|
14
|
-
name:
|
|
14
|
+
name: SchemableIdentifierNode.create(name),
|
|
15
15
|
...params,
|
|
16
16
|
});
|
|
17
17
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IdentifierNode } from './identifier-node.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
3
3
|
export declare type DropTypeNodeParams = Omit<Partial<DropTypeNode>, 'kind' | 'name'>;
|
|
4
4
|
export interface DropTypeNode extends OperationNode {
|
|
5
5
|
readonly kind: 'DropTypeNode';
|
|
6
|
-
readonly name:
|
|
6
|
+
readonly name: SchemableIdentifierNode;
|
|
7
7
|
readonly ifExists?: boolean;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="./drop-type-node.d.ts" />
|
|
2
2
|
import { freeze } from '../util/object-utils.js';
|
|
3
|
-
import {
|
|
3
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
@@ -11,7 +11,7 @@ export const DropTypeNode = freeze({
|
|
|
11
11
|
create(name) {
|
|
12
12
|
return freeze({
|
|
13
13
|
kind: 'DropTypeNode',
|
|
14
|
-
name:
|
|
14
|
+
name: SchemableIdentifierNode.create(name),
|
|
15
15
|
});
|
|
16
16
|
},
|
|
17
17
|
cloneWith(dropType, params) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IdentifierNode } from './identifier-node.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
3
3
|
export declare type DropViewNodeParams = Omit<Partial<DropViewNode>, 'kind' | 'name'>;
|
|
4
4
|
export interface DropViewNode extends OperationNode {
|
|
5
5
|
readonly kind: 'DropViewNode';
|
|
6
|
-
readonly name:
|
|
6
|
+
readonly name: SchemableIdentifierNode;
|
|
7
7
|
readonly ifExists?: boolean;
|
|
8
8
|
readonly materialized?: boolean;
|
|
9
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="./drop-view-node.d.ts" />
|
|
2
2
|
import { freeze } from '../util/object-utils.js';
|
|
3
|
-
import {
|
|
3
|
+
import { SchemableIdentifierNode } from './schemable-identifier-node.js';
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
@@ -11,7 +11,7 @@ export const DropViewNode = freeze({
|
|
|
11
11
|
create(name) {
|
|
12
12
|
return freeze({
|
|
13
13
|
kind: 'DropViewNode',
|
|
14
|
-
name:
|
|
14
|
+
name: SchemableIdentifierNode.create(name),
|
|
15
15
|
});
|
|
16
16
|
},
|
|
17
17
|
cloneWith(dropView, params) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
2
|
export interface IdentifierNode extends OperationNode {
|
|
3
3
|
readonly kind: 'IdentifierNode';
|
|
4
|
-
readonly
|
|
4
|
+
readonly name: string;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export declare const IdentifierNode: Readonly<{
|
|
10
10
|
is(node: OperationNode): node is IdentifierNode;
|
|
11
|
-
create(
|
|
11
|
+
create(name: string): IdentifierNode;
|
|
12
12
|
}>;
|