kysely 0.16.5 → 0.16.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/driver/dummy-driver.d.ts +40 -0
- package/dist/cjs/driver/dummy-driver.js +34 -0
- package/dist/cjs/driver/runtime-driver.d.ts +1 -1
- package/dist/cjs/driver/runtime-driver.js +30 -33
- package/dist/cjs/index-nodeless.d.ts +1 -0
- package/dist/cjs/index-nodeless.js +1 -0
- package/dist/cjs/util/log.d.ts +1 -0
- package/dist/cjs/util/log.js +3 -0
- package/dist/esm/driver/dummy-driver.d.ts +40 -0
- package/dist/esm/driver/dummy-driver.js +31 -0
- package/dist/esm/driver/runtime-driver.d.ts +1 -1
- package/dist/esm/driver/runtime-driver.js +29 -32
- package/dist/esm/index-nodeless.d.ts +1 -0
- package/dist/esm/index-nodeless.js +1 -0
- package/dist/esm/util/log.d.ts +1 -0
- package/dist/esm/util/log.js +3 -0
- package/package.json +9 -5
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DatabaseConnection } from './database-connection.js';
|
|
2
|
+
import { Driver } from './driver.js';
|
|
3
|
+
export declare class DummyDriver implements Driver {
|
|
4
|
+
/**
|
|
5
|
+
* Initializes the driver.
|
|
6
|
+
*
|
|
7
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
8
|
+
* methods should be callable.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
11
|
+
* should be imported inside this function, not at the top of the driver file! This is
|
|
12
|
+
* important so that Kysely is usable without installing all database driver libraries
|
|
13
|
+
* it supports.
|
|
14
|
+
*/
|
|
15
|
+
init(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Acquires a new connection from the pool.
|
|
18
|
+
*/
|
|
19
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
20
|
+
/**
|
|
21
|
+
* Begins a transaction.
|
|
22
|
+
*/
|
|
23
|
+
beginTransaction(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Commits a transaction.
|
|
26
|
+
*/
|
|
27
|
+
commitTransaction(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Rolls back a transaction.
|
|
30
|
+
*/
|
|
31
|
+
rollbackTransaction(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Releases a connection back to the pool.
|
|
34
|
+
*/
|
|
35
|
+
releaseConnection(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Destroys the driver and releases all resources.
|
|
38
|
+
*/
|
|
39
|
+
destroy(): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DummyDriver = void 0;
|
|
4
|
+
class DummyDriver {
|
|
5
|
+
init() {
|
|
6
|
+
throw new Error('Method not implemented.');
|
|
7
|
+
}
|
|
8
|
+
async acquireConnection() {
|
|
9
|
+
return new DummyConnection();
|
|
10
|
+
}
|
|
11
|
+
async beginTransaction() {
|
|
12
|
+
// Nothing to do here.
|
|
13
|
+
}
|
|
14
|
+
async commitTransaction() {
|
|
15
|
+
// Nothing to do here.
|
|
16
|
+
}
|
|
17
|
+
async rollbackTransaction() {
|
|
18
|
+
// Nothing to do here.
|
|
19
|
+
}
|
|
20
|
+
async releaseConnection() {
|
|
21
|
+
// Nothing to do here.
|
|
22
|
+
}
|
|
23
|
+
async destroy() {
|
|
24
|
+
// Nothing to do here.
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.DummyDriver = DummyDriver;
|
|
28
|
+
class DummyConnection {
|
|
29
|
+
async executeQuery(compiledQuery) {
|
|
30
|
+
return {
|
|
31
|
+
rows: [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -28,7 +28,7 @@ export declare class RuntimeDriver implements Driver {
|
|
|
28
28
|
/**
|
|
29
29
|
* Releases a connection back to the pool.
|
|
30
30
|
*/
|
|
31
|
-
releaseConnection(
|
|
31
|
+
releaseConnection(connection: DatabaseConnection): Promise<void>;
|
|
32
32
|
/**
|
|
33
33
|
* Begins a transaction.
|
|
34
34
|
*/
|
|
@@ -12,7 +12,7 @@ class RuntimeDriver {
|
|
|
12
12
|
#log;
|
|
13
13
|
#initPromise;
|
|
14
14
|
#destroyPromise;
|
|
15
|
-
#connections = new
|
|
15
|
+
#connections = new WeakSet();
|
|
16
16
|
constructor(driver, log) {
|
|
17
17
|
this.#driver = driver;
|
|
18
18
|
this.#log = log;
|
|
@@ -29,17 +29,16 @@ class RuntimeDriver {
|
|
|
29
29
|
async acquireConnection() {
|
|
30
30
|
await this.init();
|
|
31
31
|
const connection = await this.#driver.acquireConnection();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
if (!this.#connections.has(connection)) {
|
|
33
|
+
if (this.#needsLogging()) {
|
|
34
|
+
this.#addLogging(connection);
|
|
35
|
+
}
|
|
36
|
+
this.#connections.add(connection);
|
|
36
37
|
}
|
|
37
|
-
return
|
|
38
|
+
return connection;
|
|
38
39
|
}
|
|
39
|
-
async releaseConnection(
|
|
40
|
-
|
|
41
|
-
await this.#driver.releaseConnection(runtimeConnection.connection);
|
|
42
|
-
}
|
|
40
|
+
async releaseConnection(connection) {
|
|
41
|
+
await this.#driver.releaseConnection(connection);
|
|
43
42
|
}
|
|
44
43
|
beginTransaction(connection, settings) {
|
|
45
44
|
return this.#driver.beginTransaction(connection, settings);
|
|
@@ -63,30 +62,27 @@ class RuntimeDriver {
|
|
|
63
62
|
}
|
|
64
63
|
await this.#destroyPromise;
|
|
65
64
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
class RuntimeConnection {
|
|
69
|
-
#connection;
|
|
70
|
-
#log;
|
|
71
|
-
get connection() {
|
|
72
|
-
return this.#connection;
|
|
73
|
-
}
|
|
74
|
-
constructor(connection, log) {
|
|
75
|
-
this.#connection = connection;
|
|
76
|
-
this.#log = log;
|
|
65
|
+
#needsLogging() {
|
|
66
|
+
return (this.#log.isLevelEnabled('query') || this.#log.isLevelEnabled('error'));
|
|
77
67
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
68
|
+
// This method monkey patches the database connection's executeQuery method
|
|
69
|
+
// by adding logging code around it. Monkey patching is not pretty, but it's
|
|
70
|
+
// the best option in this case.
|
|
71
|
+
#addLogging(connection) {
|
|
72
|
+
const executeQuery = connection.executeQuery;
|
|
73
|
+
connection.executeQuery = async (compiledQuery) => {
|
|
74
|
+
const startTime = (0, performance_now_js_1.performanceNow)();
|
|
75
|
+
try {
|
|
76
|
+
return await executeQuery.call(connection, compiledQuery);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
this.#logError(error);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
this.#logQuery(compiledQuery, startTime);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
90
86
|
}
|
|
91
87
|
#logError(error) {
|
|
92
88
|
this.#log.error(() => ({
|
|
@@ -105,3 +101,4 @@ class RuntimeConnection {
|
|
|
105
101
|
return (0, performance_now_js_1.performanceNow)() - startTime;
|
|
106
102
|
}
|
|
107
103
|
}
|
|
104
|
+
exports.RuntimeDriver = RuntimeDriver;
|
|
@@ -40,6 +40,7 @@ export * from './driver/database-connection.js';
|
|
|
40
40
|
export * from './driver/connection-provider.js';
|
|
41
41
|
export * from './driver/default-connection-provider.js';
|
|
42
42
|
export * from './driver/single-connection-provider.js';
|
|
43
|
+
export * from './driver/dummy-driver.js';
|
|
43
44
|
export * from './dialect/dialect.js';
|
|
44
45
|
export * from './dialect/dialect-adapter.js';
|
|
45
46
|
export * from './dialect/dialect-adapter-base.js';
|
|
@@ -52,6 +52,7 @@ __exportStar(require("./driver/database-connection.js"), exports);
|
|
|
52
52
|
__exportStar(require("./driver/connection-provider.js"), exports);
|
|
53
53
|
__exportStar(require("./driver/default-connection-provider.js"), exports);
|
|
54
54
|
__exportStar(require("./driver/single-connection-provider.js"), exports);
|
|
55
|
+
__exportStar(require("./driver/dummy-driver.js"), exports);
|
|
55
56
|
__exportStar(require("./dialect/dialect.js"), exports);
|
|
56
57
|
__exportStar(require("./dialect/dialect-adapter.js"), exports);
|
|
57
58
|
__exportStar(require("./dialect/dialect-adapter-base.js"), exports);
|
package/dist/cjs/util/log.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare type LogConfig = ReadonlyArray<LogLevel> | Logger;
|
|
|
17
17
|
export declare class Log {
|
|
18
18
|
#private;
|
|
19
19
|
constructor(config: LogConfig);
|
|
20
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
20
21
|
query(getEvent: () => QueryLogEvent): void;
|
|
21
22
|
error(getEvent: () => ErrorLogEvent): void;
|
|
22
23
|
}
|
package/dist/cjs/util/log.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DatabaseConnection } from './database-connection.js';
|
|
2
|
+
import { Driver } from './driver.js';
|
|
3
|
+
export declare class DummyDriver implements Driver {
|
|
4
|
+
/**
|
|
5
|
+
* Initializes the driver.
|
|
6
|
+
*
|
|
7
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
8
|
+
* methods should be callable.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
11
|
+
* should be imported inside this function, not at the top of the driver file! This is
|
|
12
|
+
* important so that Kysely is usable without installing all database driver libraries
|
|
13
|
+
* it supports.
|
|
14
|
+
*/
|
|
15
|
+
init(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Acquires a new connection from the pool.
|
|
18
|
+
*/
|
|
19
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
20
|
+
/**
|
|
21
|
+
* Begins a transaction.
|
|
22
|
+
*/
|
|
23
|
+
beginTransaction(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Commits a transaction.
|
|
26
|
+
*/
|
|
27
|
+
commitTransaction(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Rolls back a transaction.
|
|
30
|
+
*/
|
|
31
|
+
rollbackTransaction(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Releases a connection back to the pool.
|
|
34
|
+
*/
|
|
35
|
+
releaseConnection(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Destroys the driver and releases all resources.
|
|
38
|
+
*/
|
|
39
|
+
destroy(): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="./dummy-driver.d.ts" />
|
|
2
|
+
export class DummyDriver {
|
|
3
|
+
init() {
|
|
4
|
+
throw new Error('Method not implemented.');
|
|
5
|
+
}
|
|
6
|
+
async acquireConnection() {
|
|
7
|
+
return new DummyConnection();
|
|
8
|
+
}
|
|
9
|
+
async beginTransaction() {
|
|
10
|
+
// Nothing to do here.
|
|
11
|
+
}
|
|
12
|
+
async commitTransaction() {
|
|
13
|
+
// Nothing to do here.
|
|
14
|
+
}
|
|
15
|
+
async rollbackTransaction() {
|
|
16
|
+
// Nothing to do here.
|
|
17
|
+
}
|
|
18
|
+
async releaseConnection() {
|
|
19
|
+
// Nothing to do here.
|
|
20
|
+
}
|
|
21
|
+
async destroy() {
|
|
22
|
+
// Nothing to do here.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class DummyConnection {
|
|
26
|
+
async executeQuery(compiledQuery) {
|
|
27
|
+
return {
|
|
28
|
+
rows: [],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -28,7 +28,7 @@ export declare class RuntimeDriver implements Driver {
|
|
|
28
28
|
/**
|
|
29
29
|
* Releases a connection back to the pool.
|
|
30
30
|
*/
|
|
31
|
-
releaseConnection(
|
|
31
|
+
releaseConnection(connection: DatabaseConnection): Promise<void>;
|
|
32
32
|
/**
|
|
33
33
|
* Begins a transaction.
|
|
34
34
|
*/
|
|
@@ -10,7 +10,7 @@ export class RuntimeDriver {
|
|
|
10
10
|
#log;
|
|
11
11
|
#initPromise;
|
|
12
12
|
#destroyPromise;
|
|
13
|
-
#connections = new
|
|
13
|
+
#connections = new WeakSet();
|
|
14
14
|
constructor(driver, log) {
|
|
15
15
|
this.#driver = driver;
|
|
16
16
|
this.#log = log;
|
|
@@ -27,17 +27,16 @@ export class RuntimeDriver {
|
|
|
27
27
|
async acquireConnection() {
|
|
28
28
|
await this.init();
|
|
29
29
|
const connection = await this.#driver.acquireConnection();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
if (!this.#connections.has(connection)) {
|
|
31
|
+
if (this.#needsLogging()) {
|
|
32
|
+
this.#addLogging(connection);
|
|
33
|
+
}
|
|
34
|
+
this.#connections.add(connection);
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return connection;
|
|
36
37
|
}
|
|
37
|
-
async releaseConnection(
|
|
38
|
-
|
|
39
|
-
await this.#driver.releaseConnection(runtimeConnection.connection);
|
|
40
|
-
}
|
|
38
|
+
async releaseConnection(connection) {
|
|
39
|
+
await this.#driver.releaseConnection(connection);
|
|
41
40
|
}
|
|
42
41
|
beginTransaction(connection, settings) {
|
|
43
42
|
return this.#driver.beginTransaction(connection, settings);
|
|
@@ -61,29 +60,27 @@ export class RuntimeDriver {
|
|
|
61
60
|
}
|
|
62
61
|
await this.#destroyPromise;
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
#connection;
|
|
67
|
-
#log;
|
|
68
|
-
get connection() {
|
|
69
|
-
return this.#connection;
|
|
70
|
-
}
|
|
71
|
-
constructor(connection, log) {
|
|
72
|
-
this.#connection = connection;
|
|
73
|
-
this.#log = log;
|
|
63
|
+
#needsLogging() {
|
|
64
|
+
return (this.#log.isLevelEnabled('query') || this.#log.isLevelEnabled('error'));
|
|
74
65
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
// This method monkey patches the database connection's executeQuery method
|
|
67
|
+
// by adding logging code around it. Monkey patching is not pretty, but it's
|
|
68
|
+
// the best option in this case.
|
|
69
|
+
#addLogging(connection) {
|
|
70
|
+
const executeQuery = connection.executeQuery;
|
|
71
|
+
connection.executeQuery = async (compiledQuery) => {
|
|
72
|
+
const startTime = performanceNow();
|
|
73
|
+
try {
|
|
74
|
+
return await executeQuery.call(connection, compiledQuery);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.#logError(error);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
this.#logQuery(compiledQuery, startTime);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
87
84
|
}
|
|
88
85
|
#logError(error) {
|
|
89
86
|
this.#log.error(() => ({
|
|
@@ -40,6 +40,7 @@ export * from './driver/database-connection.js';
|
|
|
40
40
|
export * from './driver/connection-provider.js';
|
|
41
41
|
export * from './driver/default-connection-provider.js';
|
|
42
42
|
export * from './driver/single-connection-provider.js';
|
|
43
|
+
export * from './driver/dummy-driver.js';
|
|
43
44
|
export * from './dialect/dialect.js';
|
|
44
45
|
export * from './dialect/dialect-adapter.js';
|
|
45
46
|
export * from './dialect/dialect-adapter-base.js';
|
|
@@ -41,6 +41,7 @@ export * from './driver/database-connection.js';
|
|
|
41
41
|
export * from './driver/connection-provider.js';
|
|
42
42
|
export * from './driver/default-connection-provider.js';
|
|
43
43
|
export * from './driver/single-connection-provider.js';
|
|
44
|
+
export * from './driver/dummy-driver.js';
|
|
44
45
|
export * from './dialect/dialect.js';
|
|
45
46
|
export * from './dialect/dialect-adapter.js';
|
|
46
47
|
export * from './dialect/dialect-adapter-base.js';
|
package/dist/esm/util/log.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare type LogConfig = ReadonlyArray<LogLevel> | Logger;
|
|
|
17
17
|
export declare class Log {
|
|
18
18
|
#private;
|
|
19
19
|
constructor(config: LogConfig);
|
|
20
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
20
21
|
query(getEvent: () => QueryLogEvent): void;
|
|
21
22
|
error(getEvent: () => ErrorLogEvent): void;
|
|
22
23
|
}
|
package/dist/esm/util/log.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kysely",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.6",
|
|
4
4
|
"description": "Type safe SQL query builder",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
"./dist/esm/index-nodeless.js": "./dist/esm/index-nodeless.js"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"test": "
|
|
26
|
-
"test:
|
|
23
|
+
"clean": "rm -rf dist && rm -rf test/node/dist && rm -rf test/browser/bundle.js",
|
|
24
|
+
"test": "npm run clean && npm run build:cjs && npm run script:copy-interface-doc && npm run test:node:build && npm run test:node && npm run test:typings && npm run test:esmimports",
|
|
25
|
+
"test:node:build": "rm -rf test/node/dist && tsc -p test/node",
|
|
26
|
+
"test:node": "mocha --timeout 15000 test/node/dist/**/*.test.js",
|
|
27
|
+
"test:browser:build": "rm -rf test/browser/bundle.js && esbuild test/browser/main.ts --bundle --outfile=test/browser/bundle.js",
|
|
28
|
+
"test:browser": "npm run clean && npm run build:esm && npm run test:browser:build && node test/browser/test.js",
|
|
27
29
|
"test:typings": "tsd test/typings",
|
|
28
30
|
"test:esmimports": "node scripts/check-esm-imports.js",
|
|
29
31
|
"prettier": "prettier --write src/**/*.ts test/**/*.ts",
|
|
@@ -51,9 +53,11 @@
|
|
|
51
53
|
"better-sqlite3": "^7.4.5",
|
|
52
54
|
"chai": "^4.3.4",
|
|
53
55
|
"chai-subset": "^1.6.0",
|
|
56
|
+
"esbuild": "^0.14.11",
|
|
54
57
|
"mocha": "^9.1.3",
|
|
55
58
|
"mysql2": "^2.3.3",
|
|
56
59
|
"pg": "^8.7.1",
|
|
60
|
+
"playwright": "^1.17.2",
|
|
57
61
|
"prettier": "^2.5.1",
|
|
58
62
|
"tsd": "^0.19.0",
|
|
59
63
|
"typedoc": "^0.22.10",
|