kysely 0.26.3 → 0.27.1
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/dialect-adapter-base.d.ts +8 -0
- package/dist/cjs/dialect/dialect-adapter-base.js +3 -0
- package/dist/cjs/dialect/dialect-adapter.d.ts +8 -0
- package/dist/cjs/dialect/mssql/mssql-adapter.d.ts +78 -0
- package/dist/cjs/dialect/mssql/mssql-adapter.js +30 -0
- package/dist/cjs/dialect/mssql/mssql-dialect-config.d.ts +143 -0
- package/dist/cjs/dialect/mssql/mssql-dialect-config.js +2 -0
- package/dist/cjs/dialect/mssql/mssql-dialect.d.ts +70 -0
- package/dist/cjs/dialect/mssql/mssql-dialect.js +65 -0
- package/dist/cjs/dialect/mssql/mssql-driver.d.ts +54 -0
- package/dist/cjs/dialect/mssql/mssql-driver.js +268 -0
- package/dist/cjs/dialect/mssql/mssql-introspector.d.ts +20 -0
- package/dist/cjs/dialect/mssql/mssql-introspector.js +99 -0
- package/dist/cjs/dialect/mssql/mssql-query-compiler.d.ts +11 -0
- package/dist/cjs/dialect/mssql/mssql-query-compiler.js +64 -0
- package/dist/cjs/dialect/mysql/mysql-query-compiler.d.ts +2 -0
- package/dist/cjs/dialect/mysql/mysql-query-compiler.js +28 -0
- package/dist/cjs/dialect/postgres/postgres-driver.js +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-adapter.js +2 -1
- package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +1 -0
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +15 -2
- package/dist/cjs/driver/driver.d.ts +1 -1
- package/dist/cjs/driver/driver.js +1 -0
- package/dist/cjs/driver/runtime-driver.js +5 -1
- package/dist/cjs/driver/single-connection-provider.js +7 -8
- package/dist/cjs/expression/expression-builder.d.ts +66 -75
- package/dist/cjs/expression/expression-builder.js +8 -17
- package/dist/cjs/expression/expression-wrapper.d.ts +21 -11
- package/dist/cjs/expression/expression-wrapper.js +12 -0
- package/dist/cjs/helpers/mssql.d.ts +152 -0
- package/dist/cjs/helpers/mssql.js +160 -0
- package/dist/cjs/index.d.ts +7 -1
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/migration/migrator.js +12 -16
- package/dist/cjs/operation-node/add-index-node.d.ts +21 -0
- package/dist/cjs/operation-node/add-index-node.js +31 -0
- package/dist/cjs/operation-node/alter-table-node.d.ts +5 -1
- package/dist/cjs/operation-node/column-definition-node.d.ts +1 -0
- package/dist/cjs/operation-node/column-update-node.d.ts +2 -3
- package/dist/cjs/operation-node/create-index-node.d.ts +1 -0
- package/dist/cjs/operation-node/create-table-node.d.ts +1 -0
- package/dist/cjs/operation-node/insert-query-node.d.ts +1 -0
- package/dist/cjs/operation-node/limit-node.d.ts +2 -3
- package/dist/cjs/operation-node/limit-node.js +1 -2
- package/dist/cjs/operation-node/offset-node.d.ts +2 -3
- package/dist/cjs/operation-node/offset-node.js +1 -2
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +19 -0
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
- 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/operator-node.d.ts +3 -3
- package/dist/cjs/operation-node/operator-node.js +2 -0
- package/dist/cjs/operation-node/select-modifier-node.d.ts +2 -1
- package/dist/cjs/operation-node/select-modifier-node.js +2 -1
- package/dist/cjs/operation-node/unique-constraint-node.d.ts +4 -1
- package/dist/cjs/operation-node/unique-constraint-node.js +8 -1
- package/dist/cjs/parser/binary-operation-parser.js +1 -1
- package/dist/cjs/parser/coalesce-parser.d.ts +12 -2
- package/dist/cjs/parser/reference-parser.d.ts +2 -1
- package/dist/cjs/parser/update-set-parser.d.ts +5 -2
- package/dist/cjs/parser/update-set-parser.js +13 -3
- package/dist/cjs/query-builder/aggregate-function-builder.d.ts +21 -4
- package/dist/cjs/query-builder/aggregate-function-builder.js +21 -0
- package/dist/cjs/query-builder/case-builder.d.ts +6 -5
- package/dist/cjs/query-builder/delete-query-builder.d.ts +8 -7
- package/dist/cjs/query-builder/delete-query-builder.js +4 -3
- package/dist/cjs/query-builder/function-module.d.ts +96 -25
- package/dist/cjs/query-builder/function-module.js +17 -3
- package/dist/cjs/query-builder/having-interface.d.ts +3 -5
- package/dist/cjs/query-builder/insert-query-builder.d.ts +34 -12
- package/dist/cjs/query-builder/insert-query-builder.js +16 -5
- package/dist/cjs/query-builder/insert-result.d.ts +8 -1
- package/dist/cjs/query-builder/insert-result.js +8 -1
- package/dist/cjs/query-builder/json-path-builder.d.ts +5 -3
- package/dist/cjs/query-builder/json-path-builder.js +9 -3
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +58 -16
- package/dist/cjs/query-builder/on-conflict-builder.js +1 -6
- package/dist/cjs/query-builder/over-builder.d.ts +2 -2
- package/dist/cjs/query-builder/select-query-builder.d.ts +49 -31
- package/dist/cjs/query-builder/select-query-builder.js +12 -10
- package/dist/cjs/query-builder/update-query-builder.d.ts +23 -7
- package/dist/cjs/query-builder/update-query-builder.js +4 -4
- package/dist/cjs/query-builder/where-interface.d.ts +3 -3
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +9 -1
- package/dist/cjs/query-compiler/default-query-compiler.js +73 -12
- package/dist/cjs/raw-builder/raw-builder.d.ts +11 -1
- package/dist/cjs/raw-builder/raw-builder.js +3 -0
- package/dist/cjs/raw-builder/sql.js +9 -2
- package/dist/cjs/schema/alter-table-add-index-builder.d.ts +104 -0
- package/dist/cjs/schema/alter-table-add-index-builder.js +146 -0
- package/dist/cjs/schema/alter-table-builder.d.ts +41 -1
- package/dist/cjs/schema/alter-table-builder.js +59 -2
- package/dist/cjs/schema/column-definition-builder.d.ts +25 -0
- package/dist/cjs/schema/column-definition-builder.js +27 -0
- package/dist/cjs/schema/create-index-builder.d.ts +23 -0
- package/dist/cjs/schema/create-index-builder.js +30 -0
- package/dist/cjs/schema/create-table-builder.d.ts +28 -2
- package/dist/cjs/schema/create-table-builder.js +38 -3
- package/dist/cjs/schema/unique-constraint-builder.d.ts +14 -0
- package/dist/cjs/schema/unique-constraint-builder.js +24 -0
- package/dist/cjs/util/log.js +5 -1
- package/dist/cjs/util/object-utils.d.ts +2 -2
- package/dist/cjs/util/object-utils.js +1 -1
- package/dist/cjs/util/type-utils.d.ts +27 -19
- package/dist/esm/dialect/dialect-adapter-base.d.ts +8 -0
- package/dist/esm/dialect/dialect-adapter-base.js +3 -0
- package/dist/esm/dialect/dialect-adapter.d.ts +8 -0
- package/dist/esm/dialect/mssql/mssql-adapter.d.ts +78 -0
- package/dist/esm/dialect/mssql/mssql-adapter.js +27 -0
- package/dist/esm/dialect/mssql/mssql-dialect-config.d.ts +143 -0
- package/dist/esm/dialect/mssql/mssql-dialect-config.js +2 -0
- package/dist/esm/dialect/mssql/mssql-dialect.d.ts +70 -0
- package/dist/esm/dialect/mssql/mssql-dialect.js +62 -0
- package/dist/esm/dialect/mssql/mssql-driver.d.ts +54 -0
- package/dist/esm/dialect/mssql/mssql-driver.js +265 -0
- package/dist/esm/dialect/mssql/mssql-introspector.d.ts +20 -0
- package/dist/esm/dialect/mssql/mssql-introspector.js +96 -0
- package/dist/esm/dialect/mssql/mssql-query-compiler.d.ts +11 -0
- package/dist/esm/dialect/mssql/mssql-query-compiler.js +61 -0
- package/dist/esm/dialect/mysql/mysql-query-compiler.d.ts +2 -0
- package/dist/esm/dialect/mysql/mysql-query-compiler.js +28 -0
- package/dist/esm/dialect/postgres/postgres-driver.js +1 -1
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-adapter.js +2 -1
- package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +1 -0
- package/dist/esm/dialect/sqlite/sqlite-driver.js +15 -2
- package/dist/esm/driver/driver.d.ts +1 -1
- package/dist/esm/driver/driver.js +1 -0
- package/dist/esm/driver/runtime-driver.js +5 -1
- package/dist/esm/driver/single-connection-provider.js +7 -8
- package/dist/esm/expression/expression-builder.d.ts +66 -75
- package/dist/esm/expression/expression-builder.js +10 -19
- package/dist/esm/expression/expression-wrapper.d.ts +21 -11
- package/dist/esm/expression/expression-wrapper.js +12 -0
- package/dist/esm/helpers/mssql.d.ts +152 -0
- package/dist/esm/helpers/mssql.js +155 -0
- package/dist/esm/index.d.ts +7 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/migration/migrator.js +12 -16
- package/dist/esm/operation-node/add-index-node.d.ts +21 -0
- package/dist/esm/operation-node/add-index-node.js +29 -0
- package/dist/esm/operation-node/alter-table-node.d.ts +5 -1
- package/dist/esm/operation-node/column-definition-node.d.ts +1 -0
- package/dist/esm/operation-node/column-update-node.d.ts +2 -3
- package/dist/esm/operation-node/create-index-node.d.ts +1 -0
- package/dist/esm/operation-node/create-table-node.d.ts +1 -0
- package/dist/esm/operation-node/insert-query-node.d.ts +1 -0
- package/dist/esm/operation-node/limit-node.d.ts +2 -3
- package/dist/esm/operation-node/limit-node.js +1 -2
- package/dist/esm/operation-node/offset-node.d.ts +2 -3
- package/dist/esm/operation-node/offset-node.js +1 -2
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +19 -0
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
- 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/operator-node.d.ts +3 -3
- package/dist/esm/operation-node/operator-node.js +2 -0
- package/dist/esm/operation-node/select-modifier-node.d.ts +2 -1
- package/dist/esm/operation-node/select-modifier-node.js +2 -1
- package/dist/esm/operation-node/unique-constraint-node.d.ts +4 -1
- package/dist/esm/operation-node/unique-constraint-node.js +8 -1
- package/dist/esm/parser/binary-operation-parser.js +1 -1
- package/dist/esm/parser/coalesce-parser.d.ts +12 -2
- package/dist/esm/parser/reference-parser.d.ts +2 -1
- package/dist/esm/parser/update-set-parser.d.ts +5 -2
- package/dist/esm/parser/update-set-parser.js +10 -1
- package/dist/esm/query-builder/aggregate-function-builder.d.ts +21 -4
- package/dist/esm/query-builder/aggregate-function-builder.js +21 -0
- package/dist/esm/query-builder/case-builder.d.ts +6 -5
- package/dist/esm/query-builder/delete-query-builder.d.ts +8 -7
- package/dist/esm/query-builder/delete-query-builder.js +4 -3
- package/dist/esm/query-builder/function-module.d.ts +96 -25
- package/dist/esm/query-builder/function-module.js +17 -3
- package/dist/esm/query-builder/having-interface.d.ts +3 -5
- package/dist/esm/query-builder/insert-query-builder.d.ts +34 -12
- package/dist/esm/query-builder/insert-query-builder.js +17 -6
- package/dist/esm/query-builder/insert-result.d.ts +8 -1
- package/dist/esm/query-builder/insert-result.js +8 -1
- package/dist/esm/query-builder/json-path-builder.d.ts +5 -3
- package/dist/esm/query-builder/json-path-builder.js +9 -3
- package/dist/esm/query-builder/on-conflict-builder.d.ts +58 -16
- package/dist/esm/query-builder/on-conflict-builder.js +2 -7
- package/dist/esm/query-builder/over-builder.d.ts +2 -2
- package/dist/esm/query-builder/select-query-builder.d.ts +49 -31
- package/dist/esm/query-builder/select-query-builder.js +13 -11
- package/dist/esm/query-builder/update-query-builder.d.ts +23 -7
- package/dist/esm/query-builder/update-query-builder.js +5 -5
- package/dist/esm/query-builder/where-interface.d.ts +3 -3
- package/dist/esm/query-compiler/default-query-compiler.d.ts +9 -1
- package/dist/esm/query-compiler/default-query-compiler.js +73 -12
- package/dist/esm/raw-builder/raw-builder.d.ts +11 -1
- package/dist/esm/raw-builder/raw-builder.js +3 -0
- package/dist/esm/raw-builder/sql.js +9 -2
- package/dist/esm/schema/alter-table-add-index-builder.d.ts +104 -0
- package/dist/esm/schema/alter-table-add-index-builder.js +143 -0
- package/dist/esm/schema/alter-table-builder.d.ts +41 -1
- package/dist/esm/schema/alter-table-builder.js +59 -2
- package/dist/esm/schema/column-definition-builder.d.ts +25 -0
- package/dist/esm/schema/column-definition-builder.js +27 -0
- package/dist/esm/schema/create-index-builder.d.ts +23 -0
- package/dist/esm/schema/create-index-builder.js +30 -0
- package/dist/esm/schema/create-table-builder.d.ts +28 -2
- package/dist/esm/schema/create-table-builder.js +38 -3
- package/dist/esm/schema/unique-constraint-builder.d.ts +14 -0
- package/dist/esm/schema/unique-constraint-builder.js +21 -0
- package/dist/esm/util/log.js +5 -1
- package/dist/esm/util/object-utils.d.ts +2 -2
- package/dist/esm/util/object-utils.js +1 -1
- package/dist/esm/util/type-utils.d.ts +27 -19
- package/helpers/mssql.d.ts +1 -0
- package/helpers/mssql.js +1 -0
- package/package.json +15 -10
|
@@ -15,6 +15,8 @@ const unique_constraint_node_js_1 = require("../operation-node/unique-constraint
|
|
|
15
15
|
const check_constraint_node_js_1 = require("../operation-node/check-constraint-node.js");
|
|
16
16
|
const table_parser_js_1 = require("../parser/table-parser.js");
|
|
17
17
|
const on_commit_action_parse_js_1 = require("../parser/on-commit-action-parse.js");
|
|
18
|
+
const unique_constraint_builder_js_1 = require("./unique-constraint-builder.js");
|
|
19
|
+
const expression_parser_js_1 = require("../parser/expression-parser.js");
|
|
18
20
|
/**
|
|
19
21
|
* This builder can be used to create a `create table` query.
|
|
20
22
|
*/
|
|
@@ -86,7 +88,7 @@ class CreateTableBuilder {
|
|
|
86
88
|
* ```
|
|
87
89
|
*
|
|
88
90
|
* With this method, it's once again good to remember that Kysely just builds the
|
|
89
|
-
* query and doesn't provide the same API for all
|
|
91
|
+
* query and doesn't provide the same API for all databases. For example, some
|
|
90
92
|
* databases like older MySQL don't support the `references` statement in the
|
|
91
93
|
* column definition. Instead foreign key constraints need to be defined in the
|
|
92
94
|
* `create table` query. See the next example:
|
|
@@ -145,11 +147,17 @@ class CreateTableBuilder {
|
|
|
145
147
|
* ```ts
|
|
146
148
|
* addUniqueConstraint('first_name_last_name_unique', ['first_name', 'last_name'])
|
|
147
149
|
* ```
|
|
150
|
+
*
|
|
151
|
+
* In dialects such as PostgreSQL you can specify `nulls not distinct` as follows:
|
|
152
|
+
* ```ts
|
|
153
|
+
* addUniqueConstraint('first_name_last_name_unique', ['first_name', 'last_name'], (builder) => builder.nullsNotDistinct())
|
|
154
|
+
* ```
|
|
148
155
|
*/
|
|
149
|
-
addUniqueConstraint(constraintName, columns) {
|
|
156
|
+
addUniqueConstraint(constraintName, columns, build = object_utils_js_1.noop) {
|
|
157
|
+
const uniqueConstraintBuilder = build(new unique_constraint_builder_js_1.UniqueConstraintNodeBuilder(unique_constraint_node_js_1.UniqueConstraintNode.create(columns, constraintName)));
|
|
150
158
|
return new CreateTableBuilder({
|
|
151
159
|
...this.#props,
|
|
152
|
-
node: create_table_node_js_1.CreateTableNode.cloneWithConstraint(this.#props.node,
|
|
160
|
+
node: create_table_node_js_1.CreateTableNode.cloneWithConstraint(this.#props.node, uniqueConstraintBuilder.toOperationNode()),
|
|
153
161
|
});
|
|
154
162
|
}
|
|
155
163
|
/**
|
|
@@ -272,6 +280,33 @@ class CreateTableBuilder {
|
|
|
272
280
|
node: create_table_node_js_1.CreateTableNode.cloneWithEndModifier(this.#props.node, modifier.toOperationNode()),
|
|
273
281
|
});
|
|
274
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Allows to create table from `select` query.
|
|
285
|
+
*
|
|
286
|
+
* ### Examples
|
|
287
|
+
*
|
|
288
|
+
* ```ts
|
|
289
|
+
* db.schema.createTable('copy')
|
|
290
|
+
* .temporary()
|
|
291
|
+
* .as(db.selectFrom('person').select(['first_name', 'last_name']))
|
|
292
|
+
* .execute()
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* The generated SQL (PostgreSQL):
|
|
296
|
+
*
|
|
297
|
+
* ```sql
|
|
298
|
+
* create temporary table "copy" as
|
|
299
|
+
* select "first_name", "last_name" from "person"
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
as(expression) {
|
|
303
|
+
return new CreateTableBuilder({
|
|
304
|
+
...this.#props,
|
|
305
|
+
node: create_table_node_js_1.CreateTableNode.cloneWith(this.#props.node, {
|
|
306
|
+
selectQuery: (0, expression_parser_js_1.parseExpression)(expression),
|
|
307
|
+
}),
|
|
308
|
+
});
|
|
309
|
+
}
|
|
275
310
|
/**
|
|
276
311
|
* Calls the given function passing `this` as the only argument.
|
|
277
312
|
*
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
2
|
+
import { UniqueConstraintNode } from '../operation-node/unique-constraint-node.js';
|
|
3
|
+
export declare class UniqueConstraintNodeBuilder implements OperationNodeSource {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(node: UniqueConstraintNode);
|
|
6
|
+
toOperationNode(): UniqueConstraintNode;
|
|
7
|
+
/**
|
|
8
|
+
* Adds `nulls not distinct` to the unique constraint definition
|
|
9
|
+
*
|
|
10
|
+
* Supported by PostgreSQL dialect only
|
|
11
|
+
*/
|
|
12
|
+
nullsNotDistinct(): UniqueConstraintNodeBuilder;
|
|
13
|
+
}
|
|
14
|
+
export type UniqueConstraintNodeBuilderCallback = (builder: UniqueConstraintNodeBuilder) => UniqueConstraintNodeBuilder;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueConstraintNodeBuilder = void 0;
|
|
4
|
+
const unique_constraint_node_js_1 = require("../operation-node/unique-constraint-node.js");
|
|
5
|
+
const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
6
|
+
class UniqueConstraintNodeBuilder {
|
|
7
|
+
#node;
|
|
8
|
+
constructor(node) {
|
|
9
|
+
this.#node = node;
|
|
10
|
+
}
|
|
11
|
+
toOperationNode() {
|
|
12
|
+
return this.#node;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Adds `nulls not distinct` to the unique constraint definition
|
|
16
|
+
*
|
|
17
|
+
* Supported by PostgreSQL dialect only
|
|
18
|
+
*/
|
|
19
|
+
nullsNotDistinct() {
|
|
20
|
+
return new UniqueConstraintNodeBuilder(unique_constraint_node_js_1.UniqueConstraintNode.cloneWith(this.#node, { nullsNotDistinct: true }));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.UniqueConstraintNodeBuilder = UniqueConstraintNodeBuilder;
|
|
24
|
+
(0, prevent_await_js_1.preventAwait)(UniqueConstraintNodeBuilder, "don't await UniqueConstraintNodeBuilder instances directly.");
|
package/dist/cjs/util/log.js
CHANGED
|
@@ -47,7 +47,11 @@ function defaultLogger(event) {
|
|
|
47
47
|
console.error(`kysely:error: ${event.error.stack ?? event.error.message}`);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
console.error(`kysely:error: ${
|
|
50
|
+
console.error(`kysely:error: ${JSON.stringify({
|
|
51
|
+
error: event.error,
|
|
52
|
+
query: event.query.sql,
|
|
53
|
+
queryDurationMillis: event.queryDurationMillis,
|
|
54
|
+
})}`);
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -6,7 +6,7 @@ export declare function isNumber(obj: unknown): obj is number;
|
|
|
6
6
|
export declare function isBoolean(obj: unknown): obj is boolean;
|
|
7
7
|
export declare function isNull(obj: unknown): obj is null;
|
|
8
8
|
export declare function isDate(obj: unknown): obj is Date;
|
|
9
|
-
export declare function isBigInt(obj: unknown): obj is
|
|
9
|
+
export declare function isBigInt(obj: unknown): obj is bigint;
|
|
10
10
|
export declare function isBuffer(obj: unknown): obj is {
|
|
11
11
|
length: number;
|
|
12
12
|
};
|
|
@@ -16,7 +16,7 @@ export declare function isArrayBufferOrView(obj: unknown): obj is ArrayBuffer |
|
|
|
16
16
|
export declare function isPlainObject(obj: unknown): obj is Record<string, unknown>;
|
|
17
17
|
export declare function getLast<T>(arr: ArrayLike<T>): T | undefined;
|
|
18
18
|
export declare function freeze<T>(obj: T): Readonly<T>;
|
|
19
|
-
export declare function asArray<T>(arg: T | T
|
|
19
|
+
export declare function asArray<T>(arg: T | ReadonlyArray<T>): ReadonlyArray<T>;
|
|
20
20
|
export declare function asReadonlyArray<T>(arg: T | ReadonlyArray<T>): ReadonlyArray<T>;
|
|
21
21
|
export declare function isReadonlyArray(arg: unknown): arg is ReadonlyArray<unknown>;
|
|
22
22
|
export declare function noop<T>(obj: T): T;
|
|
@@ -33,19 +33,15 @@ import { KyselyTypeError } from './type-error.js';
|
|
|
33
33
|
* // Columns == 'id' | 'name' | 'species'
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export type AnyColumn<DB, TB extends keyof DB> =
|
|
37
|
-
DB
|
|
38
|
-
] extends [unknown] ? {
|
|
36
|
+
export type AnyColumn<DB, TB extends keyof DB> = {
|
|
39
37
|
[T in TB]: keyof DB[T];
|
|
40
|
-
}[TB] & string
|
|
38
|
+
}[TB] & string;
|
|
41
39
|
/**
|
|
42
40
|
* Extracts a column type.
|
|
43
41
|
*/
|
|
44
|
-
export type ExtractColumnType<DB, TB extends keyof DB, C> =
|
|
45
|
-
DB
|
|
46
|
-
] extends [unknown] ? {
|
|
42
|
+
export type ExtractColumnType<DB, TB extends keyof DB, C> = {
|
|
47
43
|
[T in TB]: C extends keyof DB[T] ? DB[T][C] : never;
|
|
48
|
-
}[TB]
|
|
44
|
+
}[TB];
|
|
49
45
|
/**
|
|
50
46
|
* Given a database type and a union of table names in that db, returns
|
|
51
47
|
* a union type with all possible `table`.`column` combinations.
|
|
@@ -77,21 +73,17 @@ export type ExtractColumnType<DB, TB extends keyof DB, C> = [
|
|
|
77
73
|
* // Columns == 'person.id' | 'pet.name' | 'pet.species'
|
|
78
74
|
* ```
|
|
79
75
|
*/
|
|
80
|
-
export type AnyColumnWithTable<DB, TB extends keyof DB> =
|
|
81
|
-
[T in TB]: T
|
|
82
|
-
}[TB]
|
|
76
|
+
export type AnyColumnWithTable<DB, TB extends keyof DB> = {
|
|
77
|
+
[T in TB]: `${T & string}.${keyof DB[T] & string}`;
|
|
78
|
+
}[TB];
|
|
83
79
|
/**
|
|
84
80
|
* Just like {@link AnyColumn} but with a ` as <string>` suffix.
|
|
85
81
|
*/
|
|
86
|
-
export type AnyAliasedColumn<DB, TB extends keyof DB> =
|
|
87
|
-
[T in TB]: T extends string ? keyof DB[T] extends string ? `${keyof DB[T]} as ${string}` : never : never;
|
|
88
|
-
}[TB]>;
|
|
82
|
+
export type AnyAliasedColumn<DB, TB extends keyof DB> = `${AnyColumn<DB, TB>} as ${string}`;
|
|
89
83
|
/**
|
|
90
84
|
* Just like {@link AnyColumnWithTable} but with a ` as <string>` suffix.
|
|
91
85
|
*/
|
|
92
|
-
export type AnyAliasedColumnWithTable<DB, TB extends keyof DB> =
|
|
93
|
-
[T in TB]: T extends string ? keyof DB[T] extends string ? `${T}.${keyof DB[T]} as ${string}` : never : never;
|
|
94
|
-
}[TB]>;
|
|
86
|
+
export type AnyAliasedColumnWithTable<DB, TB extends keyof DB> = `${AnyColumnWithTable<DB, TB>} as ${string}`;
|
|
95
87
|
/**
|
|
96
88
|
* Extracts the item type of an array.
|
|
97
89
|
*/
|
|
@@ -123,9 +115,25 @@ export type IsAny<T> = 0 extends T & 1 ? true : false;
|
|
|
123
115
|
* Evaluates to `true` if the types `T` and `U` are equal.
|
|
124
116
|
*/
|
|
125
117
|
export type Equals<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
|
|
126
|
-
export type NarrowPartial<
|
|
127
|
-
[K in keyof
|
|
118
|
+
export type NarrowPartial<O, T> = DrainOuterGeneric<T extends object ? {
|
|
119
|
+
[K in keyof O & string]: K extends keyof T ? T[K] extends NotNull ? Exclude<O[K], null> : T[K] extends O[K] ? T[K] : KyselyTypeError<`$narrowType() call failed: passed type does not exist in '${K}'s type union`> : O[K];
|
|
128
120
|
} : never>;
|
|
121
|
+
/**
|
|
122
|
+
* A type constant for marking a column as not null. Can be used with `$narrowPartial`.
|
|
123
|
+
*
|
|
124
|
+
* Example:
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* const person = await db.selectFrom('person')
|
|
128
|
+
* .where('nullable_column', 'is not', null)
|
|
129
|
+
* .selectAll()
|
|
130
|
+
* .$narrowType<{ nullable_column: NotNull }>()
|
|
131
|
+
* .executeTakeFirstOrThrow()
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export type NotNull = {
|
|
135
|
+
readonly __notNull__: unique symbol;
|
|
136
|
+
};
|
|
129
137
|
export type SqlBool = boolean | 0 | 1;
|
|
130
138
|
/**
|
|
131
139
|
* Utility to reduce depth of TypeScript's internal type instantiation stack.
|
|
@@ -7,6 +7,14 @@ import { DialectAdapter, MigrationLockOptions } from './dialect-adapter.js';
|
|
|
7
7
|
* they are added and there will be less breaking changes.
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class DialectAdapterBase implements DialectAdapter {
|
|
10
|
+
/**
|
|
11
|
+
* Whether or not this dialect supports `if not exists` in creation of tables/schemas/views/etc.
|
|
12
|
+
*
|
|
13
|
+
* If this is false, Kysely's internal migrations tables and schemas are created
|
|
14
|
+
* without `if not exists` in migrations. This is not a problem if the dialect
|
|
15
|
+
* supports transactional DDL.
|
|
16
|
+
*/
|
|
17
|
+
get supportsCreateIfNotExists(): boolean;
|
|
10
18
|
/**
|
|
11
19
|
* Whether or not this dialect supports transactional DDL.
|
|
12
20
|
*
|
|
@@ -8,6 +8,14 @@ import { Kysely } from '../kysely.js';
|
|
|
8
8
|
* it. For that there's a `supportsTransactionalDdl` boolean in this interface.
|
|
9
9
|
*/
|
|
10
10
|
export interface DialectAdapter {
|
|
11
|
+
/**
|
|
12
|
+
* Whether or not this dialect supports `if not exists` in creation of tables/schemas/views/etc.
|
|
13
|
+
*
|
|
14
|
+
* If this is false, Kysely's internal migrations tables and schemas are created
|
|
15
|
+
* without `if not exists` in migrations. This is not a problem if the dialect
|
|
16
|
+
* supports transactional DDL.
|
|
17
|
+
*/
|
|
18
|
+
readonly supportsCreateIfNotExists: boolean;
|
|
11
19
|
/**
|
|
12
20
|
* Whether or not this dialect supports transactional DDL.
|
|
13
21
|
*
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Kysely } from '../../kysely.js';
|
|
2
|
+
import { DialectAdapterBase } from '../dialect-adapter-base.js';
|
|
3
|
+
export declare class MssqlAdapter extends DialectAdapterBase {
|
|
4
|
+
/**
|
|
5
|
+
* Whether or not this dialect supports `if not exists` in creation of tables/schemas/views/etc.
|
|
6
|
+
*
|
|
7
|
+
* If this is false, Kysely's internal migrations tables and schemas are created
|
|
8
|
+
* without `if not exists` in migrations. This is not a problem if the dialect
|
|
9
|
+
* supports transactional DDL.
|
|
10
|
+
*/
|
|
11
|
+
get supportsCreateIfNotExists(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether or not this dialect supports transactional DDL.
|
|
14
|
+
*
|
|
15
|
+
* If this is true, migrations are executed inside a transaction.
|
|
16
|
+
*/
|
|
17
|
+
get supportsTransactionalDdl(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether or not this dialect supports the `returning` in inserts
|
|
20
|
+
* updates and deletes.
|
|
21
|
+
*/
|
|
22
|
+
get supportsReturning(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* This method is used to acquire a lock for the migrations so that
|
|
25
|
+
* it's not possible for two migration operations to run in parallel.
|
|
26
|
+
*
|
|
27
|
+
* Most dialects have explicit locks that can be used, like advisory locks
|
|
28
|
+
* in PostgreSQL and the get_lock function in MySQL.
|
|
29
|
+
*
|
|
30
|
+
* If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
|
|
31
|
+
* created by Kysely can be used instead. You can access it through the `options` object.
|
|
32
|
+
* The lock table has two columns `id` and `is_locked` and there's only one row in the table
|
|
33
|
+
* whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
|
|
34
|
+
* takes care of creating the lock table and inserting the one single row to it before this
|
|
35
|
+
* method is executed. If the dialect supports schemas and the user has specified a custom
|
|
36
|
+
* schema in their migration settings, the options object also contains the schema name in
|
|
37
|
+
* {@link MigrationLockOptions.lockTableSchema}.
|
|
38
|
+
*
|
|
39
|
+
* Here's an example of how you might implement this method for a dialect that doesn't
|
|
40
|
+
* have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* {
|
|
44
|
+
* async acquireMigrationLock(db, options): Promise<void> {
|
|
45
|
+
* const queryDb = options.lockTableSchema
|
|
46
|
+
* ? db.withSchema(options.lockTableSchema)
|
|
47
|
+
* : db
|
|
48
|
+
*
|
|
49
|
+
* // Since our imaginary dialect supports transactional DDL and has
|
|
50
|
+
* // row locks, we can simply take a row lock here and it will guarantee
|
|
51
|
+
* // all subsequent calls to this method from other transactions will
|
|
52
|
+
* // wait until this transaction finishes.
|
|
53
|
+
* await queryDb
|
|
54
|
+
* .selectFrom(options.lockTable)
|
|
55
|
+
* .selectAll()
|
|
56
|
+
* .where('id', '=', options.lockRowId)
|
|
57
|
+
* .forUpdate()
|
|
58
|
+
* .execute()
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
64
|
+
* is a transaction inside which the migrations will be executed. Otherwise
|
|
65
|
+
* `db` is a single connection (session) that will be used to execute the
|
|
66
|
+
* migrations.
|
|
67
|
+
*/
|
|
68
|
+
acquireMigrationLock(db: Kysely<any>): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Releases the migration lock. See {@link acquireMigrationLock}.
|
|
71
|
+
*
|
|
72
|
+
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
73
|
+
* is a transaction inside which the migrations were executed. Otherwise `db`
|
|
74
|
+
* is a single connection (session) that was used to execute the migrations
|
|
75
|
+
* and the `acquireMigrationLock` call.
|
|
76
|
+
*/
|
|
77
|
+
releaseMigrationLock(): Promise<void>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="./mssql-adapter.d.ts" />
|
|
2
|
+
import { DEFAULT_MIGRATION_TABLE } from '../../migration/migrator.js';
|
|
3
|
+
import { sql } from '../../raw-builder/sql.js';
|
|
4
|
+
import { DialectAdapterBase } from '../dialect-adapter-base.js';
|
|
5
|
+
export class MssqlAdapter extends DialectAdapterBase {
|
|
6
|
+
get supportsCreateIfNotExists() {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
get supportsTransactionalDdl() {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
get supportsReturning() {
|
|
13
|
+
// mssql should support returning with the `output` clause.
|
|
14
|
+
// we need to figure this out when we'll introduce support for it.
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
async acquireMigrationLock(db) {
|
|
18
|
+
// Acquire a transaction-level exclusive lock on the migrations table.
|
|
19
|
+
// https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-getapplock-transact-sql?view=sql-server-ver16
|
|
20
|
+
await sql `exec sp_getapplock @DbPrincipal = ${sql.lit('dbo')}, @Resource = ${sql.lit(DEFAULT_MIGRATION_TABLE)}, @LockMode = ${sql.lit('Exclusive')}`.execute(db);
|
|
21
|
+
}
|
|
22
|
+
async releaseMigrationLock() {
|
|
23
|
+
// Nothing to do here. `sp_getapplock` is automatically released at the
|
|
24
|
+
// end of the transaction and since `supportsTransactionalDdl` true, we know
|
|
25
|
+
// the `db` instance passed to acquireMigrationLock is actually a transaction.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export interface MssqlDialectConfig {
|
|
2
|
+
/**
|
|
3
|
+
* This dialect uses the `tarn` package to manage the connection pool to your
|
|
4
|
+
* database. To use it as a peer dependency and not bundle it with Kysely's code,
|
|
5
|
+
* you need to pass the `tarn` package itself. You also need to pass some pool options
|
|
6
|
+
* (excluding `create`, `destroy` and `validate` functions which are controlled by this dialect),
|
|
7
|
+
* `min` & `max` connections at the very least.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import * as Tarn from 'tarn'
|
|
13
|
+
*
|
|
14
|
+
* const dialect = new MssqlDialect({
|
|
15
|
+
* // ...
|
|
16
|
+
* tarn: {
|
|
17
|
+
* ...Tarn,
|
|
18
|
+
* options: {
|
|
19
|
+
* // ...
|
|
20
|
+
* min: 0,
|
|
21
|
+
* max: 10,
|
|
22
|
+
* },
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
tarn: Tarn;
|
|
28
|
+
/**
|
|
29
|
+
* This dialect uses the `tedious` package to communicate with your MS SQL Server
|
|
30
|
+
* database. To use it as a peer dependency and not bundle it with Kysely's code,
|
|
31
|
+
* you need to pass the `tedious` package itself. You also need to pass a factory
|
|
32
|
+
* function that creates new `tedious` `Connection` instances on demand.
|
|
33
|
+
*
|
|
34
|
+
* Example:
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* import * as Tedious from 'tedious'
|
|
38
|
+
*
|
|
39
|
+
* const dialect = new MssqlDialect({
|
|
40
|
+
* // ...
|
|
41
|
+
* tedious: {
|
|
42
|
+
* ...Tedious,
|
|
43
|
+
* connectionFactory: () => new Tedious.Connection({ ... }),
|
|
44
|
+
* },
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
tedious: Tedious;
|
|
49
|
+
}
|
|
50
|
+
export interface Tedious {
|
|
51
|
+
connectionFactory: () => TediousConnection | Promise<TediousConnection>;
|
|
52
|
+
ISOLATION_LEVEL: TediousIsolationLevel;
|
|
53
|
+
Request: typeof TediousRequest;
|
|
54
|
+
TYPES: TediousTypes;
|
|
55
|
+
}
|
|
56
|
+
export type TediousIsolationLevel = Record<'NO_CHANGE' | 'READ_UNCOMMITTED' | 'READ_COMMITTED' | 'REPEATABLE_READ' | 'SERIALIZABLE' | 'SNAPSHOT', number>;
|
|
57
|
+
export type TediousTypes = Record<'BigInt' | 'Binary' | 'Bit' | 'Char' | 'Date' | 'DateTime' | 'DateTime2' | 'DateTimeOffset' | 'Decimal' | 'Float' | 'Image' | 'Int' | 'Money' | 'NChar' | 'NText' | 'Null' | 'Numeric' | 'NVarChar' | 'Real' | 'SmallDateTime' | 'SmallInt' | 'SmallMoney' | 'Text' | 'Time' | 'TinyInt' | 'TVP' | 'UDT' | 'UniqueIdentifier' | 'VarBinary' | 'VarChar' | 'Xml', {
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
}>;
|
|
61
|
+
export interface TediousType {
|
|
62
|
+
name: string;
|
|
63
|
+
type: string;
|
|
64
|
+
}
|
|
65
|
+
export interface TediousConnection {
|
|
66
|
+
beginTransaction(callback: (error?: Error) => void, transactionId?: string | undefined, isolationLevel?: number | undefined): void;
|
|
67
|
+
cancel(): void;
|
|
68
|
+
close(): void;
|
|
69
|
+
commitTransaction(callback: (error?: Error) => void): void;
|
|
70
|
+
connect(callback: (error?: Error) => void): void;
|
|
71
|
+
execSql(request: TediousRequest): void;
|
|
72
|
+
reset(callback: (error?: Error) => void): void;
|
|
73
|
+
rollbackTransaction(callback: (error?: Error) => void): void;
|
|
74
|
+
once(event: 'end', listener: () => void): void;
|
|
75
|
+
}
|
|
76
|
+
export declare class TediousRequest {
|
|
77
|
+
constructor(sql: string, callback: (error: Error, rowCount: number, rows: any[]) => void);
|
|
78
|
+
addParameter(name: string, type: TediousType, value: any, options?: {
|
|
79
|
+
length?: number | 'max' | undefined;
|
|
80
|
+
precision?: number | undefined;
|
|
81
|
+
scale?: number | undefined;
|
|
82
|
+
}): void;
|
|
83
|
+
off(event: 'row', listener: (...args: any[]) => void): void;
|
|
84
|
+
on(event: 'row', listener: (columns: TediousColumnValue[]) => void): void;
|
|
85
|
+
once(event: 'requestCompleted', listener: (...args: any[]) => void): void;
|
|
86
|
+
}
|
|
87
|
+
export interface TediousColumnValue {
|
|
88
|
+
metadata: {
|
|
89
|
+
colName: string;
|
|
90
|
+
};
|
|
91
|
+
value: any;
|
|
92
|
+
}
|
|
93
|
+
export interface Tarn {
|
|
94
|
+
/**
|
|
95
|
+
* Tarn.js' pool options, excluding `create`, `destroy` and `validate` functions,
|
|
96
|
+
* which must be implemented by this dialect.
|
|
97
|
+
*/
|
|
98
|
+
options: Omit<TarnPoolOptions<any>, 'create' | 'destroy' | 'validate'>;
|
|
99
|
+
/**
|
|
100
|
+
* Tarn.js' Pool class.
|
|
101
|
+
*
|
|
102
|
+
* Example:
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { Pool } from 'tarn'
|
|
106
|
+
*
|
|
107
|
+
* const dialect = new MssqlDialect({
|
|
108
|
+
* // ...
|
|
109
|
+
* tarn: {
|
|
110
|
+
* // ...
|
|
111
|
+
* Pool,
|
|
112
|
+
* },
|
|
113
|
+
* })
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
Pool: typeof TarnPool;
|
|
117
|
+
}
|
|
118
|
+
export declare class TarnPool<R> {
|
|
119
|
+
constructor(opt: TarnPoolOptions<R>);
|
|
120
|
+
acquire(): TarnPendingRequest<R>;
|
|
121
|
+
destroy(): any;
|
|
122
|
+
release(resource: R): void;
|
|
123
|
+
}
|
|
124
|
+
export interface TarnPoolOptions<R> {
|
|
125
|
+
acquireTimeoutMillis?: number;
|
|
126
|
+
create(cb: (err: Error | null, resource: R) => void): any | (() => Promise<R>);
|
|
127
|
+
createRetryIntervalMillis?: number;
|
|
128
|
+
createTimeoutMillis?: number;
|
|
129
|
+
destroy(resource: R): any;
|
|
130
|
+
destroyTimeoutMillis?: number;
|
|
131
|
+
idleTimeoutMillis?: number;
|
|
132
|
+
log?(msg: string): any;
|
|
133
|
+
max: number;
|
|
134
|
+
min: number;
|
|
135
|
+
propagateCreateError?: boolean;
|
|
136
|
+
reapIntervalMillis?: number;
|
|
137
|
+
validate(resource: R): boolean;
|
|
138
|
+
}
|
|
139
|
+
export interface TarnPendingRequest<R> {
|
|
140
|
+
promise: Promise<R>;
|
|
141
|
+
resolve: (resource: R) => void;
|
|
142
|
+
reject: (err: Error) => void;
|
|
143
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Driver } from '../../driver/driver.js';
|
|
2
|
+
import { Kysely } from '../../kysely.js';
|
|
3
|
+
import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
4
|
+
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
5
|
+
import { DialectAdapter } from '../dialect-adapter.js';
|
|
6
|
+
import { Dialect } from '../dialect.js';
|
|
7
|
+
import { MssqlDialectConfig } from './mssql-dialect-config.js';
|
|
8
|
+
/**
|
|
9
|
+
* MS SQL Server dialect that uses the [tedious](https://tediousjs.github.io/tedious)
|
|
10
|
+
* library.
|
|
11
|
+
*
|
|
12
|
+
* The constructor takes an instance of {@link MssqlDialectConfig}.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import * as Tedious from 'tedious'
|
|
16
|
+
* import * as Tarn from 'tarn'
|
|
17
|
+
*
|
|
18
|
+
* const dialect = new MssqlDialect({
|
|
19
|
+
* tarn: {
|
|
20
|
+
* ...Tarn,
|
|
21
|
+
* options: {
|
|
22
|
+
* min: 0,
|
|
23
|
+
* max: 10,
|
|
24
|
+
* },
|
|
25
|
+
* },
|
|
26
|
+
* tedious: {
|
|
27
|
+
* ...Tedious,
|
|
28
|
+
* connectionFactory: () => new Tedious.Connection({
|
|
29
|
+
* authentication: {
|
|
30
|
+
* options: {
|
|
31
|
+
* password: 'password',
|
|
32
|
+
* userName: 'username',
|
|
33
|
+
* },
|
|
34
|
+
* type: 'default',
|
|
35
|
+
* },
|
|
36
|
+
* options: {
|
|
37
|
+
* database: 'some_db',
|
|
38
|
+
* port: 1433,
|
|
39
|
+
* trustServerCertificate: true,
|
|
40
|
+
* },
|
|
41
|
+
* server: 'localhost',
|
|
42
|
+
* }),
|
|
43
|
+
* },
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class MssqlDialect implements Dialect {
|
|
48
|
+
#private;
|
|
49
|
+
constructor(config: MssqlDialectConfig);
|
|
50
|
+
/**
|
|
51
|
+
* Creates a driver for the dialect.
|
|
52
|
+
*/
|
|
53
|
+
createDriver(): Driver;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a query compiler for the dialect.
|
|
56
|
+
*/
|
|
57
|
+
createQueryCompiler(): QueryCompiler;
|
|
58
|
+
/**
|
|
59
|
+
* Creates an adapter for the dialect.
|
|
60
|
+
*/
|
|
61
|
+
createAdapter(): DialectAdapter;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a database introspector that can be used to get database metadata
|
|
64
|
+
* such as the table names and column names of those tables.
|
|
65
|
+
*
|
|
66
|
+
* `db` never has any plugins installed. It's created using
|
|
67
|
+
* {@link Kysely.withoutPlugins}.
|
|
68
|
+
*/
|
|
69
|
+
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
70
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/// <reference types="./mssql-dialect.d.ts" />
|
|
2
|
+
import { MssqlAdapter } from './mssql-adapter.js';
|
|
3
|
+
import { MssqlDriver } from './mssql-driver.js';
|
|
4
|
+
import { MssqlIntrospector } from './mssql-introspector.js';
|
|
5
|
+
import { MssqlQueryCompiler } from './mssql-query-compiler.js';
|
|
6
|
+
/**
|
|
7
|
+
* MS SQL Server dialect that uses the [tedious](https://tediousjs.github.io/tedious)
|
|
8
|
+
* library.
|
|
9
|
+
*
|
|
10
|
+
* The constructor takes an instance of {@link MssqlDialectConfig}.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import * as Tedious from 'tedious'
|
|
14
|
+
* import * as Tarn from 'tarn'
|
|
15
|
+
*
|
|
16
|
+
* const dialect = new MssqlDialect({
|
|
17
|
+
* tarn: {
|
|
18
|
+
* ...Tarn,
|
|
19
|
+
* options: {
|
|
20
|
+
* min: 0,
|
|
21
|
+
* max: 10,
|
|
22
|
+
* },
|
|
23
|
+
* },
|
|
24
|
+
* tedious: {
|
|
25
|
+
* ...Tedious,
|
|
26
|
+
* connectionFactory: () => new Tedious.Connection({
|
|
27
|
+
* authentication: {
|
|
28
|
+
* options: {
|
|
29
|
+
* password: 'password',
|
|
30
|
+
* userName: 'username',
|
|
31
|
+
* },
|
|
32
|
+
* type: 'default',
|
|
33
|
+
* },
|
|
34
|
+
* options: {
|
|
35
|
+
* database: 'some_db',
|
|
36
|
+
* port: 1433,
|
|
37
|
+
* trustServerCertificate: true,
|
|
38
|
+
* },
|
|
39
|
+
* server: 'localhost',
|
|
40
|
+
* }),
|
|
41
|
+
* },
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export class MssqlDialect {
|
|
46
|
+
#config;
|
|
47
|
+
constructor(config) {
|
|
48
|
+
this.#config = config;
|
|
49
|
+
}
|
|
50
|
+
createDriver() {
|
|
51
|
+
return new MssqlDriver(this.#config);
|
|
52
|
+
}
|
|
53
|
+
createQueryCompiler() {
|
|
54
|
+
return new MssqlQueryCompiler();
|
|
55
|
+
}
|
|
56
|
+
createAdapter() {
|
|
57
|
+
return new MssqlAdapter();
|
|
58
|
+
}
|
|
59
|
+
createIntrospector(db) {
|
|
60
|
+
return new MssqlIntrospector(db);
|
|
61
|
+
}
|
|
62
|
+
}
|