kysely 0.17.0 → 0.17.3
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/mysql/mysql-dialect-config.d.ts +19 -0
- package/dist/cjs/driver/connection-provider.d.ts +1 -1
- package/dist/cjs/driver/default-connection-provider.d.ts +1 -1
- package/dist/cjs/driver/default-connection-provider.js +2 -2
- package/dist/cjs/driver/dummy-driver.d.ts +8 -0
- package/dist/cjs/driver/dummy-driver.js +8 -0
- package/dist/cjs/driver/single-connection-provider.d.ts +1 -1
- package/dist/cjs/driver/single-connection-provider.js +2 -2
- package/dist/cjs/kysely.js +23 -29
- package/dist/cjs/parser/complex-expression-parser.d.ts +1 -1
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +12 -5
- 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.js +2 -2
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +24 -10
- package/dist/cjs/query-builder/select-query-builder.d.ts +12 -5
- package/dist/cjs/query-builder/update-query-builder.d.ts +12 -5
- package/dist/cjs/query-builder/where-interface.d.ts +12 -5
- package/dist/cjs/query-executor/default-query-executor.d.ts +14 -7
- package/dist/cjs/query-executor/default-query-executor.js +4 -6
- package/dist/cjs/query-executor/noop-query-executor.d.ts +12 -6
- package/dist/cjs/query-executor/noop-query-executor.js +3 -3
- package/dist/cjs/query-executor/query-executor-base.d.ts +62 -0
- package/dist/cjs/query-executor/query-executor-base.js +46 -0
- package/dist/cjs/query-executor/query-executor.d.ts +15 -15
- package/dist/cjs/query-executor/query-executor.js +0 -57
- package/dist/cjs/raw-builder/sql.d.ts +11 -3
- package/dist/cjs/raw-builder/sql.js +10 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +24 -2
- package/dist/cjs/schema/alter-table-builder.js +20 -0
- package/dist/cjs/schema/column-definition-builder.d.ts +4 -2
- package/dist/cjs/schema/create-table-builder.d.ts +1 -1
- package/dist/cjs/schema/create-table-builder.js +1 -1
- package/dist/cjs/util/type-utils.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +19 -0
- package/dist/esm/driver/connection-provider.d.ts +1 -1
- package/dist/esm/driver/default-connection-provider.d.ts +1 -1
- package/dist/esm/driver/default-connection-provider.js +2 -2
- package/dist/esm/driver/dummy-driver.d.ts +8 -0
- package/dist/esm/driver/dummy-driver.js +8 -0
- package/dist/esm/driver/single-connection-provider.d.ts +1 -1
- package/dist/esm/driver/single-connection-provider.js +2 -2
- package/dist/esm/kysely.js +23 -29
- package/dist/esm/parser/complex-expression-parser.d.ts +1 -1
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +2 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +12 -5
- 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.js +1 -1
- package/dist/esm/query-builder/on-conflict-builder.d.ts +24 -10
- package/dist/esm/query-builder/select-query-builder.d.ts +12 -5
- package/dist/esm/query-builder/update-query-builder.d.ts +12 -5
- package/dist/esm/query-builder/where-interface.d.ts +12 -5
- package/dist/esm/query-executor/default-query-executor.d.ts +14 -7
- package/dist/esm/query-executor/default-query-executor.js +4 -6
- package/dist/esm/query-executor/noop-query-executor.d.ts +12 -6
- package/dist/esm/query-executor/noop-query-executor.js +3 -3
- package/dist/esm/query-executor/query-executor-base.d.ts +62 -0
- package/dist/esm/query-executor/query-executor-base.js +43 -0
- package/dist/esm/query-executor/query-executor.d.ts +15 -15
- package/dist/esm/query-executor/query-executor.js +1 -55
- package/dist/esm/raw-builder/sql.d.ts +11 -3
- package/dist/esm/raw-builder/sql.js +10 -2
- package/dist/esm/schema/alter-table-builder.d.ts +24 -2
- package/dist/esm/schema/alter-table-builder.js +20 -0
- package/dist/esm/schema/column-definition-builder.d.ts +4 -2
- package/dist/esm/schema/create-table-builder.d.ts +1 -1
- package/dist/esm/schema/create-table-builder.js +1 -1
- package/dist/esm/util/type-utils.d.ts +1 -1
- package/package.json +9 -9
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NOOP_QUERY_EXECUTOR = exports.NoopQueryExecutor = void 0;
|
|
4
|
-
const
|
|
4
|
+
const query_executor_base_js_1 = require("./query-executor-base.js");
|
|
5
5
|
/**
|
|
6
6
|
* A {@link QueryExecutor} subclass that can be used when you don't
|
|
7
7
|
* have a {@link QueryCompiler}, {@link ConnectionProvider} or any
|
|
8
8
|
* other needed things to actually execute queries.
|
|
9
9
|
*/
|
|
10
|
-
class NoopQueryExecutor extends
|
|
10
|
+
class NoopQueryExecutor extends query_executor_base_js_1.QueryExecutorBase {
|
|
11
11
|
get adapter() {
|
|
12
12
|
throw new Error('this query cannot be compiled to SQL');
|
|
13
13
|
}
|
|
14
14
|
compileQuery() {
|
|
15
15
|
throw new Error('this query cannot be compiled to SQL');
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
provideConnection() {
|
|
18
18
|
throw new Error('this query cannot be executed');
|
|
19
19
|
}
|
|
20
20
|
withConnectionProvider() {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ConnectionProvider } from '../driver/connection-provider.js';
|
|
2
|
+
import { DatabaseConnection, QueryResult } from '../driver/database-connection.js';
|
|
3
|
+
import { CompiledQuery } from '../query-compiler/compiled-query.js';
|
|
4
|
+
import { RootOperationNode } from '../query-compiler/query-compiler.js';
|
|
5
|
+
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
6
|
+
import { QueryId } from '../util/query-id.js';
|
|
7
|
+
import { DialectAdapter } from '../dialect/dialect-adapter.js';
|
|
8
|
+
import { QueryExecutor } from './query-executor.js';
|
|
9
|
+
export declare abstract class QueryExecutorBase implements QueryExecutor {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(plugins?: ReadonlyArray<KyselyPlugin>);
|
|
12
|
+
abstract get adapter(): DialectAdapter;
|
|
13
|
+
/**
|
|
14
|
+
* Returns all installed plugins.
|
|
15
|
+
*/
|
|
16
|
+
get plugins(): ReadonlyArray<KyselyPlugin>;
|
|
17
|
+
/**
|
|
18
|
+
* Given the query the user has built (expressed as an operation node tree)
|
|
19
|
+
* this method runs it through all plugins' `transformQuery` methods and
|
|
20
|
+
* returns the result.
|
|
21
|
+
*/
|
|
22
|
+
transformQuery<T extends RootOperationNode>(node: T, queryId: QueryId): T;
|
|
23
|
+
/**
|
|
24
|
+
* Compiles the transformed query into SQL. You usually want to pass
|
|
25
|
+
* the output of {@link transformQuery} into this method but you can
|
|
26
|
+
* compile any query using this method.
|
|
27
|
+
*/
|
|
28
|
+
abstract compileQuery(node: RootOperationNode, queryId: QueryId): CompiledQuery;
|
|
29
|
+
/**
|
|
30
|
+
* Provides a connection for the callback and takes care of disposing
|
|
31
|
+
* the connection after the callback has been run.
|
|
32
|
+
*/
|
|
33
|
+
abstract provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Executes a compiled query and runs the result through all plugins'
|
|
36
|
+
* `transformResult` method.
|
|
37
|
+
*/
|
|
38
|
+
executeQuery<R>(compiledQuery: CompiledQuery, queryId: QueryId): Promise<QueryResult<R>>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a copy of this executor with a new connection provider.
|
|
41
|
+
*/
|
|
42
|
+
abstract withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutorBase;
|
|
43
|
+
/**
|
|
44
|
+
* Returns a copy of this executor with a plugin added as the
|
|
45
|
+
* last plugin.
|
|
46
|
+
*/
|
|
47
|
+
abstract withPlugin(plugin: KyselyPlugin): QueryExecutorBase;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a copy of this executor with a list of plugins added
|
|
50
|
+
* as the last plugins.
|
|
51
|
+
*/
|
|
52
|
+
abstract withPlugins(plugin: ReadonlyArray<KyselyPlugin>): QueryExecutorBase;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a copy of this executor with a plugin added as the
|
|
55
|
+
* first plugin.
|
|
56
|
+
*/
|
|
57
|
+
abstract withPluginAtFront(plugin: KyselyPlugin): QueryExecutorBase;
|
|
58
|
+
/**
|
|
59
|
+
* Returns a copy of this executor without any plugins.
|
|
60
|
+
*/
|
|
61
|
+
abstract withoutPlugins(): QueryExecutorBase;
|
|
62
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryExecutorBase = void 0;
|
|
4
|
+
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
+
const NO_PLUGINS = (0, object_utils_js_1.freeze)([]);
|
|
6
|
+
class QueryExecutorBase {
|
|
7
|
+
#plugins;
|
|
8
|
+
constructor(plugins = NO_PLUGINS) {
|
|
9
|
+
this.#plugins = plugins;
|
|
10
|
+
}
|
|
11
|
+
get plugins() {
|
|
12
|
+
return this.#plugins;
|
|
13
|
+
}
|
|
14
|
+
transformQuery(node, queryId) {
|
|
15
|
+
for (const plugin of this.#plugins) {
|
|
16
|
+
const transformedNode = plugin.transformQuery({ node, queryId });
|
|
17
|
+
// We need to do a runtime check here. There is no good way
|
|
18
|
+
// to write types that enforce this constraint.
|
|
19
|
+
if (transformedNode.kind === node.kind) {
|
|
20
|
+
node = transformedNode;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error([
|
|
24
|
+
`KyselyPlugin.transformQuery must return a node`,
|
|
25
|
+
`of the same kind that was given to it.`,
|
|
26
|
+
`The plugin was given a ${node.kind}`,
|
|
27
|
+
`but it returned a ${transformedNode.kind}`,
|
|
28
|
+
].join(' '));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return node;
|
|
32
|
+
}
|
|
33
|
+
async executeQuery(compiledQuery, queryId) {
|
|
34
|
+
return await this.provideConnection(async (connection) => {
|
|
35
|
+
const result = await connection.executeQuery(compiledQuery);
|
|
36
|
+
return this.#transformResult(result, queryId);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async #transformResult(result, queryId) {
|
|
40
|
+
for (const plugin of this.#plugins) {
|
|
41
|
+
result = await plugin.transformResult({ result, queryId });
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.QueryExecutorBase = QueryExecutorBase;
|
|
@@ -6,15 +6,19 @@ import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
|
6
6
|
import { QueryId } from '../util/query-id.js';
|
|
7
7
|
import { DialectAdapter } from '../dialect/dialect-adapter.js';
|
|
8
8
|
/**
|
|
9
|
-
* This
|
|
9
|
+
* This interface abstracts away the details of how to compile a query into SQL
|
|
10
10
|
* and execute it. Instead of passing around all those details, {@link SelectQueryBuilder}
|
|
11
11
|
* and other classes that execute queries can just pass around and instance of
|
|
12
12
|
* `QueryExecutor`.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export interface QueryExecutor extends ConnectionProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Returns the adapter for the current dialect.
|
|
17
|
+
*/
|
|
18
|
+
get adapter(): DialectAdapter;
|
|
19
|
+
/**
|
|
20
|
+
* Returns all installed plugins.
|
|
21
|
+
*/
|
|
18
22
|
get plugins(): ReadonlyArray<KyselyPlugin>;
|
|
19
23
|
/**
|
|
20
24
|
* Given the query the user has built (expressed as an operation node tree)
|
|
@@ -27,37 +31,33 @@ export declare abstract class QueryExecutor {
|
|
|
27
31
|
* the output of {@link transformQuery} into this method but you can
|
|
28
32
|
* compile any query using this method.
|
|
29
33
|
*/
|
|
30
|
-
|
|
34
|
+
compileQuery(node: RootOperationNode, queryId: QueryId): CompiledQuery;
|
|
31
35
|
/**
|
|
32
36
|
* Executes a compiled query and runs the result through all plugins'
|
|
33
37
|
* `transformResult` method.
|
|
34
38
|
*/
|
|
35
39
|
executeQuery<R>(compiledQuery: CompiledQuery, queryId: QueryId): Promise<QueryResult<R>>;
|
|
36
|
-
/**
|
|
37
|
-
* Executes a compiled query.
|
|
38
|
-
*/
|
|
39
|
-
protected abstract executeQueryImpl<R>(compiledQuery: CompiledQuery, queryId: QueryId): Promise<QueryResult<R>>;
|
|
40
40
|
/**
|
|
41
41
|
* Returns a copy of this executor with a new connection provider.
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutor;
|
|
44
44
|
/**
|
|
45
45
|
* Returns a copy of this executor with a plugin added as the
|
|
46
46
|
* last plugin.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
withPlugin(plugin: KyselyPlugin): QueryExecutor;
|
|
49
49
|
/**
|
|
50
50
|
* Returns a copy of this executor with a list of plugins added
|
|
51
51
|
* as the last plugins.
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
withPlugins(plugin: ReadonlyArray<KyselyPlugin>): QueryExecutor;
|
|
54
54
|
/**
|
|
55
55
|
* Returns a copy of this executor with a plugin added as the
|
|
56
56
|
* first plugin.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
withPluginAtFront(plugin: KyselyPlugin): QueryExecutor;
|
|
59
59
|
/**
|
|
60
60
|
* Returns a copy of this executor without any plugins.
|
|
61
61
|
*/
|
|
62
|
-
|
|
62
|
+
withoutPlugins(): QueryExecutor;
|
|
63
63
|
}
|
|
@@ -1,59 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryExecutor = void 0;
|
|
4
|
-
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
-
const NO_PLUGINS = (0, object_utils_js_1.freeze)([]);
|
|
6
|
-
/**
|
|
7
|
-
* This class abstracts away the details of how to compile a query into SQL
|
|
8
|
-
* and execute it. Instead of passing around all those details, {@link SelectQueryBuilder}
|
|
9
|
-
* and other classes that execute queries can just pass around and instance of
|
|
10
|
-
* `QueryExecutor`.
|
|
11
|
-
*/
|
|
12
|
-
class QueryExecutor {
|
|
13
|
-
#plugins;
|
|
14
|
-
constructor(plugins) {
|
|
15
|
-
this.#plugins = plugins ?? NO_PLUGINS;
|
|
16
|
-
}
|
|
17
|
-
get plugins() {
|
|
18
|
-
return this.#plugins;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Given the query the user has built (expressed as an operation node tree)
|
|
22
|
-
* this method runs it through all plugins' `transformQuery` methods and
|
|
23
|
-
* returns the result.
|
|
24
|
-
*/
|
|
25
|
-
transformQuery(node, queryId) {
|
|
26
|
-
for (const plugin of this.#plugins) {
|
|
27
|
-
const transformedNode = plugin.transformQuery({ node, queryId });
|
|
28
|
-
// We need to do a runtime check here. There is no good way
|
|
29
|
-
// to write types that enforce this constraint.
|
|
30
|
-
if (transformedNode.kind === node.kind) {
|
|
31
|
-
node = transformedNode;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw new Error([
|
|
35
|
-
`KyselyPlugin.transformQuery must return a node`,
|
|
36
|
-
`of the same kind that was given to it.`,
|
|
37
|
-
`The plugin was given a ${node.kind}`,
|
|
38
|
-
`but it returned a ${transformedNode.kind}`,
|
|
39
|
-
].join(' '));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return node;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Executes a compiled query and runs the result through all plugins'
|
|
46
|
-
* `transformResult` method.
|
|
47
|
-
*/
|
|
48
|
-
async executeQuery(compiledQuery, queryId) {
|
|
49
|
-
const result = await this.executeQueryImpl(compiledQuery, queryId);
|
|
50
|
-
return this.#transformResult(result, queryId);
|
|
51
|
-
}
|
|
52
|
-
async #transformResult(result, queryId) {
|
|
53
|
-
for (const plugin of this.#plugins) {
|
|
54
|
-
result = await plugin.transformResult({ result, queryId });
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.QueryExecutor = QueryExecutor;
|
|
@@ -221,7 +221,7 @@ export interface Sql {
|
|
|
221
221
|
* sql.id('first_name')
|
|
222
222
|
* ]
|
|
223
223
|
*
|
|
224
|
-
* sql`BEFORE ${sql.
|
|
224
|
+
* sql`BEFORE ${sql.join(things, sql`::varchar, `)} AFTER`
|
|
225
225
|
* ```
|
|
226
226
|
*
|
|
227
227
|
* The generated SQL (PostgreSQL):
|
|
@@ -281,7 +281,7 @@ export interface Sql {
|
|
|
281
281
|
* from "person"
|
|
282
282
|
* where birthdate between $1 and $2
|
|
283
283
|
* and "nicknames" @> ARRAY[$3, $4, $5, $6, $7, $8, $9, $10]
|
|
284
|
-
* order by
|
|
284
|
+
* order by concat(first_name, ' ', last_name)
|
|
285
285
|
* ```
|
|
286
286
|
*
|
|
287
287
|
* SQL snippets can be executed by calling the `execute` method and passing a `Kysely`
|
|
@@ -313,7 +313,15 @@ export interface Sql {
|
|
|
313
313
|
* .select([
|
|
314
314
|
* 'first_name',
|
|
315
315
|
* 'last_name',
|
|
316
|
-
* (eb) =>
|
|
316
|
+
* (eb) => {
|
|
317
|
+
* // The `eb.ref` method is type-safe and only accepts
|
|
318
|
+
* // column references that are possible.
|
|
319
|
+
* const firstName = eb.ref('first_name')
|
|
320
|
+
* const lastName = eb.ref('last_name')
|
|
321
|
+
*
|
|
322
|
+
* const fullName = sql<string>`concat(${firstName}, ' ', ${lastName})`
|
|
323
|
+
* return fullName.as('full_name')
|
|
324
|
+
* }
|
|
317
325
|
* ])
|
|
318
326
|
* ```
|
|
319
327
|
*
|
|
@@ -58,7 +58,7 @@ const raw_builder_js_1 = require("./raw-builder.js");
|
|
|
58
58
|
* from "person"
|
|
59
59
|
* where birthdate between $1 and $2
|
|
60
60
|
* and "nicknames" @> ARRAY[$3, $4, $5, $6, $7, $8, $9, $10]
|
|
61
|
-
* order by
|
|
61
|
+
* order by concat(first_name, ' ', last_name)
|
|
62
62
|
* ```
|
|
63
63
|
*
|
|
64
64
|
* SQL snippets can be executed by calling the `execute` method and passing a `Kysely`
|
|
@@ -90,7 +90,15 @@ const raw_builder_js_1 = require("./raw-builder.js");
|
|
|
90
90
|
* .select([
|
|
91
91
|
* 'first_name',
|
|
92
92
|
* 'last_name',
|
|
93
|
-
* (eb) =>
|
|
93
|
+
* (eb) => {
|
|
94
|
+
* // The `eb.ref` method is type-safe and only accepts
|
|
95
|
+
* // column references that are possible.
|
|
96
|
+
* const firstName = eb.ref('first_name')
|
|
97
|
+
* const lastName = eb.ref('last_name')
|
|
98
|
+
*
|
|
99
|
+
* const fullName = sql<string>`concat(${firstName}, ' ', ${lastName})`
|
|
100
|
+
* return fullName.as('full_name')
|
|
101
|
+
* }
|
|
94
102
|
* ])
|
|
95
103
|
* ```
|
|
96
104
|
*
|
|
@@ -23,6 +23,13 @@ export declare class AlterTableBuilder {
|
|
|
23
23
|
alterColumn(column: string): AlterColumnBuilder;
|
|
24
24
|
dropColumn(column: string): AlterTableExecutor;
|
|
25
25
|
renameColumn(column: string, newColumn: string): AlterTableExecutor;
|
|
26
|
+
/**
|
|
27
|
+
* See {@link CreateTableBuilder.addColumn}
|
|
28
|
+
*
|
|
29
|
+
* Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
|
|
30
|
+
* and doesn't take a callback as the last argument. This is because you can only
|
|
31
|
+
* add one column per `ALTER TABLE` query.
|
|
32
|
+
*/
|
|
26
33
|
addColumn(columnName: string, dataType: DataTypeExpression): AlterTableAddColumnBuilder;
|
|
27
34
|
/**
|
|
28
35
|
* Creates an `alter table modify column` query. The `modify column` statement
|
|
@@ -30,8 +37,21 @@ export declare class AlterTableBuilder {
|
|
|
30
37
|
* should use the `alterColumn` method.
|
|
31
38
|
*/
|
|
32
39
|
modifyColumn(columnName: string, dataType: DataTypeExpression): AlterTableModifyColumnBuilder;
|
|
40
|
+
/**
|
|
41
|
+
* See {@link CreateTableBuilder.addUniqueConstraint}
|
|
42
|
+
*/
|
|
33
43
|
addUniqueConstraint(constraintName: string, columns: string[]): AlterTableExecutor;
|
|
44
|
+
/**
|
|
45
|
+
* See {@link CreateTableBuilder.addCheckConstraint}
|
|
46
|
+
*/
|
|
34
47
|
addCheckConstraint(constraintName: string, checkExpression: AnyRawBuilder): AlterTableExecutor;
|
|
48
|
+
/**
|
|
49
|
+
* See {@link CreateTableBuilder.addForeignKeyConstraint}
|
|
50
|
+
*
|
|
51
|
+
* Unlike {@link CreateTableBuilder.addForeignKeyConstraint} this method returns
|
|
52
|
+
* the constraint builder and doesn't take a callback as the last argument. This
|
|
53
|
+
* is because you can only add one column per `ALTER TABLE` query.
|
|
54
|
+
*/
|
|
35
55
|
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[]): AlterTableAddForeignKeyConstraintBuilder;
|
|
36
56
|
}
|
|
37
57
|
export interface AlterTableBuilderProps {
|
|
@@ -142,7 +162,8 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
142
162
|
* .execute()
|
|
143
163
|
* ```
|
|
144
164
|
*
|
|
145
|
-
*
|
|
165
|
+
* Values passed to `defaultTo` are interpreted as value literals by default. You can define
|
|
166
|
+
* an arbitrary SQL expression using the {@link sql} template tag:
|
|
146
167
|
*
|
|
147
168
|
* ```ts
|
|
148
169
|
* import { sql } from 'kysely'
|
|
@@ -306,7 +327,8 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
|
|
|
306
327
|
* .execute()
|
|
307
328
|
* ```
|
|
308
329
|
*
|
|
309
|
-
*
|
|
330
|
+
* Values passed to `defaultTo` are interpreted as value literals by default. You can define
|
|
331
|
+
* an arbitrary SQL expression using the {@link sql} template tag:
|
|
310
332
|
*
|
|
311
333
|
* ```ts
|
|
312
334
|
* import { sql } from 'kysely'
|
|
@@ -68,6 +68,13 @@ class AlterTableBuilder {
|
|
|
68
68
|
}),
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* See {@link CreateTableBuilder.addColumn}
|
|
73
|
+
*
|
|
74
|
+
* Unlike {@link CreateTableBuilder.addColumn} this method returns the column builder
|
|
75
|
+
* and doesn't take a callback as the last argument. This is because you can only
|
|
76
|
+
* add one column per `ALTER TABLE` query.
|
|
77
|
+
*/
|
|
71
78
|
addColumn(columnName, dataType) {
|
|
72
79
|
return new AlterTableAddColumnBuilder({
|
|
73
80
|
...this.#props,
|
|
@@ -85,6 +92,9 @@ class AlterTableBuilder {
|
|
|
85
92
|
columnBuilder: new column_definition_builder_js_1.ColumnDefinitionBuilder(column_definition_node_js_1.ColumnDefinitionNode.create(columnName, (0, data_type_parser_js_1.parseDataTypeExpression)(dataType))),
|
|
86
93
|
});
|
|
87
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* See {@link CreateTableBuilder.addUniqueConstraint}
|
|
97
|
+
*/
|
|
88
98
|
addUniqueConstraint(constraintName, columns) {
|
|
89
99
|
return new AlterTableExecutor({
|
|
90
100
|
...this.#props,
|
|
@@ -93,6 +103,9 @@ class AlterTableBuilder {
|
|
|
93
103
|
}),
|
|
94
104
|
});
|
|
95
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* See {@link CreateTableBuilder.addCheckConstraint}
|
|
108
|
+
*/
|
|
96
109
|
addCheckConstraint(constraintName, checkExpression) {
|
|
97
110
|
return new AlterTableExecutor({
|
|
98
111
|
...this.#props,
|
|
@@ -101,6 +114,13 @@ class AlterTableBuilder {
|
|
|
101
114
|
}),
|
|
102
115
|
});
|
|
103
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* See {@link CreateTableBuilder.addForeignKeyConstraint}
|
|
119
|
+
*
|
|
120
|
+
* Unlike {@link CreateTableBuilder.addForeignKeyConstraint} this method returns
|
|
121
|
+
* the constraint builder and doesn't take a callback as the last argument. This
|
|
122
|
+
* is because you can only add one column per `ALTER TABLE` query.
|
|
123
|
+
*/
|
|
104
124
|
addForeignKeyConstraint(constraintName, columns, targetTable, targetColumns) {
|
|
105
125
|
return new AlterTableAddForeignKeyConstraintBuilder({
|
|
106
126
|
...this.#props,
|
|
@@ -83,7 +83,8 @@ export interface ColumnDefinitionBuilderInterface {
|
|
|
83
83
|
* .execute()
|
|
84
84
|
* ```
|
|
85
85
|
*
|
|
86
|
-
*
|
|
86
|
+
* Values passed to `defaultTo` are interpreted as value literals by default. You can define
|
|
87
|
+
* an arbitrary SQL expression using the {@link sql} template tag:
|
|
87
88
|
*
|
|
88
89
|
* ```ts
|
|
89
90
|
* import { sql } from 'kysely'
|
|
@@ -241,7 +242,8 @@ export declare class ColumnDefinitionBuilder implements ColumnDefinitionBuilderI
|
|
|
241
242
|
* .execute()
|
|
242
243
|
* ```
|
|
243
244
|
*
|
|
244
|
-
*
|
|
245
|
+
* Values passed to `defaultTo` are interpreted as value literals by default. You can define
|
|
246
|
+
* an arbitrary SQL expression using the {@link sql} template tag:
|
|
245
247
|
*
|
|
246
248
|
* ```ts
|
|
247
249
|
* import { sql } from 'kysely'
|
|
@@ -74,7 +74,7 @@ export declare type ExtractColumnType<DB, TB extends keyof DB, C> = {
|
|
|
74
74
|
* movie: Movie
|
|
75
75
|
* }
|
|
76
76
|
*
|
|
77
|
-
* type Columns =
|
|
77
|
+
* type Columns = AnyColumnWithTable<Database, 'person' | 'pet'>
|
|
78
78
|
*
|
|
79
79
|
* // Columns == 'person.id' | 'pet.name' | 'pet.species'
|
|
80
80
|
* ```
|
|
@@ -162,6 +162,25 @@ export interface MysqlDialectConfig {
|
|
|
162
162
|
* If keep-alive is enabled users can supply an initial delay.
|
|
163
163
|
*/
|
|
164
164
|
keepAliveInitialDelay?: number;
|
|
165
|
+
charsetNumber?: number;
|
|
166
|
+
compress?: boolean;
|
|
167
|
+
authSwitchHandler?: (data: any, callback: () => void) => any;
|
|
168
|
+
connectAttributes?: {
|
|
169
|
+
[param: string]: any;
|
|
170
|
+
};
|
|
171
|
+
decimalNumbers?: boolean;
|
|
172
|
+
isServer?: boolean;
|
|
173
|
+
maxPreparedStatements?: number;
|
|
174
|
+
namedPlaceholders?: boolean;
|
|
175
|
+
nestTables?: boolean | string;
|
|
176
|
+
passwordSha1?: string;
|
|
177
|
+
pool?: any;
|
|
178
|
+
stream?: any;
|
|
179
|
+
uri?: string;
|
|
180
|
+
Promise?: any;
|
|
181
|
+
authPlugins?: {
|
|
182
|
+
[key: string]: any;
|
|
183
|
+
};
|
|
165
184
|
/**
|
|
166
185
|
* Called once for each created connection.
|
|
167
186
|
*
|
|
@@ -4,5 +4,5 @@ export interface ConnectionProvider {
|
|
|
4
4
|
* Provides a connection for the callback and takes care of disposing
|
|
5
5
|
* the connection after the callback has been run.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
8
8
|
}
|
|
@@ -8,5 +8,5 @@ export declare class DefaultConnectionProvider implements ConnectionProvider {
|
|
|
8
8
|
* Provides a connection for the callback and takes care of disposing
|
|
9
9
|
* the connection after the callback has been run.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
12
12
|
}
|
|
@@ -4,10 +4,10 @@ export class DefaultConnectionProvider {
|
|
|
4
4
|
constructor(driver) {
|
|
5
5
|
this.#driver = driver;
|
|
6
6
|
}
|
|
7
|
-
async
|
|
7
|
+
async provideConnection(consumer) {
|
|
8
8
|
const connection = await this.#driver.acquireConnection();
|
|
9
9
|
try {
|
|
10
|
-
return await
|
|
10
|
+
return await consumer(connection);
|
|
11
11
|
}
|
|
12
12
|
finally {
|
|
13
13
|
await this.#driver.releaseConnection(connection);
|
|
@@ -27,6 +27,14 @@ import { Driver } from './driver.js';
|
|
|
27
27
|
* },
|
|
28
28
|
* })
|
|
29
29
|
* ```
|
|
30
|
+
*
|
|
31
|
+
* You can use it to build a query and compile it to SQL but trying to
|
|
32
|
+
* execute the query will throw an error.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* const { sql } = db.selectFrom('person').selectAll().compile()
|
|
36
|
+
* console.log(sql) // select * from "person"
|
|
37
|
+
* ```
|
|
30
38
|
*/
|
|
31
39
|
export declare class DummyDriver implements Driver {
|
|
32
40
|
/**
|
|
@@ -26,6 +26,14 @@
|
|
|
26
26
|
* },
|
|
27
27
|
* })
|
|
28
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* You can use it to build a query and compile it to SQL but trying to
|
|
31
|
+
* execute the query will throw an error.
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* const { sql } = db.selectFrom('person').selectAll().compile()
|
|
35
|
+
* console.log(sql) // select * from "person"
|
|
36
|
+
* ```
|
|
29
37
|
*/
|
|
30
38
|
export class DummyDriver {
|
|
31
39
|
async init() {
|
|
@@ -7,5 +7,5 @@ export declare class SingleConnectionProvider implements ConnectionProvider {
|
|
|
7
7
|
* Provides a connection for the callback and takes care of disposing
|
|
8
8
|
* the connection after the callback has been run.
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
11
11
|
}
|
|
@@ -5,11 +5,11 @@ export class SingleConnectionProvider {
|
|
|
5
5
|
constructor(connection) {
|
|
6
6
|
this.#connection = connection;
|
|
7
7
|
}
|
|
8
|
-
async
|
|
8
|
+
async provideConnection(consumer) {
|
|
9
9
|
while (this.#runningPromise) {
|
|
10
10
|
await this.#runningPromise;
|
|
11
11
|
}
|
|
12
|
-
const promise = this.#run(
|
|
12
|
+
const promise = this.#run(consumer);
|
|
13
13
|
this.#runningPromise = promise
|
|
14
14
|
.then(() => {
|
|
15
15
|
this.#runningPromise = undefined;
|
package/dist/esm/kysely.js
CHANGED
|
@@ -333,18 +333,14 @@ export class ConnectionBuilder {
|
|
|
333
333
|
this.#props = freeze(props);
|
|
334
334
|
}
|
|
335
335
|
async execute(callback) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
try {
|
|
336
|
+
return this.#props.executor.provideConnection(async (connection) => {
|
|
337
|
+
const executor = this.#props.executor.withConnectionProvider(new SingleConnectionProvider(connection));
|
|
338
|
+
const db = new Kysely({
|
|
339
|
+
...this.#props,
|
|
340
|
+
executor,
|
|
341
|
+
});
|
|
343
342
|
return await callback(db);
|
|
344
|
-
}
|
|
345
|
-
finally {
|
|
346
|
-
await this.#props.driver.releaseConnection(connection);
|
|
347
|
-
}
|
|
343
|
+
});
|
|
348
344
|
}
|
|
349
345
|
}
|
|
350
346
|
preventAwait(ConnectionBuilder, "don't await ConnectionBuilder instances directly. To execute the query you need to call the `execute` method");
|
|
@@ -363,25 +359,23 @@ export class TransactionBuilder {
|
|
|
363
359
|
const { isolationLevel, ...kyselyProps } = this.#props;
|
|
364
360
|
const settings = { isolationLevel };
|
|
365
361
|
validateTransactionSettings(settings);
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
362
|
+
return this.#props.executor.provideConnection(async (connection) => {
|
|
363
|
+
const executor = this.#props.executor.withConnectionProvider(new SingleConnectionProvider(connection));
|
|
364
|
+
const transaction = new Transaction({
|
|
365
|
+
...kyselyProps,
|
|
366
|
+
executor,
|
|
367
|
+
});
|
|
368
|
+
try {
|
|
369
|
+
await this.#props.driver.beginTransaction(connection, settings);
|
|
370
|
+
const result = await callback(transaction);
|
|
371
|
+
await this.#props.driver.commitTransaction(connection);
|
|
372
|
+
return result;
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
await this.#props.driver.rollbackTransaction(connection);
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
371
378
|
});
|
|
372
|
-
try {
|
|
373
|
-
await this.#props.driver.beginTransaction(connection, settings);
|
|
374
|
-
const result = await callback(transaction);
|
|
375
|
-
await this.#props.driver.commitTransaction(connection);
|
|
376
|
-
return result;
|
|
377
|
-
}
|
|
378
|
-
catch (error) {
|
|
379
|
-
await this.#props.driver.rollbackTransaction(connection);
|
|
380
|
-
throw error;
|
|
381
|
-
}
|
|
382
|
-
finally {
|
|
383
|
-
await this.#props.driver.releaseConnection(connection);
|
|
384
|
-
}
|
|
385
379
|
}
|
|
386
380
|
}
|
|
387
381
|
preventAwait(TransactionBuilder, "don't await TransactionBuilder instances directly. To execute the transaction you need to call the `execute` method");
|