kysely 0.9.2 → 0.9.6
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.d.ts +11 -0
- package/dist/cjs/dialect/mysql/mysql-dialect.js +7 -0
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +13 -1
- package/dist/cjs/dialect/postgres/postgres-dialect.js +10 -0
- package/dist/cjs/dialect/postgres/postgres-driver.js +2 -2
- package/dist/cjs/dialect/postgres/postgres-query-compiler.js +1 -1
- package/dist/cjs/driver/runtime-driver.d.ts +3 -2
- package/dist/cjs/driver/runtime-driver.js +57 -4
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/kysely.d.ts +31 -9
- package/dist/cjs/kysely.js +25 -9
- package/dist/cjs/migration/migration.d.ts +32 -0
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +9 -0
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +61 -59
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -316
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.js +1 -0
- package/dist/cjs/operation-node/select-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/select-query-node.js +8 -0
- package/dist/cjs/operation-node/union-node.d.ts +16 -0
- package/dist/cjs/operation-node/union-node.js +19 -0
- package/dist/cjs/parser/insert-values-parser.d.ts +1 -1
- package/dist/cjs/parser/join-parser.d.ts +4 -4
- package/dist/cjs/parser/union-parser.d.ts +5 -0
- package/dist/cjs/parser/union-parser.js +13 -0
- package/dist/cjs/parser/value-parser.d.ts +1 -1
- package/dist/cjs/plugin/camel-case/camel-case-plugin.js +5 -116
- package/dist/cjs/plugin/camel-case/camel-case-transformer.d.ts +8 -0
- package/dist/cjs/plugin/camel-case/camel-case-transformer.js +19 -0
- package/dist/cjs/plugin/camel-case/camel-case.d.ts +15 -0
- package/dist/cjs/plugin/camel-case/camel-case.js +109 -0
- package/dist/cjs/plugin/kysely-plugin.d.ts +1 -1
- package/dist/cjs/query-builder/query-builder.d.ts +65 -1
- package/dist/cjs/query-builder/query-builder.js +83 -0
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +5 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +18 -1
- package/dist/cjs/query-executor/default-query-executor.d.ts +1 -0
- package/dist/cjs/query-executor/default-query-executor.js +6 -0
- package/dist/cjs/query-executor/noop-query-executor.d.ts +1 -0
- package/dist/cjs/query-executor/noop-query-executor.js +3 -0
- package/dist/cjs/query-executor/query-executor.d.ts +9 -4
- package/dist/cjs/util/log.d.ts +19 -0
- package/dist/cjs/util/log.js +37 -0
- package/dist/cjs/util/random-string.js +6 -3
- package/dist/cjs/util/type-utils.d.ts +4 -4
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +11 -0
- package/dist/esm/dialect/mysql/mysql-dialect.js +7 -0
- package/dist/esm/dialect/mysql/mysql-driver.js +1 -1
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +13 -1
- package/dist/esm/dialect/postgres/postgres-dialect.js +10 -0
- package/dist/esm/dialect/postgres/postgres-driver.js +2 -2
- package/dist/esm/dialect/postgres/postgres-query-compiler.js +1 -1
- package/dist/esm/driver/runtime-driver.d.ts +3 -2
- package/dist/esm/driver/runtime-driver.js +57 -4
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/kysely.d.ts +31 -9
- package/dist/esm/kysely.js +25 -9
- package/dist/esm/migration/migration.d.ts +32 -0
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +9 -0
- package/dist/esm/operation-node/operation-node-visitor.d.ts +61 -59
- package/dist/esm/operation-node/operation-node-visitor.js +1 -316
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.js +1 -0
- package/dist/esm/operation-node/select-query-node.d.ts +3 -0
- package/dist/esm/operation-node/select-query-node.js +8 -0
- package/dist/esm/operation-node/union-node.d.ts +16 -0
- package/dist/esm/operation-node/union-node.js +16 -0
- package/dist/esm/parser/insert-values-parser.d.ts +1 -1
- package/dist/esm/parser/join-parser.d.ts +4 -4
- package/dist/esm/parser/union-parser.d.ts +5 -0
- package/dist/esm/parser/union-parser.js +9 -0
- package/dist/esm/parser/value-parser.d.ts +1 -1
- package/dist/esm/plugin/camel-case/camel-case-plugin.js +4 -115
- package/dist/esm/plugin/camel-case/camel-case-transformer.d.ts +8 -0
- package/dist/esm/plugin/camel-case/camel-case-transformer.js +15 -0
- package/dist/esm/plugin/camel-case/camel-case.d.ts +15 -0
- package/dist/esm/plugin/camel-case/camel-case.js +104 -0
- package/dist/esm/plugin/kysely-plugin.d.ts +1 -1
- package/dist/esm/query-builder/query-builder.d.ts +65 -1
- package/dist/esm/query-builder/query-builder.js +83 -0
- package/dist/esm/query-compiler/default-query-compiler.d.ts +5 -0
- package/dist/esm/query-compiler/default-query-compiler.js +18 -1
- package/dist/esm/query-executor/default-query-executor.d.ts +1 -0
- package/dist/esm/query-executor/default-query-executor.js +6 -0
- package/dist/esm/query-executor/noop-query-executor.d.ts +1 -0
- package/dist/esm/query-executor/noop-query-executor.js +3 -0
- package/dist/esm/query-executor/query-executor.d.ts +9 -4
- package/dist/esm/util/log.d.ts +19 -0
- package/dist/esm/util/log.js +33 -0
- package/dist/esm/util/random-string.js +6 -3
- package/dist/esm/util/type-utils.d.ts +4 -4
- package/package.json +1 -1
|
@@ -5,6 +5,13 @@ import { Dialect } from '../dialect.js';
|
|
|
5
5
|
import { DatabaseIntrospector } from '../../introspection/database-introspector.js';
|
|
6
6
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
7
7
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
8
|
+
/**
|
|
9
|
+
* MySQL dialect that uses the [mysql2](https://github.com/sidorares/node-mysql2#readme) library.
|
|
10
|
+
*
|
|
11
|
+
* The {@link MysqlDialectConfig | configuration} passed to the constructor
|
|
12
|
+
* is given as-is to the mysql2 library's [createPool](https://github.com/sidorares/node-mysql2#using-connection-pools)
|
|
13
|
+
* method.
|
|
14
|
+
*/
|
|
8
15
|
export declare class MysqlDialect implements Dialect {
|
|
9
16
|
#private;
|
|
10
17
|
constructor(config: MysqlDialectConfig);
|
|
@@ -17,6 +24,8 @@ export declare class MysqlDialect implements Dialect {
|
|
|
17
24
|
* Config for the mysql dialect.
|
|
18
25
|
*
|
|
19
26
|
* This interface is equal to `mysql2` library's pool config.
|
|
27
|
+
*
|
|
28
|
+
* https://github.com/sidorares/node-mysql2#using-connection-pools
|
|
20
29
|
*/
|
|
21
30
|
export interface MysqlDialectConfig {
|
|
22
31
|
/**
|
|
@@ -176,6 +185,8 @@ export interface MysqlDialectConfig {
|
|
|
176
185
|
keepAliveInitialDelay?: number;
|
|
177
186
|
/**
|
|
178
187
|
* Called once for each created connection.
|
|
188
|
+
*
|
|
189
|
+
* This is a Kysely specific feature and does not come from the `pg` module.
|
|
179
190
|
*/
|
|
180
191
|
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
181
192
|
}
|
|
@@ -5,6 +5,13 @@ const mysql_driver_js_1 = require("./mysql-driver.js");
|
|
|
5
5
|
const mysql_query_compiler_js_1 = require("./mysql-query-compiler.js");
|
|
6
6
|
const mysql_introspector_js_1 = require("./mysql-introspector.js");
|
|
7
7
|
const mysql_adapter_js_1 = require("./mysql-adapter.js");
|
|
8
|
+
/**
|
|
9
|
+
* MySQL dialect that uses the [mysql2](https://github.com/sidorares/node-mysql2#readme) library.
|
|
10
|
+
*
|
|
11
|
+
* The {@link MysqlDialectConfig | configuration} passed to the constructor
|
|
12
|
+
* is given as-is to the mysql2 library's [createPool](https://github.com/sidorares/node-mysql2#using-connection-pools)
|
|
13
|
+
* method.
|
|
14
|
+
*/
|
|
8
15
|
class MysqlDialect {
|
|
9
16
|
#config;
|
|
10
17
|
constructor(config) {
|
|
@@ -8,6 +8,16 @@ import { Dialect } from '../dialect.js';
|
|
|
8
8
|
import { DatabaseIntrospector } from '../../introspection/database-introspector.js';
|
|
9
9
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
10
10
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
11
|
+
/**
|
|
12
|
+
* PostgreSQL dialect that uses the [pg](https://node-postgres.com/) library.
|
|
13
|
+
*
|
|
14
|
+
* The {@link PostgresDialectConfig | configuration} passed to the constructor
|
|
15
|
+
* is given as-is to the pg library's [Pool](https://node-postgres.com/api/pool)
|
|
16
|
+
* constructor. See the following two links for more documentation:
|
|
17
|
+
*
|
|
18
|
+
* https://node-postgres.com/api/pool
|
|
19
|
+
* https://node-postgres.com/api/client
|
|
20
|
+
*/
|
|
11
21
|
export declare class PostgresDialect implements Dialect {
|
|
12
22
|
#private;
|
|
13
23
|
constructor(config: PostgresDialectConfig);
|
|
@@ -19,7 +29,7 @@ export declare class PostgresDialect implements Dialect {
|
|
|
19
29
|
/**
|
|
20
30
|
* Config for the postgres dialect.
|
|
21
31
|
*
|
|
22
|
-
* This interface is equal to `pg` library's
|
|
32
|
+
* This interface is equal to `pg` library's `Pool` config:
|
|
23
33
|
*
|
|
24
34
|
* https://node-postgres.com/api/pool
|
|
25
35
|
* https://node-postgres.com/api/client
|
|
@@ -105,6 +115,8 @@ export interface PostgresDialectConfig {
|
|
|
105
115
|
application_name?: string;
|
|
106
116
|
/**
|
|
107
117
|
* Called once for each created connection.
|
|
118
|
+
*
|
|
119
|
+
* This is a Kysely specific feature and does not come from the `pg` module.
|
|
108
120
|
*/
|
|
109
121
|
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
110
122
|
keepAlive?: boolean;
|
|
@@ -5,6 +5,16 @@ const postgres_driver_js_1 = require("./postgres-driver.js");
|
|
|
5
5
|
const postgres_introspector_js_1 = require("./postgres-introspector.js");
|
|
6
6
|
const postgres_query_compiler_js_1 = require("./postgres-query-compiler.js");
|
|
7
7
|
const postgres_adapter_js_1 = require("./postgres-adapter.js");
|
|
8
|
+
/**
|
|
9
|
+
* PostgreSQL dialect that uses the [pg](https://node-postgres.com/) library.
|
|
10
|
+
*
|
|
11
|
+
* The {@link PostgresDialectConfig | configuration} passed to the constructor
|
|
12
|
+
* is given as-is to the pg library's [Pool](https://node-postgres.com/api/pool)
|
|
13
|
+
* constructor. See the following two links for more documentation:
|
|
14
|
+
*
|
|
15
|
+
* https://node-postgres.com/api/pool
|
|
16
|
+
* https://node-postgres.com/api/client
|
|
17
|
+
*/
|
|
8
18
|
class PostgresDialect {
|
|
9
19
|
#config;
|
|
10
20
|
constructor(config) {
|
|
@@ -16,10 +16,10 @@ class PostgresDriver {
|
|
|
16
16
|
// installed. As you can see, there IS an import from `pg` at the
|
|
17
17
|
// top level too, but that's only for types. It doesn't get compiled
|
|
18
18
|
// into javascript. You can check the built javascript code.
|
|
19
|
-
const
|
|
19
|
+
const PoolConstructor = await importPgPool();
|
|
20
20
|
// Use the `pg` module's own pool. All drivers should use the
|
|
21
21
|
// pool provided by the database library if possible.
|
|
22
|
-
this.#pool = new
|
|
22
|
+
this.#pool = new PoolConstructor(this.#config);
|
|
23
23
|
}
|
|
24
24
|
async acquireConnection() {
|
|
25
25
|
const client = await this.#pool.connect();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PostgresQueryCompiler = void 0;
|
|
4
4
|
const default_query_compiler_js_1 = require("../../query-compiler/default-query-compiler.js");
|
|
5
|
-
// The default query compiler is for
|
|
5
|
+
// The default query compiler is for PostgreSQL.
|
|
6
6
|
class PostgresQueryCompiler extends default_query_compiler_js_1.DefaultQueryCompiler {
|
|
7
7
|
}
|
|
8
8
|
exports.PostgresQueryCompiler = PostgresQueryCompiler;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Log } from '../util/log.js';
|
|
1
2
|
import { DatabaseConnection } from './database-connection.js';
|
|
2
3
|
import { Driver, TransactionSettings } from './driver.js';
|
|
3
4
|
/**
|
|
@@ -7,10 +8,10 @@ import { Driver, TransactionSettings } from './driver.js';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class RuntimeDriver implements Driver {
|
|
9
10
|
#private;
|
|
10
|
-
constructor(driver: Driver);
|
|
11
|
+
constructor(driver: Driver, log: Log);
|
|
11
12
|
init(): Promise<void>;
|
|
12
13
|
acquireConnection(): Promise<DatabaseConnection>;
|
|
13
|
-
releaseConnection(
|
|
14
|
+
releaseConnection(runtimeConnection: DatabaseConnection): Promise<void>;
|
|
14
15
|
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
|
|
15
16
|
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
16
17
|
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
@@ -8,10 +8,13 @@ exports.RuntimeDriver = void 0;
|
|
|
8
8
|
*/
|
|
9
9
|
class RuntimeDriver {
|
|
10
10
|
#driver;
|
|
11
|
+
#log;
|
|
11
12
|
#initPromise;
|
|
12
13
|
#destroyPromise;
|
|
13
|
-
|
|
14
|
+
#connections = new WeakMap();
|
|
15
|
+
constructor(driver, log) {
|
|
14
16
|
this.#driver = driver;
|
|
17
|
+
this.#log = log;
|
|
15
18
|
}
|
|
16
19
|
async init() {
|
|
17
20
|
if (!this.#initPromise) {
|
|
@@ -24,10 +27,18 @@ class RuntimeDriver {
|
|
|
24
27
|
}
|
|
25
28
|
async acquireConnection() {
|
|
26
29
|
await this.init();
|
|
27
|
-
|
|
30
|
+
const connection = await this.#driver.acquireConnection();
|
|
31
|
+
let runtimeConnection = this.#connections.get(connection);
|
|
32
|
+
if (!runtimeConnection) {
|
|
33
|
+
runtimeConnection = new RuntimeConnection(connection, this.#log);
|
|
34
|
+
this.#connections.set(connection, runtimeConnection);
|
|
35
|
+
}
|
|
36
|
+
return runtimeConnection;
|
|
28
37
|
}
|
|
29
|
-
releaseConnection(
|
|
30
|
-
|
|
38
|
+
async releaseConnection(runtimeConnection) {
|
|
39
|
+
if (runtimeConnection instanceof RuntimeConnection) {
|
|
40
|
+
await this.#driver.releaseConnection(runtimeConnection.connection);
|
|
41
|
+
}
|
|
31
42
|
}
|
|
32
43
|
beginTransaction(connection, settings) {
|
|
33
44
|
return this.#driver.beginTransaction(connection, settings);
|
|
@@ -53,3 +64,45 @@ class RuntimeDriver {
|
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
exports.RuntimeDriver = RuntimeDriver;
|
|
67
|
+
class RuntimeConnection {
|
|
68
|
+
#connection;
|
|
69
|
+
#log;
|
|
70
|
+
get connection() {
|
|
71
|
+
return this.#connection;
|
|
72
|
+
}
|
|
73
|
+
constructor(connection, log) {
|
|
74
|
+
this.#connection = connection;
|
|
75
|
+
this.#log = log;
|
|
76
|
+
}
|
|
77
|
+
async executeQuery(compiledQuery) {
|
|
78
|
+
const startTime = process.hrtime.bigint();
|
|
79
|
+
try {
|
|
80
|
+
return await this.#connection.executeQuery(compiledQuery);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
this.#logError(error);
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
this.#logQuery(compiledQuery, startTime);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
#logError(error) {
|
|
91
|
+
this.#log.error(() => ({
|
|
92
|
+
level: 'error',
|
|
93
|
+
error,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
#logQuery(compiledQuery, startTime) {
|
|
97
|
+
this.#log.query(() => ({
|
|
98
|
+
level: 'query',
|
|
99
|
+
sql: compiledQuery.sql,
|
|
100
|
+
queryDurationMillis: this.#calculateDurationMillis(startTime),
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
#calculateDurationMillis(startTime) {
|
|
104
|
+
const endTime = process.hrtime.bigint();
|
|
105
|
+
const durationNanos = Number(endTime - startTime);
|
|
106
|
+
return durationNanos / 1_000_000;
|
|
107
|
+
}
|
|
108
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ export * from './operation-node/operation-node-source.js';
|
|
|
110
110
|
export * from './operation-node/order-by-node.js';
|
|
111
111
|
export * from './introspection/database-introspector.js';
|
|
112
112
|
export * from './util/compilable.js';
|
|
113
|
-
export { AnyColumn, UnknownRow
|
|
113
|
+
export { AnyColumn, UnknownRow, AnyQueryBuilder } from './util/type-utils.js';
|
|
114
114
|
export { SelectExpression, SelectExpressionOrList, } from './parser/select-parser.js';
|
|
115
115
|
export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
|
|
116
116
|
export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
|
|
@@ -120,3 +120,4 @@ export { JoinReferenceExpression, JoinCallbackExpression, } from './parser/join-
|
|
|
120
120
|
export { InsertObject } from './parser/insert-values-parser.js';
|
|
121
121
|
export { MutationObject } from './parser/update-set-parser.js';
|
|
122
122
|
export { OrderByExpression, OrderByDirectionExpression, } from './parser/order-by-parser.js';
|
|
123
|
+
export { UnionExpression } from './parser/union-parser.js';
|
package/dist/cjs/kysely.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { DatabaseIntrospector } from './introspection/database-introspector.js';
|
|
|
10
10
|
import { Driver, IsolationLevel } from './driver/driver.js';
|
|
11
11
|
import { ParseContext } from './parser/parse-context.js';
|
|
12
12
|
import { FunctionBuilder } from './query-builder/function-builder.js';
|
|
13
|
+
import { LogLevel } from './util/log.js';
|
|
13
14
|
/**
|
|
14
15
|
* The main Kysely class.
|
|
15
16
|
*
|
|
@@ -127,15 +128,20 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
127
128
|
*/
|
|
128
129
|
get fn(): FunctionBuilder<DB, keyof DB>;
|
|
129
130
|
/**
|
|
130
|
-
*
|
|
131
|
-
* otherwise it's committed.
|
|
131
|
+
* Creates a {@link TransactionBuilder} that can be used to run queries inside a transaction.
|
|
132
132
|
*
|
|
133
|
-
* @
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
133
|
+
* The returned {@link TransactionBuilder} can be used to configure the transaction. The
|
|
134
|
+
* {@link TransactionBuilder.execute} method can then be called to run the transaction.
|
|
135
|
+
* {@link TransactionBuilder.execute} takes a function that is run inside the
|
|
136
|
+
* transaction. If the function throws, the transaction is rolled back. Otherwise
|
|
137
|
+
* the transaction is committed.
|
|
138
|
+
*
|
|
139
|
+
* The callback function passed to the {@link TransactionBuilder.execute | execute}
|
|
140
|
+
* method gets the transaction object as its only argument. The transaction is
|
|
141
|
+
* of type {@link Transaction} which inherits {@link Kysely}. Any query
|
|
142
|
+
* started through the transaction object is executed inside the transaction.
|
|
138
143
|
*
|
|
144
|
+
* @example
|
|
139
145
|
* ```ts
|
|
140
146
|
* const catto = await db.transaction().execute(async (trx) => {
|
|
141
147
|
* const jennifer = await trx.insertInto('person')
|
|
@@ -188,6 +194,10 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
188
194
|
* ```
|
|
189
195
|
*/
|
|
190
196
|
connection(): ConnectionBuilder<DB>;
|
|
197
|
+
/**
|
|
198
|
+
* Returns a copy of this Kysely instance with the given plugin installed.
|
|
199
|
+
*/
|
|
200
|
+
withPlugin(plugin: KyselyPlugin): Kysely<DB>;
|
|
191
201
|
/**
|
|
192
202
|
* Returns a copy of this Kysely instance without any plugins.
|
|
193
203
|
*/
|
|
@@ -220,8 +230,20 @@ export interface KyselyProps {
|
|
|
220
230
|
}
|
|
221
231
|
export declare function isKyselyProps(obj: unknown): obj is KyselyProps;
|
|
222
232
|
export interface KyselyConfig {
|
|
223
|
-
dialect: Dialect;
|
|
224
|
-
plugins?: KyselyPlugin[];
|
|
233
|
+
readonly dialect: Dialect;
|
|
234
|
+
readonly plugins?: KyselyPlugin[];
|
|
235
|
+
/**
|
|
236
|
+
* A list of log levels to log.
|
|
237
|
+
*
|
|
238
|
+
* Currently there's only two levels: `query` and `error`.
|
|
239
|
+
* This will be expanded based on user feedback later.
|
|
240
|
+
*
|
|
241
|
+
* Log levels:
|
|
242
|
+
*
|
|
243
|
+
* - query: Log each query's SQL and duration using console.log
|
|
244
|
+
* - error: Log all query errors using console.error
|
|
245
|
+
*/
|
|
246
|
+
readonly log?: ReadonlyArray<LogLevel>;
|
|
225
247
|
}
|
|
226
248
|
export declare class ConnectionBuilder<DB> {
|
|
227
249
|
#private;
|
package/dist/cjs/kysely.js
CHANGED
|
@@ -15,6 +15,7 @@ const driver_js_1 = require("./driver/driver.js");
|
|
|
15
15
|
const prevent_await_js_1 = require("./util/prevent-await.js");
|
|
16
16
|
const parse_context_js_1 = require("./parser/parse-context.js");
|
|
17
17
|
const function_builder_js_1 = require("./query-builder/function-builder.js");
|
|
18
|
+
const log_js_1 = require("./util/log.js");
|
|
18
19
|
/**
|
|
19
20
|
* The main Kysely class.
|
|
20
21
|
*
|
|
@@ -60,15 +61,16 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
60
61
|
constructor(args) {
|
|
61
62
|
if (isKyselyProps(args)) {
|
|
62
63
|
super({ executor: args.executor, parseContext: args.parseContext });
|
|
63
|
-
this.#props = (0, object_utils_js_1.freeze)(args);
|
|
64
|
+
this.#props = (0, object_utils_js_1.freeze)({ ...args });
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
66
67
|
const dialect = args.dialect;
|
|
67
68
|
const driver = dialect.createDriver();
|
|
68
69
|
const compiler = dialect.createQueryCompiler();
|
|
69
70
|
const adapter = dialect.createAdapter();
|
|
71
|
+
const log = new log_js_1.Log(args.log ?? []);
|
|
70
72
|
const parseContext = new parse_context_js_1.DefaultParseContext(adapter);
|
|
71
|
-
const runtimeDriver = new runtime_driver_js_1.RuntimeDriver(driver);
|
|
73
|
+
const runtimeDriver = new runtime_driver_js_1.RuntimeDriver(driver, log);
|
|
72
74
|
const connectionProvider = new default_connection_provider_js_1.DefaultConnectionProvider(runtimeDriver);
|
|
73
75
|
const executor = new default_query_executor_js_1.DefaultQueryExecutor(compiler, connectionProvider, args.plugins ?? []);
|
|
74
76
|
super({ executor, parseContext });
|
|
@@ -166,15 +168,20 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
166
168
|
return new function_builder_js_1.FunctionBuilder({ executor: this.#props.executor });
|
|
167
169
|
}
|
|
168
170
|
/**
|
|
169
|
-
*
|
|
170
|
-
* otherwise it's committed.
|
|
171
|
+
* Creates a {@link TransactionBuilder} that can be used to run queries inside a transaction.
|
|
171
172
|
*
|
|
172
|
-
* @
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
173
|
+
* The returned {@link TransactionBuilder} can be used to configure the transaction. The
|
|
174
|
+
* {@link TransactionBuilder.execute} method can then be called to run the transaction.
|
|
175
|
+
* {@link TransactionBuilder.execute} takes a function that is run inside the
|
|
176
|
+
* transaction. If the function throws, the transaction is rolled back. Otherwise
|
|
177
|
+
* the transaction is committed.
|
|
178
|
+
*
|
|
179
|
+
* The callback function passed to the {@link TransactionBuilder.execute | execute}
|
|
180
|
+
* method gets the transaction object as its only argument. The transaction is
|
|
181
|
+
* of type {@link Transaction} which inherits {@link Kysely}. Any query
|
|
182
|
+
* started through the transaction object is executed inside the transaction.
|
|
177
183
|
*
|
|
184
|
+
* @example
|
|
178
185
|
* ```ts
|
|
179
186
|
* const catto = await db.transaction().execute(async (trx) => {
|
|
180
187
|
* const jennifer = await trx.insertInto('person')
|
|
@@ -231,6 +238,15 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
231
238
|
connection() {
|
|
232
239
|
return new ConnectionBuilder({ ...this.#props });
|
|
233
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Returns a copy of this Kysely instance with the given plugin installed.
|
|
243
|
+
*/
|
|
244
|
+
withPlugin(plugin) {
|
|
245
|
+
return new Kysely({
|
|
246
|
+
...this.#props,
|
|
247
|
+
executor: this.#props.executor.withPlugin(plugin),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
234
250
|
/**
|
|
235
251
|
* Returns a copy of this Kysely instance without any plugins.
|
|
236
252
|
*/
|
|
@@ -24,6 +24,38 @@ export declare class MigrationModule {
|
|
|
24
24
|
* path.join(__dirname, 'migrations')
|
|
25
25
|
* )
|
|
26
26
|
* ```
|
|
27
|
+
*
|
|
28
|
+
* In the next example, we use a record of migration objects instead of file folder path.
|
|
29
|
+
* The keys in the object are migration names that can be anything you want. The order of
|
|
30
|
+
* the migrations is determined based on the alphabetical order of the keys in the record.
|
|
31
|
+
* This can be useful if you are using a bundler like webpack or esbuild.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* await db.migration.migrateToLatest({
|
|
36
|
+
* migration1: {
|
|
37
|
+
* async up(db: Kysely<any>): Promise<void> {
|
|
38
|
+
* ...
|
|
39
|
+
* },
|
|
40
|
+
*
|
|
41
|
+
* async down(db: Kysely<any>): Promise<void> {
|
|
42
|
+
* ...
|
|
43
|
+
* }
|
|
44
|
+
* },
|
|
45
|
+
*
|
|
46
|
+
* migration2: {
|
|
47
|
+
* async up(db: Kysely<any>): Promise<void> {
|
|
48
|
+
* ...
|
|
49
|
+
* },
|
|
50
|
+
*
|
|
51
|
+
* async down(db: Kysely<any>): Promise<void> {
|
|
52
|
+
* ...
|
|
53
|
+
* }
|
|
54
|
+
* },
|
|
55
|
+
*
|
|
56
|
+
* ...
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
27
59
|
*/
|
|
28
60
|
migrateToLatest(migrationsFolderPath: string): Promise<void>;
|
|
29
61
|
migrateToLatest(allMigrations: Record<string, Migration>): Promise<void>;
|
|
@@ -57,6 +57,7 @@ import { ForeignKeyConstraintNode } from './foreign-key-constraint-node.js';
|
|
|
57
57
|
import { ColumnDefinitionNode } from './column-definition-node.js';
|
|
58
58
|
import { ModifyColumnNode } from './modify-column-node.js';
|
|
59
59
|
import { OnDuplicateKeyNode } from './on-duplicate-key-node.js';
|
|
60
|
+
import { UnionNode } from './union-node.js';
|
|
60
61
|
/**
|
|
61
62
|
* Transforms an operation node tree into another one.
|
|
62
63
|
*
|
|
@@ -129,6 +130,7 @@ export declare class OperationNodeTransformer {
|
|
|
129
130
|
protected transformPrimaryKeyConstraint(node: PrimaryKeyConstraintNode): PrimaryKeyConstraintNode;
|
|
130
131
|
protected transformUniqueConstraint(node: UniqueConstraintNode): UniqueConstraintNode;
|
|
131
132
|
protected transformForeignKeyConstraint(node: ForeignKeyConstraintNode): ForeignKeyConstraintNode;
|
|
133
|
+
protected transformUnion(node: UnionNode): UnionNode;
|
|
132
134
|
protected transformReferences(node: ReferencesNode): ReferencesNode;
|
|
133
135
|
protected transformCheckConstraint(node: CheckConstraintNode): CheckConstraintNode;
|
|
134
136
|
protected transformWith(node: WithNode): WithNode;
|
|
@@ -92,6 +92,7 @@ class OperationNodeTransformer {
|
|
|
92
92
|
AddConstraintNode: this.transformAddConstraint.bind(this),
|
|
93
93
|
DropConstraintNode: this.transformDropConstraint.bind(this),
|
|
94
94
|
ForeignKeyConstraintNode: this.transformForeignKeyConstraint.bind(this),
|
|
95
|
+
UnionNode: this.transformUnion.bind(this),
|
|
95
96
|
};
|
|
96
97
|
transformNode = (node) => {
|
|
97
98
|
if (!node) {
|
|
@@ -124,6 +125,7 @@ class OperationNodeTransformer {
|
|
|
124
125
|
offset: this.transformNode(node.offset),
|
|
125
126
|
with: this.transformNode(node.with),
|
|
126
127
|
having: this.transformNode(node.having),
|
|
128
|
+
union: this.transformNodeList(node.union),
|
|
127
129
|
};
|
|
128
130
|
}
|
|
129
131
|
transformSelection(node) {
|
|
@@ -403,6 +405,13 @@ class OperationNodeTransformer {
|
|
|
403
405
|
onUpdate: node.onUpdate,
|
|
404
406
|
};
|
|
405
407
|
}
|
|
408
|
+
transformUnion(node) {
|
|
409
|
+
return {
|
|
410
|
+
kind: 'UnionNode',
|
|
411
|
+
union: this.transformNode(node.union),
|
|
412
|
+
all: node.all,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
406
415
|
transformReferences(node) {
|
|
407
416
|
return {
|
|
408
417
|
kind: 'ReferencesNode',
|
|
@@ -57,66 +57,68 @@ import { ForeignKeyConstraintNode } from './foreign-key-constraint-node.js';
|
|
|
57
57
|
import { ColumnDefinitionNode } from './column-definition-node.js';
|
|
58
58
|
import { ModifyColumnNode } from './modify-column-node.js';
|
|
59
59
|
import { OnDuplicateKeyNode } from './on-duplicate-key-node.js';
|
|
60
|
-
|
|
60
|
+
import { UnionNode } from './union-node.js';
|
|
61
|
+
export declare abstract class OperationNodeVisitor {
|
|
61
62
|
#private;
|
|
62
63
|
protected readonly nodeStack: OperationNode[];
|
|
63
64
|
protected readonly visitNode: (node: OperationNode) => void;
|
|
64
|
-
protected visitSelectQuery(node: SelectQueryNode): void;
|
|
65
|
-
protected visitSelection(node: SelectionNode): void;
|
|
66
|
-
protected visitColumn(node: ColumnNode): void;
|
|
67
|
-
protected visitAlias(node: AliasNode): void;
|
|
68
|
-
protected visitTable(node: TableNode): void;
|
|
69
|
-
protected visitFrom(node: FromNode): void;
|
|
70
|
-
protected visitReference(node: ReferenceNode): void;
|
|
71
|
-
protected visitFilter(node: FilterNode): void;
|
|
72
|
-
protected visitAnd(node: AndNode): void;
|
|
73
|
-
protected visitOr(node: OrNode): void;
|
|
74
|
-
protected visitValueList(node: ValueListNode): void;
|
|
75
|
-
protected visitParens(node: ParensNode): void;
|
|
76
|
-
protected visitJoin(node: JoinNode): void;
|
|
77
|
-
protected visitRaw(node: RawNode): void;
|
|
78
|
-
protected visitWhere(node: WhereNode): void;
|
|
79
|
-
protected visitInsertQuery(node: InsertQueryNode): void;
|
|
80
|
-
protected visitDeleteQuery(node: DeleteQueryNode): void;
|
|
81
|
-
protected visitReturning(node: ReturningNode): void;
|
|
82
|
-
protected visitCreateTable(node: CreateTableNode): void;
|
|
83
|
-
protected visitAddColumn(node: AddColumnNode): void;
|
|
84
|
-
protected visitColumnDefinition(node: ColumnDefinitionNode): void;
|
|
85
|
-
protected visitDropTable(node: DropTableNode): void;
|
|
86
|
-
protected visitOrderBy(node: OrderByNode): void;
|
|
87
|
-
protected visitOrderByItem(node: OrderByItemNode): void;
|
|
88
|
-
protected visitGroupBy(node: GroupByNode): void;
|
|
89
|
-
protected visitGroupByItem(node: GroupByItemNode): void;
|
|
90
|
-
protected visitUpdateQuery(node: UpdateQueryNode): void;
|
|
91
|
-
protected visitColumnUpdate(node: ColumnUpdateNode): void;
|
|
92
|
-
protected visitLimit(node: LimitNode): void;
|
|
93
|
-
protected visitOffset(node: OffsetNode): void;
|
|
94
|
-
protected visitOnConflict(node: OnConflictNode): void;
|
|
95
|
-
protected visitOnDuplicateKey(node: OnDuplicateKeyNode): void;
|
|
96
|
-
protected visitCreateIndex(node: CreateIndexNode): void;
|
|
97
|
-
protected
|
|
98
|
-
protected
|
|
99
|
-
protected visitPrimaryKeyConstraint(node: PrimaryKeyConstraintNode): void;
|
|
100
|
-
protected visitUniqueConstraint(node: UniqueConstraintNode): void;
|
|
101
|
-
protected visitReferences(node: ReferencesNode): void;
|
|
102
|
-
protected visitCheckConstraint(node: CheckConstraintNode): void;
|
|
103
|
-
protected visitWith(node: WithNode): void;
|
|
104
|
-
protected visitCommonTableExpression(node: CommonTableExpressionNode): void;
|
|
105
|
-
protected visitHaving(node: HavingNode): void;
|
|
106
|
-
protected visitCreateSchema(node: CreateSchemaNode): void;
|
|
107
|
-
protected visitDropSchema(node: DropSchemaNode): void;
|
|
108
|
-
protected visitAlterTable(node: AlterTableNode): void;
|
|
109
|
-
protected visitDropColumn(node: DropColumnNode): void;
|
|
110
|
-
protected visitRenameColumn(node: RenameColumnNode): void;
|
|
111
|
-
protected visitAlterColumn(node: AlterColumnNode): void;
|
|
112
|
-
protected visitModifyColumn(node: ModifyColumnNode): void;
|
|
113
|
-
protected visitAddConstraint(node: AddConstraintNode): void;
|
|
114
|
-
protected visitDropConstraint(node: DropConstraintNode): void;
|
|
115
|
-
protected visitForeignKeyConstraint(node: ForeignKeyConstraintNode): void;
|
|
116
|
-
protected
|
|
117
|
-
protected
|
|
118
|
-
protected
|
|
119
|
-
protected
|
|
120
|
-
protected
|
|
121
|
-
protected
|
|
65
|
+
protected abstract visitSelectQuery(node: SelectQueryNode): void;
|
|
66
|
+
protected abstract visitSelection(node: SelectionNode): void;
|
|
67
|
+
protected abstract visitColumn(node: ColumnNode): void;
|
|
68
|
+
protected abstract visitAlias(node: AliasNode): void;
|
|
69
|
+
protected abstract visitTable(node: TableNode): void;
|
|
70
|
+
protected abstract visitFrom(node: FromNode): void;
|
|
71
|
+
protected abstract visitReference(node: ReferenceNode): void;
|
|
72
|
+
protected abstract visitFilter(node: FilterNode): void;
|
|
73
|
+
protected abstract visitAnd(node: AndNode): void;
|
|
74
|
+
protected abstract visitOr(node: OrNode): void;
|
|
75
|
+
protected abstract visitValueList(node: ValueListNode): void;
|
|
76
|
+
protected abstract visitParens(node: ParensNode): void;
|
|
77
|
+
protected abstract visitJoin(node: JoinNode): void;
|
|
78
|
+
protected abstract visitRaw(node: RawNode): void;
|
|
79
|
+
protected abstract visitWhere(node: WhereNode): void;
|
|
80
|
+
protected abstract visitInsertQuery(node: InsertQueryNode): void;
|
|
81
|
+
protected abstract visitDeleteQuery(node: DeleteQueryNode): void;
|
|
82
|
+
protected abstract visitReturning(node: ReturningNode): void;
|
|
83
|
+
protected abstract visitCreateTable(node: CreateTableNode): void;
|
|
84
|
+
protected abstract visitAddColumn(node: AddColumnNode): void;
|
|
85
|
+
protected abstract visitColumnDefinition(node: ColumnDefinitionNode): void;
|
|
86
|
+
protected abstract visitDropTable(node: DropTableNode): void;
|
|
87
|
+
protected abstract visitOrderBy(node: OrderByNode): void;
|
|
88
|
+
protected abstract visitOrderByItem(node: OrderByItemNode): void;
|
|
89
|
+
protected abstract visitGroupBy(node: GroupByNode): void;
|
|
90
|
+
protected abstract visitGroupByItem(node: GroupByItemNode): void;
|
|
91
|
+
protected abstract visitUpdateQuery(node: UpdateQueryNode): void;
|
|
92
|
+
protected abstract visitColumnUpdate(node: ColumnUpdateNode): void;
|
|
93
|
+
protected abstract visitLimit(node: LimitNode): void;
|
|
94
|
+
protected abstract visitOffset(node: OffsetNode): void;
|
|
95
|
+
protected abstract visitOnConflict(node: OnConflictNode): void;
|
|
96
|
+
protected abstract visitOnDuplicateKey(node: OnDuplicateKeyNode): void;
|
|
97
|
+
protected abstract visitCreateIndex(node: CreateIndexNode): void;
|
|
98
|
+
protected abstract visitDropIndex(node: DropIndexNode): void;
|
|
99
|
+
protected abstract visitList(node: ListNode): void;
|
|
100
|
+
protected abstract visitPrimaryKeyConstraint(node: PrimaryKeyConstraintNode): void;
|
|
101
|
+
protected abstract visitUniqueConstraint(node: UniqueConstraintNode): void;
|
|
102
|
+
protected abstract visitReferences(node: ReferencesNode): void;
|
|
103
|
+
protected abstract visitCheckConstraint(node: CheckConstraintNode): void;
|
|
104
|
+
protected abstract visitWith(node: WithNode): void;
|
|
105
|
+
protected abstract visitCommonTableExpression(node: CommonTableExpressionNode): void;
|
|
106
|
+
protected abstract visitHaving(node: HavingNode): void;
|
|
107
|
+
protected abstract visitCreateSchema(node: CreateSchemaNode): void;
|
|
108
|
+
protected abstract visitDropSchema(node: DropSchemaNode): void;
|
|
109
|
+
protected abstract visitAlterTable(node: AlterTableNode): void;
|
|
110
|
+
protected abstract visitDropColumn(node: DropColumnNode): void;
|
|
111
|
+
protected abstract visitRenameColumn(node: RenameColumnNode): void;
|
|
112
|
+
protected abstract visitAlterColumn(node: AlterColumnNode): void;
|
|
113
|
+
protected abstract visitModifyColumn(node: ModifyColumnNode): void;
|
|
114
|
+
protected abstract visitAddConstraint(node: AddConstraintNode): void;
|
|
115
|
+
protected abstract visitDropConstraint(node: DropConstraintNode): void;
|
|
116
|
+
protected abstract visitForeignKeyConstraint(node: ForeignKeyConstraintNode): void;
|
|
117
|
+
protected abstract visitUnion(node: UnionNode): void;
|
|
118
|
+
protected abstract visitDataType(node: DataTypeNode): void;
|
|
119
|
+
protected abstract visitSelectAll(_: SelectAllNode): void;
|
|
120
|
+
protected abstract visitIdentifier(_: IdentifierNode): void;
|
|
121
|
+
protected abstract visitValue(_: ValueNode): void;
|
|
122
|
+
protected abstract visitPrimitiveValueList(_: PrimitiveValueListNode): void;
|
|
123
|
+
protected abstract visitOperator(node: OperatorNode): void;
|
|
122
124
|
}
|