kysely 0.9.0 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +9 -0
- package/dist/cjs/dialect/mysql/mysql-dialect.js +7 -0
- package/dist/cjs/dialect/mysql/mysql-driver.js +2 -2
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +11 -1
- package/dist/cjs/dialect/postgres/postgres-dialect.js +10 -0
- package/dist/cjs/driver/runtime-driver.d.ts +3 -2
- package/dist/cjs/driver/runtime-driver.js +43 -4
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/kysely.d.ts +26 -9
- package/dist/cjs/kysely.js +16 -9
- package/dist/cjs/migration/migration.d.ts +32 -0
- package/dist/cjs/operation-node/create-schema-node.d.ts +1 -1
- package/dist/cjs/operation-node/create-schema-node.js +2 -2
- package/dist/cjs/operation-node/create-table-node.d.ts +1 -5
- package/dist/cjs/operation-node/create-table-node.js +1 -31
- package/dist/cjs/operation-node/join-node.d.ts +2 -1
- package/dist/cjs/operation-node/join-node.js +8 -6
- package/dist/cjs/operation-node/operation-node-source.d.ts +1 -1
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +11 -1
- 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/query-node.d.ts +4 -3
- package/dist/cjs/operation-node/query-node.js +10 -2
- package/dist/cjs/operation-node/select-query-node.d.ts +5 -1
- package/dist/cjs/operation-node/select-query-node.js +18 -2
- 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/group-by-parser.d.ts +4 -0
- package/dist/cjs/parser/group-by-parser.js +9 -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/order-by-parser.d.ts +2 -4
- package/dist/cjs/parser/order-by-parser.js +6 -3
- package/dist/cjs/parser/reference-parser.d.ts +1 -1
- package/dist/cjs/parser/reference-parser.js +1 -1
- 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/query-builder/join-builder.js +8 -8
- package/dist/cjs/query-builder/query-builder.d.ts +65 -1
- package/dist/cjs/query-builder/query-builder.js +103 -22
- package/dist/cjs/query-compiler/compiled-query.d.ts +1 -1
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +7 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +21 -4
- package/dist/cjs/schema/create-schema-builder.js +1 -1
- package/dist/cjs/schema/create-table-builder.js +7 -4
- package/dist/cjs/util/log.d.ts +8 -0
- package/dist/cjs/util/log.js +21 -0
- package/dist/cjs/util/object-utils.d.ts +11 -11
- package/dist/cjs/util/object-utils.js +1 -1
- 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 +9 -0
- package/dist/esm/dialect/mysql/mysql-dialect.js +7 -0
- package/dist/esm/dialect/mysql/mysql-driver.js +3 -3
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +11 -1
- package/dist/esm/dialect/postgres/postgres-dialect.js +10 -0
- package/dist/esm/driver/runtime-driver.d.ts +3 -2
- package/dist/esm/driver/runtime-driver.js +43 -4
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/kysely.d.ts +26 -9
- package/dist/esm/kysely.js +16 -9
- package/dist/esm/migration/migration.d.ts +32 -0
- package/dist/esm/operation-node/create-schema-node.d.ts +1 -1
- package/dist/esm/operation-node/create-schema-node.js +2 -2
- package/dist/esm/operation-node/create-table-node.d.ts +1 -5
- package/dist/esm/operation-node/create-table-node.js +1 -31
- package/dist/esm/operation-node/join-node.d.ts +2 -1
- package/dist/esm/operation-node/join-node.js +8 -6
- package/dist/esm/operation-node/operation-node-source.d.ts +1 -1
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +11 -1
- 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/query-node.d.ts +4 -3
- package/dist/esm/operation-node/query-node.js +10 -2
- package/dist/esm/operation-node/select-query-node.d.ts +5 -1
- package/dist/esm/operation-node/select-query-node.js +18 -2
- 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/group-by-parser.d.ts +4 -0
- package/dist/esm/parser/group-by-parser.js +5 -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/order-by-parser.d.ts +2 -4
- package/dist/esm/parser/order-by-parser.js +6 -2
- package/dist/esm/parser/reference-parser.d.ts +1 -1
- package/dist/esm/parser/reference-parser.js +2 -2
- 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/query-builder/join-builder.js +8 -8
- package/dist/esm/query-builder/query-builder.d.ts +65 -1
- package/dist/esm/query-builder/query-builder.js +104 -23
- package/dist/esm/query-compiler/compiled-query.d.ts +1 -1
- package/dist/esm/query-compiler/default-query-compiler.d.ts +7 -2
- package/dist/esm/query-compiler/default-query-compiler.js +21 -4
- package/dist/esm/schema/create-schema-builder.js +1 -1
- package/dist/esm/schema/create-table-builder.js +7 -4
- package/dist/esm/util/log.d.ts +8 -0
- package/dist/esm/util/log.js +17 -0
- package/dist/esm/util/object-utils.d.ts +11 -11
- package/dist/esm/util/object-utils.js +1 -1
- 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
|
/**
|
|
@@ -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) {
|
|
@@ -107,13 +107,13 @@ class MysqlConnection {
|
|
|
107
107
|
async executeQuery(compiledQuery) {
|
|
108
108
|
const result = await this.#executeQuery(compiledQuery);
|
|
109
109
|
if ((0, object_utils_js_1.isObject)(result) && 'insertId' in result && 'affectedRows' in result) {
|
|
110
|
-
if (result.insertId) {
|
|
110
|
+
if ((0, object_utils_js_1.isNumber)(result.insertId) && result.insertId > 0) {
|
|
111
111
|
return {
|
|
112
112
|
insertedPrimaryKey: result.insertId,
|
|
113
113
|
rows: [],
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
-
else {
|
|
116
|
+
else if ((0, object_utils_js_1.isNumber)(result.affectedRows)) {
|
|
117
117
|
return {
|
|
118
118
|
numUpdatedOrDeletedRows: result.affectedRows,
|
|
119
119
|
rows: [],
|
|
@@ -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
|
|
@@ -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) {
|
|
@@ -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,31 @@ 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
|
+
finally {
|
|
83
|
+
this.#log.query((log) => {
|
|
84
|
+
log(compiledQuery.sql);
|
|
85
|
+
log(`duration: ${this.#calculateDurationMillis(startTime)}ms`);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
#calculateDurationMillis(startTime) {
|
|
90
|
+
const endTime = process.hrtime.bigint();
|
|
91
|
+
const durationTensMillis = Number((endTime - startTime) / 100000n);
|
|
92
|
+
return durationTensMillis / 10;
|
|
93
|
+
}
|
|
94
|
+
}
|
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';
|
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')
|
|
@@ -220,8 +226,19 @@ export interface KyselyProps {
|
|
|
220
226
|
}
|
|
221
227
|
export declare function isKyselyProps(obj: unknown): obj is KyselyProps;
|
|
222
228
|
export interface KyselyConfig {
|
|
223
|
-
dialect: Dialect;
|
|
224
|
-
plugins?: KyselyPlugin[];
|
|
229
|
+
readonly dialect: Dialect;
|
|
230
|
+
readonly plugins?: KyselyPlugin[];
|
|
231
|
+
/**
|
|
232
|
+
* A list of log levels to log.
|
|
233
|
+
*
|
|
234
|
+
* Currently there's only one level: `query` and it's logged using
|
|
235
|
+
* `console.log`. This will be expanded based on user request later.
|
|
236
|
+
*
|
|
237
|
+
* Log levels:
|
|
238
|
+
*
|
|
239
|
+
* - query: Log each query's SQL and duration.
|
|
240
|
+
*/
|
|
241
|
+
readonly log?: ReadonlyArray<LogLevel>;
|
|
225
242
|
}
|
|
226
243
|
export declare class ConnectionBuilder<DB> {
|
|
227
244
|
#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')
|
|
@@ -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>;
|
|
@@ -13,5 +13,5 @@ export interface CreateSchemaNode extends OperationNode {
|
|
|
13
13
|
export declare const CreateSchemaNode: Readonly<{
|
|
14
14
|
is(node: OperationNode): node is CreateSchemaNode;
|
|
15
15
|
create(schema: string, params?: CreateSchemaNodeParams | undefined): CreateSchemaNode;
|
|
16
|
-
|
|
16
|
+
cloneWith(createSchema: CreateSchemaNode, params: CreateSchemaNodeParams): CreateSchemaNode;
|
|
17
17
|
}>;
|
|
@@ -17,10 +17,10 @@ exports.CreateSchemaNode = (0, object_utils_js_1.freeze)({
|
|
|
17
17
|
...params,
|
|
18
18
|
});
|
|
19
19
|
},
|
|
20
|
-
|
|
20
|
+
cloneWith(createSchema, params) {
|
|
21
21
|
return (0, object_utils_js_1.freeze)({
|
|
22
22
|
...createSchema,
|
|
23
|
-
|
|
23
|
+
...params,
|
|
24
24
|
});
|
|
25
25
|
},
|
|
26
26
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
2
|
import { TableNode } from './table-node.js';
|
|
3
|
-
import { ForeignKeyConstraintNode } from './foreign-key-constraint-node.js';
|
|
4
3
|
import { ConstraintNode } from './constraint-node.js';
|
|
5
4
|
import { ColumnDefinitionNode } from './column-definition-node.js';
|
|
6
5
|
export declare type CreateTableNodeModifier = 'IfNotExists';
|
|
@@ -19,8 +18,5 @@ export declare const CreateTableNode: Readonly<{
|
|
|
19
18
|
create(table: TableNode): CreateTableNode;
|
|
20
19
|
cloneWithColumn(createTable: CreateTableNode, column: ColumnDefinitionNode): CreateTableNode;
|
|
21
20
|
cloneWithModifier(createTable: CreateTableNode, modifier: CreateTableNodeModifier): CreateTableNode;
|
|
22
|
-
|
|
23
|
-
cloneWithUniqueConstraint(createTable: CreateTableNode, constraintName: string, columns: string[]): CreateTableNode;
|
|
24
|
-
cloneWithCheckConstraint(createTable: CreateTableNode, constraintName: string, sql: string): CreateTableNode;
|
|
25
|
-
cloneWithForeignKeyConstraint(createTable: CreateTableNode, constraint: ForeignKeyConstraintNode): CreateTableNode;
|
|
21
|
+
cloneWithConstraint(createTable: CreateTableNode, constraint: ConstraintNode): CreateTableNode;
|
|
26
22
|
}>;
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateTableNode = void 0;
|
|
4
4
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
5
|
-
const check_constraint_node_js_1 = require("./check-constraint-node.js");
|
|
6
|
-
const primary_constraint_node_js_1 = require("./primary-constraint-node.js");
|
|
7
|
-
const unique_constraint_node_js_1 = require("./unique-constraint-node.js");
|
|
8
5
|
/**
|
|
9
6
|
* @internal
|
|
10
7
|
*/
|
|
@@ -31,34 +28,7 @@ exports.CreateTableNode = (0, object_utils_js_1.freeze)({
|
|
|
31
28
|
modifier,
|
|
32
29
|
});
|
|
33
30
|
},
|
|
34
|
-
|
|
35
|
-
const constraint = primary_constraint_node_js_1.PrimaryConstraintNode.create(columns, constraintName);
|
|
36
|
-
return (0, object_utils_js_1.freeze)({
|
|
37
|
-
...createTable,
|
|
38
|
-
constraints: createTable.constraints
|
|
39
|
-
? (0, object_utils_js_1.freeze)([...createTable.constraints, constraint])
|
|
40
|
-
: (0, object_utils_js_1.freeze)([constraint]),
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
cloneWithUniqueConstraint(createTable, constraintName, columns) {
|
|
44
|
-
const constraint = unique_constraint_node_js_1.UniqueConstraintNode.create(columns, constraintName);
|
|
45
|
-
return (0, object_utils_js_1.freeze)({
|
|
46
|
-
...createTable,
|
|
47
|
-
constraints: createTable.constraints
|
|
48
|
-
? (0, object_utils_js_1.freeze)([...createTable.constraints, constraint])
|
|
49
|
-
: (0, object_utils_js_1.freeze)([constraint]),
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
cloneWithCheckConstraint(createTable, constraintName, sql) {
|
|
53
|
-
const constraint = check_constraint_node_js_1.CheckConstraintNode.create(sql, constraintName);
|
|
54
|
-
return (0, object_utils_js_1.freeze)({
|
|
55
|
-
...createTable,
|
|
56
|
-
constraints: createTable.constraints
|
|
57
|
-
? (0, object_utils_js_1.freeze)([...createTable.constraints, constraint])
|
|
58
|
-
: (0, object_utils_js_1.freeze)([constraint]),
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
cloneWithForeignKeyConstraint(createTable, constraint) {
|
|
31
|
+
cloneWithConstraint(createTable, constraint) {
|
|
62
32
|
return (0, object_utils_js_1.freeze)({
|
|
63
33
|
...createTable,
|
|
64
34
|
constraints: createTable.constraints
|
|
@@ -21,5 +21,6 @@ export declare const JoinNode: Readonly<{
|
|
|
21
21
|
is(node: OperationNode): node is JoinNode;
|
|
22
22
|
create(joinType: JoinType, table: JoinTableNode): JoinNode;
|
|
23
23
|
createWithOn(joinType: JoinType, table: JoinTableNode, on: JoinNodeOnNode): JoinNode;
|
|
24
|
-
cloneWithOn(joinNode: JoinNode,
|
|
24
|
+
cloneWithOn(joinNode: JoinNode, on: JoinNodeOnNode): JoinNode;
|
|
25
|
+
cloneWithOrOn(joinNode: JoinNode, on: JoinNodeOnNode): JoinNode;
|
|
25
26
|
}>;
|
|
@@ -27,14 +27,16 @@ exports.JoinNode = (0, object_utils_js_1.freeze)({
|
|
|
27
27
|
on,
|
|
28
28
|
});
|
|
29
29
|
},
|
|
30
|
-
cloneWithOn(joinNode,
|
|
30
|
+
cloneWithOn(joinNode, on) {
|
|
31
31
|
return (0, object_utils_js_1.freeze)({
|
|
32
32
|
...joinNode,
|
|
33
|
-
on: joinNode.on
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
on: joinNode.on ? and_node_js_1.AndNode.create(joinNode.on, on) : on,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
cloneWithOrOn(joinNode, on) {
|
|
37
|
+
return (0, object_utils_js_1.freeze)({
|
|
38
|
+
...joinNode,
|
|
39
|
+
on: joinNode.on ? or_node_js_1.OrNode.create(joinNode.on, on) : on,
|
|
38
40
|
});
|
|
39
41
|
},
|
|
40
42
|
});
|
|
@@ -2,4 +2,4 @@ import { OperationNode } from './operation-node.js';
|
|
|
2
2
|
export interface OperationNodeSource {
|
|
3
3
|
toOperationNode(): OperationNode;
|
|
4
4
|
}
|
|
5
|
-
export declare function isOperationNodeSource(obj:
|
|
5
|
+
export declare function isOperationNodeSource(obj: unknown): obj is OperationNodeSource;
|
|
@@ -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',
|
|
@@ -456,11 +465,12 @@ class OperationNodeTransformer {
|
|
|
456
465
|
kind: 'AlterTableNode',
|
|
457
466
|
table: this.transformNode(node.table),
|
|
458
467
|
renameTo: this.transformNode(node.renameTo),
|
|
459
|
-
renameColumn: this.transformNode(node.renameColumn),
|
|
460
468
|
setSchema: this.transformNode(node.setSchema),
|
|
469
|
+
renameColumn: this.transformNode(node.renameColumn),
|
|
461
470
|
addColumn: this.transformNode(node.addColumn),
|
|
462
471
|
dropColumn: this.transformNode(node.dropColumn),
|
|
463
472
|
alterColumn: this.transformNode(node.alterColumn),
|
|
473
|
+
modifyColumn: this.transformNode(node.modifyColumn),
|
|
464
474
|
addConstraint: this.transformNode(node.addConstraint),
|
|
465
475
|
dropConstraint: this.transformNode(node.dropConstraint),
|
|
466
476
|
};
|