kysely 0.16.4 → 0.16.8
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 +118 -5
- package/dist/cjs/dialect/mysql/mysql-dialect.js +2 -1
- package/dist/cjs/dialect/mysql/mysql-driver.js +1 -1
- package/dist/cjs/dialect/postgres/postgres-dialect.js +2 -1
- package/dist/cjs/dialect/postgres/postgres-driver.js +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-dialect.js +2 -1
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +1 -1
- package/dist/cjs/driver/dummy-driver.d.ts +68 -0
- package/dist/cjs/driver/dummy-driver.js +62 -0
- package/dist/cjs/driver/runtime-driver.d.ts +1 -1
- package/dist/cjs/driver/runtime-driver.js +30 -33
- package/dist/cjs/index-nodeless.d.ts +2 -0
- package/dist/cjs/index-nodeless.js +2 -0
- package/dist/cjs/kysely.d.ts +8 -6
- package/dist/cjs/kysely.js +8 -6
- package/dist/cjs/migration/migrator.d.ts +2 -2
- package/dist/cjs/operation-node/primitive-value-list-node.d.ts +2 -3
- package/dist/cjs/operation-node/value-node.d.ts +3 -4
- package/dist/cjs/parser/complex-expression-parser.d.ts +1 -0
- package/dist/cjs/parser/complex-expression-parser.js +5 -1
- package/dist/cjs/parser/default-value-parser.d.ts +2 -3
- package/dist/cjs/parser/default-value-parser.js +2 -2
- package/dist/cjs/parser/insert-values-parser.js +4 -3
- package/dist/cjs/parser/reference-parser.d.ts +2 -3
- package/dist/cjs/parser/value-parser.d.ts +2 -3
- package/dist/cjs/parser/value-parser.js +6 -7
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.js +19 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.js +42 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +51 -9
- package/dist/cjs/query-builder/delete-query-builder.js +56 -8
- package/dist/cjs/query-builder/expression-builder.d.ts +1 -1
- package/dist/cjs/query-builder/expression-builder.js +2 -2
- package/dist/cjs/query-builder/function-builder.d.ts +29 -5
- package/dist/cjs/query-builder/function-builder.js +31 -7
- package/dist/cjs/query-builder/insert-query-builder.d.ts +53 -11
- package/dist/cjs/query-builder/insert-query-builder.js +58 -10
- package/dist/cjs/query-builder/select-query-builder.d.ts +58 -16
- package/dist/cjs/query-builder/select-query-builder.js +64 -15
- package/dist/cjs/query-builder/update-query-builder.d.ts +52 -9
- package/dist/cjs/query-builder/update-query-builder.js +57 -8
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +1 -2
- package/dist/cjs/query-creator.d.ts +2 -2
- package/dist/cjs/query-creator.js +2 -2
- package/dist/cjs/query-executor/query-executor.js +3 -2
- package/dist/cjs/raw-builder/raw-builder.d.ts +2 -2
- package/dist/cjs/raw-builder/raw-builder.js +8 -1
- package/dist/cjs/schema/alter-table-builder.d.ts +30 -4
- package/dist/cjs/schema/alter-table-builder.js +2 -5
- package/dist/cjs/schema/column-definition-builder.d.ts +27 -2
- package/dist/cjs/schema/create-view-builder.js +1 -1
- package/dist/cjs/util/log.d.ts +1 -0
- package/dist/cjs/util/log.js +3 -0
- package/dist/cjs/util/object-utils.d.ts +5 -5
- package/dist/cjs/util/object-utils.js +52 -11
- package/dist/cjs/util/type-utils.d.ts +21 -0
- package/dist/esm/dialect/mysql/mysql-dialect.js +2 -1
- package/dist/esm/dialect/mysql/mysql-driver.js +2 -2
- package/dist/esm/dialect/postgres/postgres-dialect.js +2 -1
- package/dist/esm/dialect/postgres/postgres-driver.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-dialect.js +2 -1
- package/dist/esm/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/esm/driver/dummy-driver.d.ts +68 -0
- package/dist/esm/driver/dummy-driver.js +59 -0
- package/dist/esm/driver/runtime-driver.d.ts +1 -1
- package/dist/esm/driver/runtime-driver.js +29 -32
- package/dist/esm/index-nodeless.d.ts +2 -0
- package/dist/esm/index-nodeless.js +2 -0
- package/dist/esm/kysely.d.ts +8 -6
- package/dist/esm/kysely.js +8 -6
- package/dist/esm/migration/migrator.d.ts +2 -2
- package/dist/esm/operation-node/primitive-value-list-node.d.ts +2 -3
- package/dist/esm/operation-node/value-node.d.ts +3 -4
- package/dist/esm/parser/complex-expression-parser.d.ts +1 -0
- package/dist/esm/parser/complex-expression-parser.js +3 -0
- package/dist/esm/parser/default-value-parser.d.ts +2 -3
- package/dist/esm/parser/default-value-parser.js +2 -2
- package/dist/esm/parser/insert-values-parser.js +5 -4
- package/dist/esm/parser/reference-parser.d.ts +2 -3
- package/dist/esm/parser/reference-parser.js +1 -1
- package/dist/esm/parser/value-parser.d.ts +2 -3
- package/dist/esm/parser/value-parser.js +8 -9
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.js +16 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.js +39 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +51 -9
- package/dist/esm/query-builder/delete-query-builder.js +56 -8
- package/dist/esm/query-builder/expression-builder.d.ts +1 -1
- package/dist/esm/query-builder/expression-builder.js +1 -1
- package/dist/esm/query-builder/function-builder.d.ts +29 -5
- package/dist/esm/query-builder/function-builder.js +31 -7
- package/dist/esm/query-builder/insert-query-builder.d.ts +53 -11
- package/dist/esm/query-builder/insert-query-builder.js +58 -10
- package/dist/esm/query-builder/select-query-builder.d.ts +58 -16
- package/dist/esm/query-builder/select-query-builder.js +64 -15
- package/dist/esm/query-builder/update-query-builder.d.ts +52 -9
- package/dist/esm/query-builder/update-query-builder.js +57 -8
- package/dist/esm/query-compiler/default-query-compiler.d.ts +1 -2
- package/dist/esm/query-creator.d.ts +2 -2
- package/dist/esm/query-creator.js +2 -2
- package/dist/esm/query-executor/query-executor.js +3 -2
- package/dist/esm/raw-builder/raw-builder.d.ts +2 -2
- package/dist/esm/raw-builder/raw-builder.js +8 -1
- package/dist/esm/schema/alter-table-builder.d.ts +30 -4
- package/dist/esm/schema/alter-table-builder.js +2 -5
- package/dist/esm/schema/column-definition-builder.d.ts +27 -2
- package/dist/esm/schema/create-view-builder.js +1 -1
- package/dist/esm/util/log.d.ts +1 -0
- package/dist/esm/util/log.js +3 -0
- package/dist/esm/util/object-utils.d.ts +5 -5
- package/dist/esm/util/object-utils.js +50 -9
- package/dist/esm/util/type-utils.d.ts +21 -0
- package/package.json +11 -5
|
@@ -7,11 +7,18 @@ const raw_node_js_1 = require("../operation-node/raw-node.js");
|
|
|
7
7
|
const value_node_js_1 = require("../operation-node/value-node.js");
|
|
8
8
|
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
|
9
9
|
const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
10
|
+
const query_id_js_1 = require("../util/query-id.js");
|
|
10
11
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
12
|
+
const noop_query_executor_js_1 = require("../query-executor/noop-query-executor.js");
|
|
11
13
|
class RawBuilder {
|
|
12
14
|
#props;
|
|
13
15
|
constructor(props) {
|
|
14
|
-
this.#props = (0, object_utils_js_1.freeze)(
|
|
16
|
+
this.#props = (0, object_utils_js_1.freeze)({
|
|
17
|
+
queryId: props.queryId ?? (0, query_id_js_1.createQueryId)(),
|
|
18
|
+
executor: props.executor ?? new noop_query_executor_js_1.NoopQueryExecutor(),
|
|
19
|
+
sql: props.sql,
|
|
20
|
+
parameters: props.parameters,
|
|
21
|
+
});
|
|
15
22
|
}
|
|
16
23
|
as(alias) {
|
|
17
24
|
return new AliasedRawBuilder(this, alias);
|
|
@@ -5,13 +5,13 @@ import { OperationNodeSource } from '../operation-node/operation-node-source.js'
|
|
|
5
5
|
import { OnModifyForeignAction } from '../operation-node/references-node.js';
|
|
6
6
|
import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
7
7
|
import { Compilable } from '../util/compilable.js';
|
|
8
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
9
8
|
import { ColumnDefinitionBuilder, ColumnDefinitionBuilderInterface } from './column-definition-builder.js';
|
|
10
9
|
import { AnyRawBuilder } from '../util/type-utils.js';
|
|
11
10
|
import { QueryId } from '../util/query-id.js';
|
|
12
11
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
13
12
|
import { DataTypeExpression } from '../parser/data-type-parser.js';
|
|
14
13
|
import { ForeignKeyConstraintBuilder, ForeignKeyConstraintBuilderInterface } from './foreign-key-constraint-builder.js';
|
|
14
|
+
import { DefaultValueExpression } from '../parser/default-value-parser.js';
|
|
15
15
|
/**
|
|
16
16
|
* This builder can be used to create a `alter table` query.
|
|
17
17
|
*/
|
|
@@ -43,7 +43,7 @@ export declare class AlterColumnBuilder {
|
|
|
43
43
|
#private;
|
|
44
44
|
constructor(props: AlterColumnBuilderProps);
|
|
45
45
|
setDataType(dataType: ColumnDataType): AlterTableExecutor;
|
|
46
|
-
setDefault(value:
|
|
46
|
+
setDefault(value: DefaultValueExpression): AlterTableExecutor;
|
|
47
47
|
dropDefault(): AlterTableExecutor;
|
|
48
48
|
setNotNull(): AlterTableExecutor;
|
|
49
49
|
dropNotNull(): AlterTableExecutor;
|
|
@@ -141,8 +141,21 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
141
141
|
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
|
142
142
|
* .execute()
|
|
143
143
|
* ```
|
|
144
|
+
*
|
|
145
|
+
* Raw expressions are also supported:
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* db.schema
|
|
149
|
+
* .createTable('pet')
|
|
150
|
+
* .addColumn(
|
|
151
|
+
* 'number_of_legs',
|
|
152
|
+
* 'integer',
|
|
153
|
+
* (col) => col.defaultTo(db.raw('any SQL here'))
|
|
154
|
+
* )
|
|
155
|
+
* .execute()
|
|
156
|
+
* ```
|
|
144
157
|
*/
|
|
145
|
-
defaultTo(value:
|
|
158
|
+
defaultTo(value: DefaultValueExpression): AlterTableAddColumnBuilder;
|
|
146
159
|
/**
|
|
147
160
|
* Adds a check constraint for the column.
|
|
148
161
|
*
|
|
@@ -286,8 +299,21 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
|
|
|
286
299
|
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
|
287
300
|
* .execute()
|
|
288
301
|
* ```
|
|
302
|
+
*
|
|
303
|
+
* Raw expressions are also supported:
|
|
304
|
+
*
|
|
305
|
+
* ```ts
|
|
306
|
+
* db.schema
|
|
307
|
+
* .createTable('pet')
|
|
308
|
+
* .addColumn(
|
|
309
|
+
* 'number_of_legs',
|
|
310
|
+
* 'integer',
|
|
311
|
+
* (col) => col.defaultTo(db.raw('any SQL here'))
|
|
312
|
+
* )
|
|
313
|
+
* .execute()
|
|
314
|
+
* ```
|
|
289
315
|
*/
|
|
290
|
-
defaultTo(value:
|
|
316
|
+
defaultTo(value: DefaultValueExpression): AlterTableModifyColumnBuilder;
|
|
291
317
|
/**
|
|
292
318
|
* Adds a check constraint for the column.
|
|
293
319
|
*
|
|
@@ -8,10 +8,8 @@ const column_definition_node_js_1 = require("../operation-node/column-definition
|
|
|
8
8
|
const data_type_node_js_1 = require("../operation-node/data-type-node.js");
|
|
9
9
|
const drop_column_node_js_1 = require("../operation-node/drop-column-node.js");
|
|
10
10
|
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
|
11
|
-
const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
|
|
12
11
|
const rename_column_node_js_1 = require("../operation-node/rename-column-node.js");
|
|
13
12
|
const table_node_js_1 = require("../operation-node/table-node.js");
|
|
14
|
-
const value_node_js_1 = require("../operation-node/value-node.js");
|
|
15
13
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
16
14
|
const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
17
15
|
const column_definition_builder_js_1 = require("./column-definition-builder.js");
|
|
@@ -23,6 +21,7 @@ const unique_constraint_node_js_1 = require("../operation-node/unique-constraint
|
|
|
23
21
|
const check_constraint_node_js_1 = require("../operation-node/check-constraint-node.js");
|
|
24
22
|
const foreign_key_constraint_node_js_1 = require("../operation-node/foreign-key-constraint-node.js");
|
|
25
23
|
const column_node_js_1 = require("../operation-node/column-node.js");
|
|
24
|
+
const default_value_parser_js_1 = require("../parser/default-value-parser.js");
|
|
26
25
|
/**
|
|
27
26
|
* This builder can be used to create a `alter table` query.
|
|
28
27
|
*/
|
|
@@ -130,9 +129,7 @@ class AlterColumnBuilder {
|
|
|
130
129
|
...this.#props,
|
|
131
130
|
alterTableNode: alter_table_node_js_1.AlterTableNode.cloneWith(this.#props.alterTableNode, {
|
|
132
131
|
alterColumn: alter_column_node_js_1.AlterColumnNode.cloneWith(this.#props.alterColumnNode, {
|
|
133
|
-
setDefault: (0,
|
|
134
|
-
? value.toOperationNode()
|
|
135
|
-
: value_node_js_1.ValueNode.createImmediate(value),
|
|
132
|
+
setDefault: (0, default_value_parser_js_1.parseDefaultValueExpression)(value),
|
|
136
133
|
}),
|
|
137
134
|
}),
|
|
138
135
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
2
2
|
import { OnModifyForeignAction } from '../operation-node/references-node.js';
|
|
3
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
4
3
|
import { ColumnDefinitionNode } from '../operation-node/column-definition-node.js';
|
|
5
4
|
import { AnyRawBuilder } from '../util/type-utils.js';
|
|
6
5
|
import { DefaultValueExpression } from '../parser/default-value-parser.js';
|
|
@@ -83,8 +82,21 @@ export interface ColumnDefinitionBuilderInterface {
|
|
|
83
82
|
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
|
84
83
|
* .execute()
|
|
85
84
|
* ```
|
|
85
|
+
*
|
|
86
|
+
* Raw expressions are also supported:
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* db.schema
|
|
90
|
+
* .createTable('pet')
|
|
91
|
+
* .addColumn(
|
|
92
|
+
* 'number_of_legs',
|
|
93
|
+
* 'integer',
|
|
94
|
+
* (col) => col.defaultTo(db.raw('any SQL here'))
|
|
95
|
+
* )
|
|
96
|
+
* .execute()
|
|
97
|
+
* ```
|
|
86
98
|
*/
|
|
87
|
-
defaultTo(value:
|
|
99
|
+
defaultTo(value: DefaultValueExpression): ColumnDefinitionBuilderInterface;
|
|
88
100
|
/**
|
|
89
101
|
* Adds a check constraint for the column.
|
|
90
102
|
*
|
|
@@ -222,6 +234,19 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
|
|
|
222
234
|
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
|
223
235
|
* .execute()
|
|
224
236
|
* ```
|
|
237
|
+
*
|
|
238
|
+
* Raw expressions are also supported:
|
|
239
|
+
*
|
|
240
|
+
* ```ts
|
|
241
|
+
* db.schema
|
|
242
|
+
* .createTable('pet')
|
|
243
|
+
* .addColumn(
|
|
244
|
+
* 'number_of_legs',
|
|
245
|
+
* 'integer',
|
|
246
|
+
* (col) => col.defaultTo(db.raw('any SQL here'))
|
|
247
|
+
* )
|
|
248
|
+
* .execute()
|
|
249
|
+
* ```
|
|
225
250
|
*/
|
|
226
251
|
defaultTo(value: DefaultValueExpression): ColumnDefinitionBuilder;
|
|
227
252
|
/**
|
|
@@ -5,7 +5,7 @@ const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
|
5
5
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
6
6
|
const create_view_node_js_1 = require("../operation-node/create-view-node.js");
|
|
7
7
|
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
|
8
|
-
const immediate_value_plugin_js_1 = require("../plugin/immediate-value
|
|
8
|
+
const immediate_value_plugin_js_1 = require("../plugin/immediate-value/immediate-value-plugin.js");
|
|
9
9
|
class CreateViewBuilder {
|
|
10
10
|
#props;
|
|
11
11
|
constructor(props) {
|
package/dist/cjs/util/log.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare type LogConfig = ReadonlyArray<LogLevel> | Logger;
|
|
|
17
17
|
export declare class Log {
|
|
18
18
|
#private;
|
|
19
19
|
constructor(config: LogConfig);
|
|
20
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
20
21
|
query(getEvent: () => QueryLogEvent): void;
|
|
21
22
|
error(getEvent: () => ErrorLogEvent): void;
|
|
22
23
|
}
|
package/dist/cjs/util/log.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
export declare type PrimitiveValue = string | number | boolean | null | Date | Buffer | BigInt;
|
|
3
|
-
export declare function isEmpty(obj: ArrayLike<unknown> | string | object | Buffer): boolean;
|
|
1
|
+
export declare function isEmpty(obj: ArrayLike<unknown> | string | object): boolean;
|
|
4
2
|
export declare function isString(obj: unknown): obj is string;
|
|
5
3
|
export declare function isNumber(obj: unknown): obj is number;
|
|
6
4
|
export declare function isBoolean(obj: unknown): obj is boolean;
|
|
7
5
|
export declare function isNull(obj: unknown): obj is null;
|
|
8
6
|
export declare function isDate(obj: unknown): obj is Date;
|
|
9
7
|
export declare function isBigInt(obj: unknown): obj is BigInt;
|
|
10
|
-
export declare function isBuffer(obj: unknown): obj is
|
|
11
|
-
|
|
8
|
+
export declare function isBuffer(obj: unknown): obj is {
|
|
9
|
+
length: number;
|
|
10
|
+
};
|
|
12
11
|
export declare function isFunction(obj: unknown): obj is Function;
|
|
13
12
|
export declare function isObject(obj: unknown): obj is Record<string, unknown>;
|
|
14
13
|
export declare function getLast<T>(arr: ArrayLike<T>): T | undefined;
|
|
@@ -17,3 +16,4 @@ export declare function asArray<T>(arg: T | T[]): T[];
|
|
|
17
16
|
export declare function asReadonlyArray<T>(arg: T | ReadonlyArray<T>): ReadonlyArray<T>;
|
|
18
17
|
export declare function isReadonlyArray(arg: unknown): arg is ReadonlyArray<unknown>;
|
|
19
18
|
export declare function noop<T>(obj: T): T;
|
|
19
|
+
export declare function compare(obj1: unknown, obj2: unknown): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noop = exports.isReadonlyArray = exports.asReadonlyArray = exports.asArray = exports.freeze = exports.getLast = exports.isObject = exports.isFunction = exports.
|
|
3
|
+
exports.compare = exports.noop = exports.isReadonlyArray = exports.asReadonlyArray = exports.asArray = exports.freeze = exports.getLast = exports.isObject = exports.isFunction = exports.isBuffer = exports.isBigInt = exports.isDate = exports.isNull = exports.isBoolean = exports.isNumber = exports.isString = exports.isEmpty = void 0;
|
|
4
4
|
function isEmpty(obj) {
|
|
5
5
|
if (Array.isArray(obj) || isString(obj) || isBuffer(obj)) {
|
|
6
6
|
return obj.length === 0;
|
|
@@ -35,20 +35,12 @@ function isBigInt(obj) {
|
|
|
35
35
|
return typeof obj === 'bigint';
|
|
36
36
|
}
|
|
37
37
|
exports.isBigInt = isBigInt;
|
|
38
|
+
// Don't change the returnd type to `obj is Buffer` to not create a
|
|
39
|
+
// hard dependency to node.
|
|
38
40
|
function isBuffer(obj) {
|
|
39
41
|
return typeof Buffer !== 'undefined' && Buffer.isBuffer(obj);
|
|
40
42
|
}
|
|
41
43
|
exports.isBuffer = isBuffer;
|
|
42
|
-
function isPrimitive(obj) {
|
|
43
|
-
return (isString(obj) ||
|
|
44
|
-
isNumber(obj) ||
|
|
45
|
-
isBoolean(obj) ||
|
|
46
|
-
isNull(obj) ||
|
|
47
|
-
isDate(obj) ||
|
|
48
|
-
isBigInt(obj) ||
|
|
49
|
-
isBuffer(obj));
|
|
50
|
-
}
|
|
51
|
-
exports.isPrimitive = isPrimitive;
|
|
52
44
|
function isFunction(obj) {
|
|
53
45
|
return typeof obj === 'function';
|
|
54
46
|
}
|
|
@@ -91,3 +83,52 @@ function noop(obj) {
|
|
|
91
83
|
return obj;
|
|
92
84
|
}
|
|
93
85
|
exports.noop = noop;
|
|
86
|
+
function compare(obj1, obj2) {
|
|
87
|
+
if (isReadonlyArray(obj1) && isReadonlyArray(obj2)) {
|
|
88
|
+
return compareArrays(obj1, obj2);
|
|
89
|
+
}
|
|
90
|
+
else if (isObject(obj1) && isObject(obj2)) {
|
|
91
|
+
return compareObjects(obj1, obj2);
|
|
92
|
+
}
|
|
93
|
+
return obj1 === obj2;
|
|
94
|
+
}
|
|
95
|
+
exports.compare = compare;
|
|
96
|
+
function compareArrays(arr1, arr2) {
|
|
97
|
+
if (arr1.length !== arr2.length) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
for (let i = 0; i < arr1.length; ++i) {
|
|
101
|
+
if (!compare(arr1[i], arr2[i])) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
function compareObjects(obj1, obj2) {
|
|
108
|
+
if (isBuffer(obj1) && isBuffer(obj2)) {
|
|
109
|
+
return compareBuffers(obj1, obj2);
|
|
110
|
+
}
|
|
111
|
+
else if (isDate(obj1) && isDate(obj2)) {
|
|
112
|
+
return compareDates(obj1, obj2);
|
|
113
|
+
}
|
|
114
|
+
return compareGenericObjects(obj1, obj2);
|
|
115
|
+
}
|
|
116
|
+
function compareBuffers(buf1, buf2) {
|
|
117
|
+
return Buffer.compare(buf1, buf2) === 0;
|
|
118
|
+
}
|
|
119
|
+
function compareDates(date1, date2) {
|
|
120
|
+
return date1.getTime() === date2.getTime();
|
|
121
|
+
}
|
|
122
|
+
function compareGenericObjects(obj1, obj2) {
|
|
123
|
+
const keys1 = Object.keys(obj1);
|
|
124
|
+
const keys2 = Object.keys(obj2);
|
|
125
|
+
if (keys1.length !== keys2.length) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
for (const key of keys1) {
|
|
129
|
+
if (!compare(obj1[key], obj2[key])) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
@@ -111,3 +111,24 @@ export declare type UnknownRow = Record<string, unknown>;
|
|
|
111
111
|
export declare type Nullable<T> = {
|
|
112
112
|
[P in keyof T]: T[P] | null;
|
|
113
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Takes all properties from T1 and merges all properties from T2
|
|
116
|
+
* that don't exist in T1 as optional properties.
|
|
117
|
+
*
|
|
118
|
+
* Example:
|
|
119
|
+
*
|
|
120
|
+
* interface Person {
|
|
121
|
+
* name: string
|
|
122
|
+
* age: number
|
|
123
|
+
* }
|
|
124
|
+
*
|
|
125
|
+
* interface Pet {
|
|
126
|
+
* name: string
|
|
127
|
+
* species: 'cat' | 'dog'
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* type Merged = MergePartial<Person, Pet>
|
|
131
|
+
*
|
|
132
|
+
* // { name: string, age: number, species?: 'cat' | 'dog' }
|
|
133
|
+
*/
|
|
134
|
+
export declare type MergePartial<T1, T2> = T1 & Partial<Omit<T2, keyof T1>>;
|
|
@@ -3,6 +3,7 @@ import { MysqlDriver } from './mysql-driver.js';
|
|
|
3
3
|
import { MysqlQueryCompiler } from './mysql-query-compiler.js';
|
|
4
4
|
import { MysqlIntrospector } from './mysql-introspector.js';
|
|
5
5
|
import { MysqlAdapter } from './mysql-adapter.js';
|
|
6
|
+
import { freeze } from '../../util/object-utils.js';
|
|
6
7
|
/**
|
|
7
8
|
* MySQL dialect that uses the [mysql2](https://github.com/sidorares/node-mysql2#readme) library.
|
|
8
9
|
*
|
|
@@ -13,7 +14,7 @@ import { MysqlAdapter } from './mysql-adapter.js';
|
|
|
13
14
|
export class MysqlDialect {
|
|
14
15
|
#config;
|
|
15
16
|
constructor(config) {
|
|
16
|
-
this.#config = config;
|
|
17
|
+
this.#config = freeze({ ...config });
|
|
17
18
|
}
|
|
18
19
|
createDriver() {
|
|
19
20
|
return new MysqlDriver(this.#config);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="./mysql-driver.d.ts" />
|
|
2
2
|
import { CompiledQuery } from '../../query-compiler/compiled-query.js';
|
|
3
|
-
import { isFunction, isObject } from '../../util/object-utils.js';
|
|
3
|
+
import { isFunction, isObject, freeze } from '../../util/object-utils.js';
|
|
4
4
|
const PRIVATE_RELEASE_METHOD = Symbol();
|
|
5
5
|
export class MysqlDriver {
|
|
6
6
|
#config;
|
|
7
7
|
#connections = new WeakMap();
|
|
8
8
|
#pool;
|
|
9
9
|
constructor(config) {
|
|
10
|
-
this.#config = config;
|
|
10
|
+
this.#config = freeze({ ...config });
|
|
11
11
|
}
|
|
12
12
|
async init() {
|
|
13
13
|
// Import the `mysql2` module here instead at the top of the file
|
|
@@ -3,6 +3,7 @@ import { PostgresDriver } from './postgres-driver.js';
|
|
|
3
3
|
import { PostgresIntrospector } from './postgres-introspector.js';
|
|
4
4
|
import { PostgresQueryCompiler } from './postgres-query-compiler.js';
|
|
5
5
|
import { PostgresAdapter } from './postgres-adapter.js';
|
|
6
|
+
import { freeze } from '../../util/object-utils.js';
|
|
6
7
|
/**
|
|
7
8
|
* PostgreSQL dialect that uses the [pg](https://node-postgres.com/) library.
|
|
8
9
|
*
|
|
@@ -16,7 +17,7 @@ import { PostgresAdapter } from './postgres-adapter.js';
|
|
|
16
17
|
export class PostgresDialect {
|
|
17
18
|
#config;
|
|
18
19
|
constructor(config) {
|
|
19
|
-
this.#config = config;
|
|
20
|
+
this.#config = freeze({ ...config });
|
|
20
21
|
}
|
|
21
22
|
createDriver() {
|
|
22
23
|
return new PostgresDriver(this.#config);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="./postgres-driver.d.ts" />
|
|
2
2
|
import { CompiledQuery } from '../../query-compiler/compiled-query.js';
|
|
3
|
-
import { isFunction } from '../../util/object-utils.js';
|
|
3
|
+
import { isFunction, freeze } from '../../util/object-utils.js';
|
|
4
4
|
const PRIVATE_RELEASE_METHOD = Symbol();
|
|
5
5
|
export class PostgresDriver {
|
|
6
6
|
#config;
|
|
7
7
|
#connections = new WeakMap();
|
|
8
8
|
#pool = null;
|
|
9
9
|
constructor(config) {
|
|
10
|
-
this.#config = config;
|
|
10
|
+
this.#config = freeze({ ...config });
|
|
11
11
|
}
|
|
12
12
|
async init() {
|
|
13
13
|
// Import the `pg` module here instead at the top of the file
|
|
@@ -3,6 +3,7 @@ import { SqliteDriver } from './sqlite-driver.js';
|
|
|
3
3
|
import { SqliteQueryCompiler } from './sqlite-query-compiler.js';
|
|
4
4
|
import { SqliteIntrospector } from './sqlite-introspector.js';
|
|
5
5
|
import { SqliteAdapter } from './sqlite-adapter.js';
|
|
6
|
+
import { freeze } from '../../util/object-utils.js';
|
|
6
7
|
/**
|
|
7
8
|
* SQLite dialect that uses the [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) library.
|
|
8
9
|
*
|
|
@@ -13,7 +14,7 @@ import { SqliteAdapter } from './sqlite-adapter.js';
|
|
|
13
14
|
export class SqliteDialect {
|
|
14
15
|
#config;
|
|
15
16
|
constructor(config) {
|
|
16
|
-
this.#config = config;
|
|
17
|
+
this.#config = freeze({ ...config });
|
|
17
18
|
}
|
|
18
19
|
createDriver() {
|
|
19
20
|
return new SqliteDriver(this.#config);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="./sqlite-driver.d.ts" />
|
|
2
2
|
import { CompiledQuery } from '../../query-compiler/compiled-query.js';
|
|
3
|
-
import { isBoolean, isFunction, isNumber } from '../../util/object-utils.js';
|
|
3
|
+
import { freeze, isBoolean, isFunction, isNumber, } from '../../util/object-utils.js';
|
|
4
4
|
export class SqliteDriver {
|
|
5
5
|
#config;
|
|
6
6
|
#connectionMutex = new ConnectionMutex();
|
|
7
7
|
#db;
|
|
8
8
|
#connection;
|
|
9
9
|
constructor(config) {
|
|
10
|
-
this.#config = config;
|
|
10
|
+
this.#config = freeze({ ...config });
|
|
11
11
|
}
|
|
12
12
|
async init() {
|
|
13
13
|
// Import the `better-sqlite3` module here instead at the top of the file
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DatabaseConnection } from './database-connection.js';
|
|
2
|
+
import { Driver } from './driver.js';
|
|
3
|
+
/**
|
|
4
|
+
* A driver that does absolutely nothing.
|
|
5
|
+
*
|
|
6
|
+
* You can use this to create Kysely instances solely for building queries
|
|
7
|
+
*
|
|
8
|
+
* ### Examples
|
|
9
|
+
*
|
|
10
|
+
* This example creates a Kysely instance for building postgres queries:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const db = new Kysely<Database>({
|
|
14
|
+
* dialect: {
|
|
15
|
+
* createAdapter() {
|
|
16
|
+
* return new PostgresAdapter()
|
|
17
|
+
* },
|
|
18
|
+
* createDriver() {
|
|
19
|
+
* return new DummyDriver()
|
|
20
|
+
* },
|
|
21
|
+
* createIntrospector(db: Kysely<any>) {
|
|
22
|
+
* return new PostgresIntrospector(db)
|
|
23
|
+
* },
|
|
24
|
+
* createQueryCompiler() {
|
|
25
|
+
* return new PostgresQueryCompiler()
|
|
26
|
+
* },
|
|
27
|
+
* },
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class DummyDriver implements Driver {
|
|
32
|
+
/**
|
|
33
|
+
* Initializes the driver.
|
|
34
|
+
*
|
|
35
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
36
|
+
* methods should be callable.
|
|
37
|
+
*
|
|
38
|
+
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
39
|
+
* should be imported inside this function, not at the top of the driver file! This is
|
|
40
|
+
* important so that Kysely is usable without installing all database driver libraries
|
|
41
|
+
* it supports.
|
|
42
|
+
*/
|
|
43
|
+
init(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Acquires a new connection from the pool.
|
|
46
|
+
*/
|
|
47
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
48
|
+
/**
|
|
49
|
+
* Begins a transaction.
|
|
50
|
+
*/
|
|
51
|
+
beginTransaction(): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Commits a transaction.
|
|
54
|
+
*/
|
|
55
|
+
commitTransaction(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Rolls back a transaction.
|
|
58
|
+
*/
|
|
59
|
+
rollbackTransaction(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Releases a connection back to the pool.
|
|
62
|
+
*/
|
|
63
|
+
releaseConnection(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Destroys the driver and releases all resources.
|
|
66
|
+
*/
|
|
67
|
+
destroy(): Promise<void>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="./dummy-driver.d.ts" />
|
|
2
|
+
/**
|
|
3
|
+
* A driver that does absolutely nothing.
|
|
4
|
+
*
|
|
5
|
+
* You can use this to create Kysely instances solely for building queries
|
|
6
|
+
*
|
|
7
|
+
* ### Examples
|
|
8
|
+
*
|
|
9
|
+
* This example creates a Kysely instance for building postgres queries:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const db = new Kysely<Database>({
|
|
13
|
+
* dialect: {
|
|
14
|
+
* createAdapter() {
|
|
15
|
+
* return new PostgresAdapter()
|
|
16
|
+
* },
|
|
17
|
+
* createDriver() {
|
|
18
|
+
* return new DummyDriver()
|
|
19
|
+
* },
|
|
20
|
+
* createIntrospector(db: Kysely<any>) {
|
|
21
|
+
* return new PostgresIntrospector(db)
|
|
22
|
+
* },
|
|
23
|
+
* createQueryCompiler() {
|
|
24
|
+
* return new PostgresQueryCompiler()
|
|
25
|
+
* },
|
|
26
|
+
* },
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class DummyDriver {
|
|
31
|
+
async init() {
|
|
32
|
+
// Nothing to do here.
|
|
33
|
+
}
|
|
34
|
+
async acquireConnection() {
|
|
35
|
+
return new DummyConnection();
|
|
36
|
+
}
|
|
37
|
+
async beginTransaction() {
|
|
38
|
+
// Nothing to do here.
|
|
39
|
+
}
|
|
40
|
+
async commitTransaction() {
|
|
41
|
+
// Nothing to do here.
|
|
42
|
+
}
|
|
43
|
+
async rollbackTransaction() {
|
|
44
|
+
// Nothing to do here.
|
|
45
|
+
}
|
|
46
|
+
async releaseConnection() {
|
|
47
|
+
// Nothing to do here.
|
|
48
|
+
}
|
|
49
|
+
async destroy() {
|
|
50
|
+
// Nothing to do here.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class DummyConnection {
|
|
54
|
+
async executeQuery() {
|
|
55
|
+
return {
|
|
56
|
+
rows: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -28,7 +28,7 @@ export declare class RuntimeDriver implements Driver {
|
|
|
28
28
|
/**
|
|
29
29
|
* Releases a connection back to the pool.
|
|
30
30
|
*/
|
|
31
|
-
releaseConnection(
|
|
31
|
+
releaseConnection(connection: DatabaseConnection): Promise<void>;
|
|
32
32
|
/**
|
|
33
33
|
* Begins a transaction.
|
|
34
34
|
*/
|
|
@@ -10,7 +10,7 @@ export class RuntimeDriver {
|
|
|
10
10
|
#log;
|
|
11
11
|
#initPromise;
|
|
12
12
|
#destroyPromise;
|
|
13
|
-
#connections = new
|
|
13
|
+
#connections = new WeakSet();
|
|
14
14
|
constructor(driver, log) {
|
|
15
15
|
this.#driver = driver;
|
|
16
16
|
this.#log = log;
|
|
@@ -27,17 +27,16 @@ export class RuntimeDriver {
|
|
|
27
27
|
async acquireConnection() {
|
|
28
28
|
await this.init();
|
|
29
29
|
const connection = await this.#driver.acquireConnection();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
if (!this.#connections.has(connection)) {
|
|
31
|
+
if (this.#needsLogging()) {
|
|
32
|
+
this.#addLogging(connection);
|
|
33
|
+
}
|
|
34
|
+
this.#connections.add(connection);
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return connection;
|
|
36
37
|
}
|
|
37
|
-
async releaseConnection(
|
|
38
|
-
|
|
39
|
-
await this.#driver.releaseConnection(runtimeConnection.connection);
|
|
40
|
-
}
|
|
38
|
+
async releaseConnection(connection) {
|
|
39
|
+
await this.#driver.releaseConnection(connection);
|
|
41
40
|
}
|
|
42
41
|
beginTransaction(connection, settings) {
|
|
43
42
|
return this.#driver.beginTransaction(connection, settings);
|
|
@@ -61,29 +60,27 @@ export class RuntimeDriver {
|
|
|
61
60
|
}
|
|
62
61
|
await this.#destroyPromise;
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
#connection;
|
|
67
|
-
#log;
|
|
68
|
-
get connection() {
|
|
69
|
-
return this.#connection;
|
|
70
|
-
}
|
|
71
|
-
constructor(connection, log) {
|
|
72
|
-
this.#connection = connection;
|
|
73
|
-
this.#log = log;
|
|
63
|
+
#needsLogging() {
|
|
64
|
+
return (this.#log.isLevelEnabled('query') || this.#log.isLevelEnabled('error'));
|
|
74
65
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
// This method monkey patches the database connection's executeQuery method
|
|
67
|
+
// by adding logging code around it. Monkey patching is not pretty, but it's
|
|
68
|
+
// the best option in this case.
|
|
69
|
+
#addLogging(connection) {
|
|
70
|
+
const executeQuery = connection.executeQuery;
|
|
71
|
+
connection.executeQuery = async (compiledQuery) => {
|
|
72
|
+
const startTime = performanceNow();
|
|
73
|
+
try {
|
|
74
|
+
return await executeQuery.call(connection, compiledQuery);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.#logError(error);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
this.#logQuery(compiledQuery, startTime);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
87
84
|
}
|
|
88
85
|
#logError(error) {
|
|
89
86
|
this.#log.error(() => ({
|