kysely 0.26.2 → 0.27.0
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/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 +97 -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 -73
- package/dist/cjs/expression/expression-builder.js +8 -17
- package/dist/cjs/expression/expression-wrapper.d.ts +8 -8
- package/dist/cjs/helpers/mssql.d.ts +152 -0
- package/dist/cjs/helpers/mssql.js +160 -0
- package/dist/cjs/helpers/mysql.d.ts +3 -3
- package/dist/cjs/helpers/sqlite.d.ts +3 -3
- package/dist/cjs/index.d.ts +8 -2
- 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/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +17 -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/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/expression-parser.d.ts +2 -2
- package/dist/cjs/parser/reference-parser.d.ts +3 -2
- package/dist/cjs/parser/returning-parser.d.ts +2 -1
- package/dist/cjs/parser/select-parser.d.ts +20 -9
- package/dist/cjs/parser/update-set-parser.d.ts +5 -2
- package/dist/cjs/parser/update-set-parser.js +13 -3
- package/dist/cjs/parser/value-parser.d.ts +2 -2
- package/dist/cjs/query-builder/aggregate-function-builder.d.ts +4 -4
- package/dist/cjs/query-builder/case-builder.d.ts +5 -4
- package/dist/cjs/query-builder/delete-query-builder.d.ts +8 -6
- package/dist/cjs/query-builder/function-module.d.ts +98 -27
- 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 +32 -12
- package/dist/cjs/query-builder/insert-query-builder.js +3 -3
- 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 +3 -2
- package/dist/cjs/query-builder/json-path-builder.js +6 -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/returning-interface.d.ts +3 -2
- package/dist/cjs/query-builder/select-query-builder-expression.d.ts +20 -0
- package/dist/cjs/query-builder/select-query-builder-expression.js +2 -0
- package/dist/cjs/query-builder/select-query-builder.d.ts +48 -29
- package/dist/cjs/query-builder/select-query-builder.js +5 -2
- package/dist/cjs/query-builder/update-query-builder.d.ts +25 -7
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- 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 +65 -12
- package/dist/cjs/query-creator.d.ts +5 -3
- package/dist/cjs/query-creator.js +0 -47
- package/dist/cjs/raw-builder/raw-builder.d.ts +0 -3
- 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/create-view-builder.d.ts +2 -2
- 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/infer-result.d.ts +2 -1
- package/dist/cjs/util/log.js +5 -1
- package/dist/cjs/util/object-utils.d.ts +1 -1
- package/dist/cjs/util/type-utils.d.ts +27 -20
- 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 +94 -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 -73
- package/dist/esm/expression/expression-builder.js +10 -19
- package/dist/esm/expression/expression-wrapper.d.ts +8 -8
- package/dist/esm/helpers/mssql.d.ts +152 -0
- package/dist/esm/helpers/mssql.js +155 -0
- package/dist/esm/helpers/mysql.d.ts +3 -3
- package/dist/esm/helpers/sqlite.d.ts +3 -3
- package/dist/esm/index.d.ts +8 -2
- 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/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +17 -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/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/expression-parser.d.ts +2 -2
- package/dist/esm/parser/reference-parser.d.ts +3 -2
- package/dist/esm/parser/returning-parser.d.ts +2 -1
- package/dist/esm/parser/select-parser.d.ts +20 -9
- package/dist/esm/parser/update-set-parser.d.ts +5 -2
- package/dist/esm/parser/update-set-parser.js +10 -1
- package/dist/esm/parser/value-parser.d.ts +2 -2
- package/dist/esm/query-builder/aggregate-function-builder.d.ts +4 -4
- package/dist/esm/query-builder/case-builder.d.ts +5 -4
- package/dist/esm/query-builder/delete-query-builder.d.ts +8 -6
- package/dist/esm/query-builder/function-module.d.ts +98 -27
- 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 +32 -12
- package/dist/esm/query-builder/insert-query-builder.js +4 -4
- 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 +3 -2
- package/dist/esm/query-builder/json-path-builder.js +6 -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/returning-interface.d.ts +3 -2
- package/dist/esm/query-builder/select-query-builder-expression.d.ts +20 -0
- package/dist/esm/query-builder/select-query-builder-expression.js +2 -0
- package/dist/esm/query-builder/select-query-builder.d.ts +48 -29
- package/dist/esm/query-builder/select-query-builder.js +5 -2
- package/dist/esm/query-builder/update-query-builder.d.ts +25 -7
- package/dist/esm/query-builder/update-query-builder.js +3 -3
- 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 +65 -12
- package/dist/esm/query-creator.d.ts +5 -3
- package/dist/esm/query-creator.js +0 -47
- package/dist/esm/raw-builder/raw-builder.d.ts +0 -3
- 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/create-view-builder.d.ts +2 -2
- 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/infer-result.d.ts +2 -1
- package/dist/esm/util/log.js +5 -1
- package/dist/esm/util/object-utils.d.ts +1 -1
- package/dist/esm/util/type-utils.d.ts +27 -20
- package/helpers/mssql.d.ts +1 -0
- package/helpers/mssql.js +1 -0
- package/package.json +17 -6
|
@@ -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,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MssqlAdapter = void 0;
|
|
4
|
+
const migrator_js_1 = require("../../migration/migrator.js");
|
|
5
|
+
const sql_js_1 = require("../../raw-builder/sql.js");
|
|
6
|
+
const dialect_adapter_base_js_1 = require("../dialect-adapter-base.js");
|
|
7
|
+
class MssqlAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
|
|
8
|
+
get supportsCreateIfNotExists() {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
get supportsTransactionalDdl() {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
get supportsReturning() {
|
|
15
|
+
// mssql should support returning with the `output` clause.
|
|
16
|
+
// we need to figure this out when we'll introduce support for it.
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
async acquireMigrationLock(db) {
|
|
20
|
+
// Acquire a transaction-level exclusive lock on the migrations table.
|
|
21
|
+
// https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-getapplock-transact-sql?view=sql-server-ver16
|
|
22
|
+
await (0, sql_js_1.sql) `exec sp_getapplock @DbPrincipal = ${sql_js_1.sql.lit('dbo')}, @Resource = ${sql_js_1.sql.lit(migrator_js_1.DEFAULT_MIGRATION_TABLE)}, @LockMode = ${sql_js_1.sql.lit('Exclusive')}`.execute(db);
|
|
23
|
+
}
|
|
24
|
+
async releaseMigrationLock() {
|
|
25
|
+
// Nothing to do here. `sp_getapplock` is automatically released at the
|
|
26
|
+
// end of the transaction and since `supportsTransactionalDdl` true, we know
|
|
27
|
+
// the `db` instance passed to acquireMigrationLock is actually a transaction.
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.MssqlAdapter = MssqlAdapter;
|
|
@@ -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,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MssqlDialect = void 0;
|
|
4
|
+
const mssql_adapter_js_1 = require("./mssql-adapter.js");
|
|
5
|
+
const mssql_driver_js_1 = require("./mssql-driver.js");
|
|
6
|
+
const mssql_introspector_js_1 = require("./mssql-introspector.js");
|
|
7
|
+
const mssql_query_compiler_js_1 = require("./mssql-query-compiler.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
|
+
class MssqlDialect {
|
|
48
|
+
#config;
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.#config = config;
|
|
51
|
+
}
|
|
52
|
+
createDriver() {
|
|
53
|
+
return new mssql_driver_js_1.MssqlDriver(this.#config);
|
|
54
|
+
}
|
|
55
|
+
createQueryCompiler() {
|
|
56
|
+
return new mssql_query_compiler_js_1.MssqlQueryCompiler();
|
|
57
|
+
}
|
|
58
|
+
createAdapter() {
|
|
59
|
+
return new mssql_adapter_js_1.MssqlAdapter();
|
|
60
|
+
}
|
|
61
|
+
createIntrospector(db) {
|
|
62
|
+
return new mssql_introspector_js_1.MssqlIntrospector(db);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MssqlDialect = MssqlDialect;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DatabaseConnection, QueryResult } from '../../driver/database-connection.js';
|
|
2
|
+
import { Driver, TransactionSettings } from '../../driver/driver.js';
|
|
3
|
+
import { MssqlDialectConfig, Tedious, TediousConnection } from './mssql-dialect-config.js';
|
|
4
|
+
import { CompiledQuery } from '../../query-compiler/compiled-query.js';
|
|
5
|
+
declare const PRIVATE_RELEASE_METHOD: unique symbol;
|
|
6
|
+
declare const PRIVATE_DESTROY_METHOD: unique symbol;
|
|
7
|
+
export declare class MssqlDriver implements Driver {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(config: MssqlDialectConfig);
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the driver.
|
|
12
|
+
*
|
|
13
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
14
|
+
* methods should be callable.
|
|
15
|
+
*/
|
|
16
|
+
init(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Acquires a new connection from the pool.
|
|
19
|
+
*/
|
|
20
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
21
|
+
/**
|
|
22
|
+
* Begins a transaction.
|
|
23
|
+
*/
|
|
24
|
+
beginTransaction(connection: MssqlConnection, settings: TransactionSettings): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Commits a transaction.
|
|
27
|
+
*/
|
|
28
|
+
commitTransaction(connection: MssqlConnection): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Rolls back a transaction.
|
|
31
|
+
*/
|
|
32
|
+
rollbackTransaction(connection: MssqlConnection): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Releases a connection back to the pool.
|
|
35
|
+
*/
|
|
36
|
+
releaseConnection(connection: MssqlConnection): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Destroys the driver and releases all resources.
|
|
39
|
+
*/
|
|
40
|
+
destroy(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
declare class MssqlConnection implements DatabaseConnection {
|
|
43
|
+
#private;
|
|
44
|
+
constructor(connection: TediousConnection, tedious: Tedious);
|
|
45
|
+
beginTransaction(settings: TransactionSettings): Promise<void>;
|
|
46
|
+
commitTransaction(): Promise<void>;
|
|
47
|
+
executeQuery<O>(compiledQuery: CompiledQuery): Promise<QueryResult<O>>;
|
|
48
|
+
rollbackTransaction(): Promise<void>;
|
|
49
|
+
streamQuery<O>(compiledQuery: CompiledQuery, chunkSize: number): AsyncIterableIterator<QueryResult<O>>;
|
|
50
|
+
validate(): Promise<boolean>;
|
|
51
|
+
[PRIVATE_RELEASE_METHOD](): Promise<void>;
|
|
52
|
+
[PRIVATE_DESTROY_METHOD](): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export {};
|