kysely 0.28.2 → 0.28.4
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/mssql/mssql-driver.d.ts +3 -2
- package/dist/cjs/dialect/mssql/mssql-driver.js +68 -57
- package/dist/cjs/dialect/postgres/postgres-introspector.js +2 -0
- package/dist/cjs/helpers/mssql.d.ts +4 -4
- package/dist/cjs/helpers/mysql.d.ts +4 -4
- package/dist/cjs/helpers/postgres.d.ts +4 -4
- package/dist/cjs/helpers/sqlite.d.ts +4 -4
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/kysely.d.ts +4 -0
- package/dist/cjs/kysely.js +12 -6
- package/dist/cjs/migration/migrator.js +2 -1
- package/dist/cjs/parser/delete-from-parser.d.ts +5 -1
- package/dist/cjs/parser/merge-into-parser.d.ts +3 -1
- package/dist/cjs/parser/select-from-parser.d.ts +3 -1
- package/dist/cjs/parser/update-parser.d.ts +5 -1
- package/dist/cjs/query-builder/delete-query-builder.js +2 -2
- package/dist/cjs/query-builder/function-module.d.ts +6 -6
- package/dist/cjs/query-builder/insert-query-builder.js +2 -2
- package/dist/cjs/query-builder/merge-query-builder.js +1 -1
- package/dist/cjs/query-builder/select-query-builder.js +2 -2
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +1 -4
- package/dist/cjs/query-executor/query-executor-base.d.ts +2 -2
- package/dist/cjs/query-executor/query-executor-base.js +4 -4
- package/dist/cjs/query-executor/query-executor.d.ts +2 -2
- package/dist/cjs/raw-builder/raw-builder.js +1 -1
- package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.js +1 -1
- package/dist/cjs/schema/alter-table-add-index-builder.js +1 -1
- package/dist/cjs/schema/alter-table-builder.js +1 -1
- package/dist/cjs/schema/alter-table-drop-constraint-builder.js +1 -1
- package/dist/cjs/schema/alter-table-executor.js +1 -1
- package/dist/cjs/schema/create-index-builder.js +1 -1
- package/dist/cjs/schema/create-schema-builder.js +1 -1
- package/dist/cjs/schema/create-table-builder.js +1 -1
- package/dist/cjs/schema/create-type-builder.js +1 -1
- package/dist/cjs/schema/create-view-builder.js +1 -1
- package/dist/cjs/schema/drop-index-builder.js +1 -1
- package/dist/cjs/schema/drop-schema-builder.js +1 -1
- package/dist/cjs/schema/drop-table-builder.js +1 -1
- package/dist/cjs/schema/drop-type-builder.js +1 -1
- package/dist/cjs/schema/drop-view-builder.js +1 -1
- package/dist/cjs/schema/refresh-materialized-view-builder.js +1 -1
- package/dist/cjs/util/type-utils.d.ts +18 -0
- package/dist/esm/dialect/mssql/mssql-driver.d.ts +3 -2
- package/dist/esm/dialect/mssql/mssql-driver.js +68 -57
- package/dist/esm/dialect/postgres/postgres-introspector.js +2 -0
- package/dist/esm/helpers/mssql.d.ts +4 -4
- package/dist/esm/helpers/mysql.d.ts +4 -4
- package/dist/esm/helpers/postgres.d.ts +4 -4
- package/dist/esm/helpers/sqlite.d.ts +4 -4
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/kysely.d.ts +4 -0
- package/dist/esm/kysely.js +12 -6
- package/dist/esm/migration/migrator.js +3 -2
- package/dist/esm/parser/delete-from-parser.d.ts +5 -1
- package/dist/esm/parser/merge-into-parser.d.ts +3 -1
- package/dist/esm/parser/select-from-parser.d.ts +3 -1
- package/dist/esm/parser/update-parser.d.ts +5 -1
- package/dist/esm/query-builder/delete-query-builder.js +2 -2
- package/dist/esm/query-builder/function-module.d.ts +6 -6
- package/dist/esm/query-builder/insert-query-builder.js +2 -2
- package/dist/esm/query-builder/merge-query-builder.js +1 -1
- package/dist/esm/query-builder/select-query-builder.js +2 -2
- package/dist/esm/query-builder/update-query-builder.js +2 -2
- package/dist/esm/query-compiler/default-query-compiler.js +1 -4
- package/dist/esm/query-executor/query-executor-base.d.ts +2 -2
- package/dist/esm/query-executor/query-executor-base.js +4 -4
- package/dist/esm/query-executor/query-executor.d.ts +2 -2
- package/dist/esm/raw-builder/raw-builder.js +1 -1
- package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.js +1 -1
- package/dist/esm/schema/alter-table-add-index-builder.js +1 -1
- package/dist/esm/schema/alter-table-builder.js +1 -1
- package/dist/esm/schema/alter-table-drop-constraint-builder.js +1 -1
- package/dist/esm/schema/alter-table-executor.js +1 -1
- package/dist/esm/schema/create-index-builder.js +1 -1
- package/dist/esm/schema/create-schema-builder.js +1 -1
- package/dist/esm/schema/create-table-builder.js +1 -1
- package/dist/esm/schema/create-type-builder.js +1 -1
- package/dist/esm/schema/create-view-builder.js +1 -1
- package/dist/esm/schema/drop-index-builder.js +1 -1
- package/dist/esm/schema/drop-schema-builder.js +1 -1
- package/dist/esm/schema/drop-table-builder.js +1 -1
- package/dist/esm/schema/drop-type-builder.js +1 -1
- package/dist/esm/schema/drop-view-builder.js +1 -1
- package/dist/esm/schema/refresh-materialized-view-builder.js +1 -1
- package/dist/esm/util/type-utils.d.ts +18 -0
- package/package.json +57 -57
- package/.renovaterc.json +0 -3
- package/CODE_OF_CONDUCT.md +0 -183
- package/FUNDING.md +0 -25
- package/deno.check.d.ts +0 -96
- package/deno.check.json +0 -21
|
@@ -35,13 +35,13 @@ export declare abstract class QueryExecutorBase implements QueryExecutor {
|
|
|
35
35
|
* Executes a compiled query and runs the result through all plugins'
|
|
36
36
|
* `transformResult` method.
|
|
37
37
|
*/
|
|
38
|
-
executeQuery<R>(compiledQuery: CompiledQuery
|
|
38
|
+
executeQuery<R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>>;
|
|
39
39
|
/**
|
|
40
40
|
* Executes a compiled query and runs the result through all plugins'
|
|
41
41
|
* `transformResult` method. Results are streamead instead of loaded
|
|
42
42
|
* at once.
|
|
43
43
|
*/
|
|
44
|
-
stream<R>(compiledQuery: CompiledQuery, chunkSize: number
|
|
44
|
+
stream<R>(compiledQuery: CompiledQuery, chunkSize: number): AsyncIterableIterator<QueryResult<R>>;
|
|
45
45
|
/**
|
|
46
46
|
* Returns a copy of this executor with a new connection provider.
|
|
47
47
|
*/
|
|
@@ -32,20 +32,20 @@ class QueryExecutorBase {
|
|
|
32
32
|
}
|
|
33
33
|
return node;
|
|
34
34
|
}
|
|
35
|
-
async executeQuery(compiledQuery
|
|
35
|
+
async executeQuery(compiledQuery) {
|
|
36
36
|
return await this.provideConnection(async (connection) => {
|
|
37
37
|
const result = await connection.executeQuery(compiledQuery);
|
|
38
38
|
if ('numUpdatedOrDeletedRows' in result) {
|
|
39
39
|
(0, log_once_js_1.logOnce)('kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.');
|
|
40
40
|
}
|
|
41
|
-
return await this.#transformResult(result, queryId);
|
|
41
|
+
return await this.#transformResult(result, compiledQuery.queryId);
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
async *stream(compiledQuery, chunkSize
|
|
44
|
+
async *stream(compiledQuery, chunkSize) {
|
|
45
45
|
const { connection, release } = await (0, provide_controlled_connection_js_1.provideControlledConnection)(this);
|
|
46
46
|
try {
|
|
47
47
|
for await (const result of connection.streamQuery(compiledQuery, chunkSize)) {
|
|
48
|
-
yield await this.#transformResult(result, queryId);
|
|
48
|
+
yield await this.#transformResult(result, compiledQuery.queryId);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
finally {
|
|
@@ -36,7 +36,7 @@ export interface QueryExecutor extends ConnectionProvider {
|
|
|
36
36
|
* Executes a compiled query and runs the result through all plugins'
|
|
37
37
|
* `transformResult` method.
|
|
38
38
|
*/
|
|
39
|
-
executeQuery<R>(compiledQuery: CompiledQuery<R
|
|
39
|
+
executeQuery<R>(compiledQuery: CompiledQuery<R>): Promise<QueryResult<R>>;
|
|
40
40
|
/**
|
|
41
41
|
* Executes a compiled query and runs the result through all plugins'
|
|
42
42
|
* `transformResult` method. Results are streamead instead of loaded
|
|
@@ -47,7 +47,7 @@ export interface QueryExecutor extends ConnectionProvider {
|
|
|
47
47
|
* How many rows should be pulled from the database at once. Supported
|
|
48
48
|
* only by the postgres driver.
|
|
49
49
|
*/
|
|
50
|
-
chunkSize: number
|
|
50
|
+
chunkSize: number): AsyncIterableIterator<QueryResult<R>>;
|
|
51
51
|
/**
|
|
52
52
|
* Returns a copy of this executor with a new connection provider.
|
|
53
53
|
*/
|
|
@@ -42,7 +42,7 @@ class RawBuilderImpl {
|
|
|
42
42
|
}
|
|
43
43
|
async execute(executorProvider) {
|
|
44
44
|
const executor = this.#getExecutor(executorProvider);
|
|
45
|
-
return executor.executeQuery(this.#compile(executor)
|
|
45
|
+
return executor.executeQuery(this.#compile(executor));
|
|
46
46
|
}
|
|
47
47
|
#getExecutor(executorProvider) {
|
|
48
48
|
const executor = executorProvider !== undefined
|
|
@@ -61,7 +61,7 @@ class AlterTableAddForeignKeyConstraintBuilder {
|
|
|
61
61
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
62
62
|
}
|
|
63
63
|
async execute() {
|
|
64
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
64
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
exports.AlterTableAddForeignKeyConstraintBuilder = AlterTableAddForeignKeyConstraintBuilder;
|
|
@@ -159,7 +159,7 @@ class AlterTableAddIndexBuilder {
|
|
|
159
159
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
160
160
|
}
|
|
161
161
|
async execute() {
|
|
162
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
162
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
exports.AlterTableAddIndexBuilder = AlterTableAddIndexBuilder;
|
|
@@ -261,7 +261,7 @@ class AlterTableColumnAlteringBuilder {
|
|
|
261
261
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
262
262
|
}
|
|
263
263
|
async execute() {
|
|
264
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
264
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
exports.AlterTableColumnAlteringBuilder = AlterTableColumnAlteringBuilder;
|
|
@@ -53,7 +53,7 @@ class AlterTableDropConstraintBuilder {
|
|
|
53
53
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
54
54
|
}
|
|
55
55
|
async execute() {
|
|
56
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
56
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
exports.AlterTableDropConstraintBuilder = AlterTableDropConstraintBuilder;
|
|
@@ -14,7 +14,7 @@ class AlterTableExecutor {
|
|
|
14
14
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
15
15
|
}
|
|
16
16
|
async execute() {
|
|
17
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
17
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.AlterTableExecutor = AlterTableExecutor;
|
|
@@ -196,7 +196,7 @@ class CreateIndexBuilder {
|
|
|
196
196
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
197
197
|
}
|
|
198
198
|
async execute() {
|
|
199
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
199
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
exports.CreateIndexBuilder = CreateIndexBuilder;
|
|
@@ -28,7 +28,7 @@ class CreateSchemaBuilder {
|
|
|
28
28
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
29
29
|
}
|
|
30
30
|
async execute() {
|
|
31
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
31
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
exports.CreateSchemaBuilder = CreateSchemaBuilder;
|
|
@@ -405,7 +405,7 @@ class CreateTableBuilder {
|
|
|
405
405
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
406
406
|
}
|
|
407
407
|
async execute() {
|
|
408
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
408
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
exports.CreateTableBuilder = CreateTableBuilder;
|
|
@@ -37,7 +37,7 @@ class CreateTypeBuilder {
|
|
|
37
37
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
38
38
|
}
|
|
39
39
|
async execute() {
|
|
40
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
40
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
exports.CreateTypeBuilder = CreateTypeBuilder;
|
|
@@ -92,7 +92,7 @@ class CreateViewBuilder {
|
|
|
92
92
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
93
93
|
}
|
|
94
94
|
async execute() {
|
|
95
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
95
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
exports.CreateViewBuilder = CreateViewBuilder;
|
|
@@ -51,7 +51,7 @@ class DropIndexBuilder {
|
|
|
51
51
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
52
52
|
}
|
|
53
53
|
async execute() {
|
|
54
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
54
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
exports.DropIndexBuilder = DropIndexBuilder;
|
|
@@ -38,7 +38,7 @@ class DropSchemaBuilder {
|
|
|
38
38
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
39
39
|
}
|
|
40
40
|
async execute() {
|
|
41
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
41
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
exports.DropSchemaBuilder = DropSchemaBuilder;
|
|
@@ -38,7 +38,7 @@ class DropTableBuilder {
|
|
|
38
38
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
39
39
|
}
|
|
40
40
|
async execute() {
|
|
41
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
41
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
exports.DropTableBuilder = DropTableBuilder;
|
|
@@ -30,7 +30,7 @@ class DropTypeBuilder {
|
|
|
30
30
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
31
31
|
}
|
|
32
32
|
async execute() {
|
|
33
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
33
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
exports.DropTypeBuilder = DropTypeBuilder;
|
|
@@ -46,7 +46,7 @@ class DropViewBuilder {
|
|
|
46
46
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
47
47
|
}
|
|
48
48
|
async execute() {
|
|
49
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
49
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
exports.DropViewBuilder = DropViewBuilder;
|
|
@@ -69,7 +69,7 @@ class RefreshMaterializedViewBuilder {
|
|
|
69
69
|
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
|
70
70
|
}
|
|
71
71
|
async execute() {
|
|
72
|
-
await this.#props.executor.executeQuery(this.compile()
|
|
72
|
+
await this.#props.executor.executeQuery(this.compile());
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
exports.RefreshMaterializedViewBuilder = RefreshMaterializedViewBuilder;
|
|
@@ -169,3 +169,21 @@ export type DrainOuterGeneric<T> = [T] extends [unknown] ? T : never;
|
|
|
169
169
|
export type ShallowRecord<K extends keyof any, T> = DrainOuterGeneric<{
|
|
170
170
|
[P in K]: T;
|
|
171
171
|
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Dehydrates any root properties of an object that are not valid JSON types.
|
|
174
|
+
*
|
|
175
|
+
* For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`.
|
|
176
|
+
*/
|
|
177
|
+
export type ShallowDehydrateObject<O> = {
|
|
178
|
+
[K in keyof O]: ShallowDehydrateValue<O[K]>;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Dehydrates a value when it is not a valid JSON type.
|
|
182
|
+
*
|
|
183
|
+
* For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`,
|
|
184
|
+
* and anything in {@link NumbersWhenDataTypeNotAvailable} and convert it to `number`.
|
|
185
|
+
*/
|
|
186
|
+
export type ShallowDehydrateValue<T> = T extends null | undefined ? T : T extends (infer U)[] | null | undefined ? Array<ShallowDehydrateValue<U>> | Extract<T, null | undefined> : Exclude<T, StringsWhenDataTypeNotAvailable | NumbersWhenDataTypeNotAvailable> | ([Extract<T, NumbersWhenDataTypeNotAvailable>] extends [never] ? never : number) | ([Extract<T, StringsWhenDataTypeNotAvailable>] extends [never] ? never : string);
|
|
187
|
+
export type StringsWhenDataTypeNotAvailable = Date | Buffer | ArrayBuffer;
|
|
188
|
+
export type NumbersWhenDataTypeNotAvailable = bigint | NumericString;
|
|
189
|
+
export type NumericString = `${number}`;
|
|
@@ -4,6 +4,7 @@ import { MssqlDialectConfig, Tedious, TediousConnection } from './mssql-dialect-
|
|
|
4
4
|
import { CompiledQuery } from '../../query-compiler/compiled-query.js';
|
|
5
5
|
declare const PRIVATE_RESET_METHOD: unique symbol;
|
|
6
6
|
declare const PRIVATE_DESTROY_METHOD: unique symbol;
|
|
7
|
+
declare const PRIVATE_VALIDATE_METHOD: unique symbol;
|
|
7
8
|
export declare class MssqlDriver implements Driver {
|
|
8
9
|
#private;
|
|
9
10
|
constructor(config: MssqlDialectConfig);
|
|
@@ -51,8 +52,8 @@ declare class MssqlConnection implements DatabaseConnection {
|
|
|
51
52
|
rollbackTransaction(savepointName?: string): Promise<void>;
|
|
52
53
|
savepoint(savepointName: string): Promise<void>;
|
|
53
54
|
streamQuery<O>(compiledQuery: CompiledQuery, chunkSize: number): AsyncIterableIterator<QueryResult<O>>;
|
|
54
|
-
validate(): Promise<boolean>;
|
|
55
|
-
[PRIVATE_RESET_METHOD](): Promise<void>;
|
|
56
55
|
[PRIVATE_DESTROY_METHOD](): Promise<void>;
|
|
56
|
+
[PRIVATE_RESET_METHOD](): Promise<void>;
|
|
57
|
+
[PRIVATE_VALIDATE_METHOD](): Promise<boolean>;
|
|
57
58
|
}
|
|
58
59
|
export {};
|
|
@@ -6,6 +6,7 @@ import { randomString } from '../../util/random-string.js';
|
|
|
6
6
|
import { Deferred } from '../../util/deferred.js';
|
|
7
7
|
const PRIVATE_RESET_METHOD = Symbol();
|
|
8
8
|
const PRIVATE_DESTROY_METHOD = Symbol();
|
|
9
|
+
const PRIVATE_VALIDATE_METHOD = Symbol();
|
|
9
10
|
export class MssqlDriver {
|
|
10
11
|
#config;
|
|
11
12
|
#pool;
|
|
@@ -27,7 +28,7 @@ export class MssqlDriver {
|
|
|
27
28
|
validate: validateConnections === false ||
|
|
28
29
|
deprecatedValidateConnections === false
|
|
29
30
|
? undefined
|
|
30
|
-
: (connection) => connection
|
|
31
|
+
: (connection) => connection[PRIVATE_VALIDATE_METHOD](),
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
async init() {
|
|
@@ -64,14 +65,12 @@ export class MssqlDriver {
|
|
|
64
65
|
}
|
|
65
66
|
class MssqlConnection {
|
|
66
67
|
#connection;
|
|
68
|
+
#hasSocketError;
|
|
67
69
|
#tedious;
|
|
68
70
|
constructor(connection, tedious) {
|
|
69
71
|
this.#connection = connection;
|
|
72
|
+
this.#hasSocketError = false;
|
|
70
73
|
this.#tedious = tedious;
|
|
71
|
-
this.#connection.on('error', console.error);
|
|
72
|
-
this.#connection.once('end', () => {
|
|
73
|
-
this.#connection.off('error', console.error);
|
|
74
|
-
});
|
|
75
74
|
}
|
|
76
75
|
async beginTransaction(settings) {
|
|
77
76
|
const { isolationLevel } = settings;
|
|
@@ -93,17 +92,28 @@ class MssqlConnection {
|
|
|
93
92
|
}));
|
|
94
93
|
}
|
|
95
94
|
async connect() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
else {
|
|
103
|
-
resolve(undefined);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
95
|
+
const { promise: waitForConnected, reject, resolve } = new Deferred();
|
|
96
|
+
this.#connection.connect((error) => {
|
|
97
|
+
if (error) {
|
|
98
|
+
return reject(error);
|
|
99
|
+
}
|
|
100
|
+
resolve();
|
|
106
101
|
});
|
|
102
|
+
this.#connection.on('error', (error) => {
|
|
103
|
+
if (error instanceof Error &&
|
|
104
|
+
'code' in error &&
|
|
105
|
+
error.code === 'ESOCKET') {
|
|
106
|
+
this.#hasSocketError = true;
|
|
107
|
+
}
|
|
108
|
+
console.error(error);
|
|
109
|
+
reject(error);
|
|
110
|
+
});
|
|
111
|
+
function endListener() {
|
|
112
|
+
reject(new Error('The connection ended without ever completing the connection'));
|
|
113
|
+
}
|
|
114
|
+
this.#connection.once('end', endListener);
|
|
115
|
+
await waitForConnected;
|
|
116
|
+
this.#connection.off('end', endListener);
|
|
107
117
|
return this;
|
|
108
118
|
}
|
|
109
119
|
async executeQuery(compiledQuery) {
|
|
@@ -167,22 +177,6 @@ class MssqlConnection {
|
|
|
167
177
|
await this.#cancelRequest(request);
|
|
168
178
|
}
|
|
169
179
|
}
|
|
170
|
-
async validate() {
|
|
171
|
-
try {
|
|
172
|
-
const deferred = new Deferred();
|
|
173
|
-
const request = new MssqlRequest({
|
|
174
|
-
compiledQuery: CompiledQuery.raw('select 1'),
|
|
175
|
-
onDone: deferred,
|
|
176
|
-
tedious: this.#tedious,
|
|
177
|
-
});
|
|
178
|
-
this.#connection.execSql(request.request);
|
|
179
|
-
await deferred.promise;
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
catch {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
180
|
#getTediousIsolationLevel(isolationLevel) {
|
|
187
181
|
const { ISOLATION_LEVEL } = this.#tedious;
|
|
188
182
|
const mapper = {
|
|
@@ -204,27 +198,50 @@ class MssqlConnection {
|
|
|
204
198
|
const wasCanceled = this.#connection.cancel();
|
|
205
199
|
if (!wasCanceled) {
|
|
206
200
|
request.request.off('requestCompleted', resolve);
|
|
207
|
-
resolve(
|
|
201
|
+
resolve();
|
|
208
202
|
}
|
|
209
203
|
});
|
|
210
204
|
}
|
|
205
|
+
[PRIVATE_DESTROY_METHOD]() {
|
|
206
|
+
if ('closed' in this.#connection && this.#connection.closed) {
|
|
207
|
+
return Promise.resolve();
|
|
208
|
+
}
|
|
209
|
+
return new Promise((resolve) => {
|
|
210
|
+
this.#connection.once('end', resolve);
|
|
211
|
+
this.#connection.close();
|
|
212
|
+
});
|
|
213
|
+
}
|
|
211
214
|
async [PRIVATE_RESET_METHOD]() {
|
|
212
215
|
await new Promise((resolve, reject) => {
|
|
213
216
|
this.#connection.reset((error) => {
|
|
214
|
-
if (error)
|
|
215
|
-
reject(error);
|
|
216
|
-
|
|
217
|
-
|
|
217
|
+
if (error) {
|
|
218
|
+
return reject(error);
|
|
219
|
+
}
|
|
220
|
+
resolve();
|
|
218
221
|
});
|
|
219
222
|
});
|
|
220
223
|
}
|
|
221
|
-
[
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
224
|
+
async [PRIVATE_VALIDATE_METHOD]() {
|
|
225
|
+
if (this.#hasSocketError || this.#isConnectionClosed()) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
const deferred = new Deferred();
|
|
230
|
+
const request = new MssqlRequest({
|
|
231
|
+
compiledQuery: CompiledQuery.raw('select 1'),
|
|
232
|
+
onDone: deferred,
|
|
233
|
+
tedious: this.#tedious,
|
|
225
234
|
});
|
|
226
|
-
this.#connection.
|
|
227
|
-
|
|
235
|
+
this.#connection.execSql(request.request);
|
|
236
|
+
await deferred.promise;
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
#isConnectionClosed() {
|
|
244
|
+
return 'closed' in this.#connection && Boolean(this.#connection.closed);
|
|
228
245
|
}
|
|
229
246
|
}
|
|
230
247
|
class MssqlRequest {
|
|
@@ -248,23 +265,19 @@ class MssqlRequest {
|
|
|
248
265
|
}
|
|
249
266
|
delete this.#subscribers[subscriptionKey];
|
|
250
267
|
if (event === 'error') {
|
|
251
|
-
onDone.reject(error);
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
onDone.resolve({
|
|
255
|
-
rowCount: this.#rowCount,
|
|
256
|
-
rows: this.#rows,
|
|
257
|
-
});
|
|
268
|
+
return onDone.reject(error);
|
|
258
269
|
}
|
|
270
|
+
onDone.resolve({
|
|
271
|
+
rowCount: this.#rowCount,
|
|
272
|
+
rows: this.#rows,
|
|
273
|
+
});
|
|
259
274
|
};
|
|
260
275
|
}
|
|
261
276
|
this.#request = new this.#tedious.Request(compiledQuery.sql, (err, rowCount) => {
|
|
262
277
|
if (err) {
|
|
263
|
-
Object.values(this.#subscribers).forEach((subscriber) => subscriber('error', err instanceof AggregateError ? err.errors : err));
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
this.#rowCount = rowCount;
|
|
278
|
+
return Object.values(this.#subscribers).forEach((subscriber) => subscriber('error', err instanceof AggregateError ? err.errors : err));
|
|
267
279
|
}
|
|
280
|
+
this.#rowCount = rowCount;
|
|
268
281
|
});
|
|
269
282
|
this.#addParametersToRequest(compiledQuery.parameters);
|
|
270
283
|
this.#attachListeners();
|
|
@@ -278,11 +291,9 @@ class MssqlRequest {
|
|
|
278
291
|
this.#subscribers[subscriptionKey] = (event, error) => {
|
|
279
292
|
delete this.#subscribers[subscriptionKey];
|
|
280
293
|
if (event === 'error') {
|
|
281
|
-
reject(error);
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
resolve(this.#rows.splice(0, this.#streamChunkSize));
|
|
294
|
+
return reject(error);
|
|
285
295
|
}
|
|
296
|
+
resolve(this.#rows.splice(0, this.#streamChunkSize));
|
|
286
297
|
};
|
|
287
298
|
this.#request.resume();
|
|
288
299
|
});
|
|
@@ -46,6 +46,8 @@ export class PostgresIntrospector {
|
|
|
46
46
|
])
|
|
47
47
|
.where('ns.nspname', '!~', '^pg_')
|
|
48
48
|
.where('ns.nspname', '!=', 'information_schema')
|
|
49
|
+
// Filter out internal cockroachdb schema
|
|
50
|
+
.where('ns.nspname', '!=', 'crdb_internal')
|
|
49
51
|
// No system columns
|
|
50
52
|
.where('a.attnum', '>=', 0)
|
|
51
53
|
.where('a.attisdropped', '!=', true)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Expression } from '../expression/expression.js';
|
|
2
2
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
3
|
-
import { Simplify } from '../util/type-utils.js';
|
|
3
|
+
import { ShallowDehydrateObject, ShallowDehydrateValue, Simplify } from '../util/type-utils.js';
|
|
4
4
|
/**
|
|
5
5
|
* An MS SQL Server helper for aggregating a subquery into a JSON array.
|
|
6
6
|
*
|
|
@@ -73,7 +73,7 @@ import { Simplify } from '../util/type-utils.js';
|
|
|
73
73
|
* from "person"
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
|
-
export declare function jsonArrayFrom<O>(expr: Expression<O>): RawBuilder<Simplify<O
|
|
76
|
+
export declare function jsonArrayFrom<O>(expr: Expression<O>): RawBuilder<Simplify<ShallowDehydrateObject<O>>[]>;
|
|
77
77
|
/**
|
|
78
78
|
* An MS SQL Server helper for turning a subquery into a JSON object.
|
|
79
79
|
*
|
|
@@ -146,7 +146,7 @@ export declare function jsonArrayFrom<O>(expr: Expression<O>): RawBuilder<Simpli
|
|
|
146
146
|
* from "person"
|
|
147
147
|
* ```
|
|
148
148
|
*/
|
|
149
|
-
export declare function jsonObjectFrom<O>(expr: Expression<O>): RawBuilder<Simplify<O
|
|
149
|
+
export declare function jsonObjectFrom<O>(expr: Expression<O>): RawBuilder<Simplify<ShallowDehydrateObject<O>> | null>;
|
|
150
150
|
/**
|
|
151
151
|
* The MS SQL Server `json_query` function, single argument variant.
|
|
152
152
|
*
|
|
@@ -208,5 +208,5 @@ export declare function jsonObjectFrom<O>(expr: Expression<O>): RawBuilder<Simpl
|
|
|
208
208
|
* ```
|
|
209
209
|
*/
|
|
210
210
|
export declare function jsonBuildObject<O extends Record<string, Expression<unknown>>>(obj: O): RawBuilder<Simplify<{
|
|
211
|
-
[K in keyof O]: O[K] extends Expression<infer V> ? V : never;
|
|
211
|
+
[K in keyof O]: O[K] extends Expression<infer V> ? ShallowDehydrateValue<V> : never;
|
|
212
212
|
}>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Expression } from '../expression/expression.js';
|
|
2
2
|
import { SelectQueryBuilderExpression } from '../query-builder/select-query-builder-expression.js';
|
|
3
3
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
4
|
-
import { Simplify } from '../util/type-utils.js';
|
|
4
|
+
import { ShallowDehydrateObject, ShallowDehydrateValue, Simplify } from '../util/type-utils.js';
|
|
5
5
|
/**
|
|
6
6
|
* A MySQL helper for aggregating a subquery into a JSON array.
|
|
7
7
|
*
|
|
@@ -50,7 +50,7 @@ import { Simplify } from '../util/type-utils.js';
|
|
|
50
50
|
* from `person`
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
export declare function jsonArrayFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<O
|
|
53
|
+
export declare function jsonArrayFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<ShallowDehydrateObject<O>>[]>;
|
|
54
54
|
/**
|
|
55
55
|
* A MySQL helper for turning a subquery into a JSON object.
|
|
56
56
|
*
|
|
@@ -101,7 +101,7 @@ export declare function jsonArrayFrom<O>(expr: SelectQueryBuilderExpression<O>):
|
|
|
101
101
|
* from `person`
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
|
-
export declare function jsonObjectFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<O
|
|
104
|
+
export declare function jsonObjectFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<ShallowDehydrateObject<O>> | null>;
|
|
105
105
|
/**
|
|
106
106
|
* The MySQL `json_object` function.
|
|
107
107
|
*
|
|
@@ -143,5 +143,5 @@ export declare function jsonObjectFrom<O>(expr: SelectQueryBuilderExpression<O>)
|
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
145
|
export declare function jsonBuildObject<O extends Record<string, Expression<unknown>>>(obj: O): RawBuilder<Simplify<{
|
|
146
|
-
[K in keyof O]: O[K] extends Expression<infer V> ? V : never;
|
|
146
|
+
[K in keyof O]: O[K] extends Expression<infer V> ? ShallowDehydrateValue<V> : never;
|
|
147
147
|
}>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Expression } from '../expression/expression.js';
|
|
2
2
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
3
|
-
import { Simplify } from '../util/type-utils.js';
|
|
3
|
+
import { ShallowDehydrateValue, ShallowDehydrateObject, Simplify } from '../util/type-utils.js';
|
|
4
4
|
/**
|
|
5
5
|
* A postgres helper for aggregating a subquery (or other expression) into a JSONB array.
|
|
6
6
|
*
|
|
@@ -50,7 +50,7 @@ import { Simplify } from '../util/type-utils.js';
|
|
|
50
50
|
* from "person"
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
export declare function jsonArrayFrom<O>(expr: Expression<O>): RawBuilder<Simplify<O
|
|
53
|
+
export declare function jsonArrayFrom<O>(expr: Expression<O>): RawBuilder<Simplify<ShallowDehydrateObject<O>>[]>;
|
|
54
54
|
/**
|
|
55
55
|
* A postgres helper for turning a subquery (or other expression) into a JSON object.
|
|
56
56
|
*
|
|
@@ -102,7 +102,7 @@ export declare function jsonArrayFrom<O>(expr: Expression<O>): RawBuilder<Simpli
|
|
|
102
102
|
* from "person"
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
|
-
export declare function jsonObjectFrom<O>(expr: Expression<O>): RawBuilder<Simplify<O
|
|
105
|
+
export declare function jsonObjectFrom<O>(expr: Expression<O>): RawBuilder<Simplify<ShallowDehydrateObject<O>> | null>;
|
|
106
106
|
/**
|
|
107
107
|
* The PostgreSQL `json_build_object` function.
|
|
108
108
|
*
|
|
@@ -147,7 +147,7 @@ export declare function jsonObjectFrom<O>(expr: Expression<O>): RawBuilder<Simpl
|
|
|
147
147
|
* ```
|
|
148
148
|
*/
|
|
149
149
|
export declare function jsonBuildObject<O extends Record<string, Expression<unknown>>>(obj: O): RawBuilder<Simplify<{
|
|
150
|
-
[K in keyof O]: O[K] extends Expression<infer V> ? V : never;
|
|
150
|
+
[K in keyof O]: O[K] extends Expression<infer V> ? ShallowDehydrateValue<V> : never;
|
|
151
151
|
}>>;
|
|
152
152
|
export type MergeAction = 'INSERT' | 'UPDATE' | 'DELETE';
|
|
153
153
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Expression } from '../expression/expression.js';
|
|
2
2
|
import { SelectQueryBuilderExpression } from '../query-builder/select-query-builder-expression.js';
|
|
3
3
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
4
|
-
import { Simplify } from '../util/type-utils.js';
|
|
4
|
+
import { ShallowDehydrateObject, ShallowDehydrateValue, Simplify } from '../util/type-utils.js';
|
|
5
5
|
/**
|
|
6
6
|
* A SQLite helper for aggregating a subquery into a JSON array.
|
|
7
7
|
*
|
|
@@ -63,7 +63,7 @@ import { Simplify } from '../util/type-utils.js';
|
|
|
63
63
|
* from "person"
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
export declare function jsonArrayFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<O
|
|
66
|
+
export declare function jsonArrayFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<ShallowDehydrateObject<O>>[]>;
|
|
67
67
|
/**
|
|
68
68
|
* A SQLite helper for turning a subquery into a JSON object.
|
|
69
69
|
*
|
|
@@ -127,7 +127,7 @@ export declare function jsonArrayFrom<O>(expr: SelectQueryBuilderExpression<O>):
|
|
|
127
127
|
* from "person";
|
|
128
128
|
* ```
|
|
129
129
|
*/
|
|
130
|
-
export declare function jsonObjectFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<O
|
|
130
|
+
export declare function jsonObjectFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<ShallowDehydrateObject<O>> | null>;
|
|
131
131
|
/**
|
|
132
132
|
* The SQLite `json_object` function.
|
|
133
133
|
*
|
|
@@ -185,5 +185,5 @@ export declare function jsonObjectFrom<O>(expr: SelectQueryBuilderExpression<O>)
|
|
|
185
185
|
* ```
|
|
186
186
|
*/
|
|
187
187
|
export declare function jsonBuildObject<O extends Record<string, Expression<unknown>>>(obj: O): RawBuilder<Simplify<{
|
|
188
|
-
[K in keyof O]: O[K] extends Expression<infer V> ? V : never;
|
|
188
|
+
[K in keyof O]: O[K] extends Expression<infer V> ? ShallowDehydrateValue<V> : never;
|
|
189
189
|
}>>;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -204,7 +204,7 @@ export * from './util/compilable.js';
|
|
|
204
204
|
export * from './util/explainable.js';
|
|
205
205
|
export * from './util/streamable.js';
|
|
206
206
|
export * from './util/log.js';
|
|
207
|
-
export { AnyAliasedColumn, AnyAliasedColumnWithTable, AnyColumn, AnyColumnWithTable, Equals, UnknownRow, Simplify, SqlBool, Nullable, NotNull, } from './util/type-utils.js';
|
|
207
|
+
export { AnyAliasedColumn, AnyAliasedColumnWithTable, AnyColumn, AnyColumnWithTable, Equals, UnknownRow, Simplify, SqlBool, Nullable, NumbersWhenDataTypeNotAvailable, NotNull, NumericString, ShallowDehydrateObject, ShallowDehydrateValue, StringsWhenDataTypeNotAvailable, } from './util/type-utils.js';
|
|
208
208
|
export * from './util/infer-result.js';
|
|
209
209
|
export { logOnce } from './util/log-once.js';
|
|
210
210
|
export { createQueryId, QueryId } from './util/query-id.js';
|
package/dist/esm/kysely.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ import { Expression } from './expression/expression.js';
|
|
|
18
18
|
import { DrainOuterGeneric } from './util/type-utils.js';
|
|
19
19
|
import { ReleaseSavepoint, RollbackToSavepoint } from './parser/savepoint-parser.js';
|
|
20
20
|
import { ControlledConnection } from './util/provide-controlled-connection.js';
|
|
21
|
+
declare global {
|
|
22
|
+
interface AsyncDisposable {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
21
25
|
/**
|
|
22
26
|
* The main Kysely class.
|
|
23
27
|
*
|