kysely 0.16.3 → 0.16.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -9
- package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +205 -0
- package/dist/cjs/dialect/mysql/mysql-dialect-config.js +2 -0
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -205
- package/dist/cjs/dialect/mysql/mysql-dialect.js +2 -1
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-driver.js +11 -3
- package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +103 -0
- package/dist/cjs/dialect/postgres/postgres-dialect-config.js +2 -0
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -103
- package/dist/cjs/dialect/postgres/postgres-dialect.js +2 -1
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-driver.js +12 -3
- package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +43 -0
- package/dist/cjs/dialect/sqlite/sqlite-dialect-config.js +2 -0
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -43
- package/dist/cjs/dialect/sqlite/sqlite-dialect.js +2 -1
- package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +11 -3
- package/dist/cjs/driver/dummy-driver.d.ts +68 -0
- package/dist/cjs/driver/dummy-driver.js +62 -0
- package/dist/cjs/driver/runtime-driver.d.ts +1 -1
- package/dist/cjs/driver/runtime-driver.js +30 -33
- package/dist/cjs/index-nodeless.d.ts +2 -0
- package/dist/cjs/index-nodeless.js +2 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/kysely.d.ts +8 -6
- package/dist/cjs/kysely.js +8 -6
- package/dist/cjs/migration/migrator.d.ts +2 -2
- package/dist/cjs/operation-node/primitive-value-list-node.d.ts +2 -3
- package/dist/cjs/operation-node/value-node.d.ts +3 -4
- package/dist/cjs/parser/complex-expression-parser.d.ts +1 -0
- package/dist/cjs/parser/complex-expression-parser.js +5 -1
- package/dist/cjs/parser/default-value-parser.d.ts +2 -3
- package/dist/cjs/parser/default-value-parser.js +2 -2
- package/dist/cjs/parser/insert-values-parser.js +4 -3
- package/dist/cjs/parser/reference-parser.d.ts +2 -3
- package/dist/cjs/parser/value-parser.d.ts +2 -3
- package/dist/cjs/parser/value-parser.js +6 -7
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.js +19 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.js +42 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +51 -9
- package/dist/cjs/query-builder/delete-query-builder.js +56 -8
- package/dist/cjs/query-builder/expression-builder.d.ts +1 -1
- package/dist/cjs/query-builder/expression-builder.js +2 -2
- package/dist/cjs/query-builder/function-builder.d.ts +29 -5
- package/dist/cjs/query-builder/function-builder.js +31 -7
- package/dist/cjs/query-builder/insert-query-builder.d.ts +53 -11
- package/dist/cjs/query-builder/insert-query-builder.js +58 -10
- package/dist/cjs/query-builder/select-query-builder.d.ts +58 -16
- package/dist/cjs/query-builder/select-query-builder.js +64 -15
- package/dist/cjs/query-builder/update-query-builder.d.ts +52 -9
- package/dist/cjs/query-builder/update-query-builder.js +57 -8
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +1 -2
- package/dist/cjs/query-creator.d.ts +2 -2
- package/dist/cjs/query-creator.js +2 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +30 -4
- package/dist/cjs/schema/alter-table-builder.js +2 -5
- package/dist/cjs/schema/column-definition-builder.d.ts +27 -2
- package/dist/cjs/schema/create-view-builder.js +1 -1
- package/dist/cjs/util/log.d.ts +1 -0
- package/dist/cjs/util/log.js +3 -0
- package/dist/cjs/util/object-utils.d.ts +5 -5
- package/dist/cjs/util/object-utils.js +52 -11
- package/dist/cjs/util/type-utils.d.ts +21 -0
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +205 -0
- package/dist/esm/dialect/mysql/mysql-dialect-config.js +2 -0
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -205
- package/dist/esm/dialect/mysql/mysql-dialect.js +2 -1
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-driver.js +12 -4
- package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +103 -0
- package/dist/esm/dialect/postgres/postgres-dialect-config.js +2 -0
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -103
- package/dist/esm/dialect/postgres/postgres-dialect.js +2 -1
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-driver.js +12 -3
- package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +43 -0
- package/dist/esm/dialect/sqlite/sqlite-dialect-config.js +2 -0
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -43
- package/dist/esm/dialect/sqlite/sqlite-dialect.js +2 -1
- package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-driver.js +12 -4
- package/dist/esm/driver/dummy-driver.d.ts +68 -0
- package/dist/esm/driver/dummy-driver.js +59 -0
- package/dist/esm/driver/runtime-driver.d.ts +1 -1
- package/dist/esm/driver/runtime-driver.js +29 -32
- package/dist/esm/index-nodeless.d.ts +2 -0
- package/dist/esm/index-nodeless.js +2 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/kysely.d.ts +8 -6
- package/dist/esm/kysely.js +8 -6
- package/dist/esm/migration/migrator.d.ts +2 -2
- package/dist/esm/operation-node/primitive-value-list-node.d.ts +2 -3
- package/dist/esm/operation-node/value-node.d.ts +3 -4
- package/dist/esm/parser/complex-expression-parser.d.ts +1 -0
- package/dist/esm/parser/complex-expression-parser.js +3 -0
- package/dist/esm/parser/default-value-parser.d.ts +2 -3
- package/dist/esm/parser/default-value-parser.js +2 -2
- package/dist/esm/parser/insert-values-parser.js +5 -4
- package/dist/esm/parser/reference-parser.d.ts +2 -3
- package/dist/esm/parser/reference-parser.js +1 -1
- package/dist/esm/parser/value-parser.d.ts +2 -3
- package/dist/esm/parser/value-parser.js +8 -9
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.js +16 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.js +39 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +51 -9
- package/dist/esm/query-builder/delete-query-builder.js +56 -8
- package/dist/esm/query-builder/expression-builder.d.ts +1 -1
- package/dist/esm/query-builder/expression-builder.js +1 -1
- package/dist/esm/query-builder/function-builder.d.ts +29 -5
- package/dist/esm/query-builder/function-builder.js +31 -7
- package/dist/esm/query-builder/insert-query-builder.d.ts +53 -11
- package/dist/esm/query-builder/insert-query-builder.js +58 -10
- package/dist/esm/query-builder/select-query-builder.d.ts +58 -16
- package/dist/esm/query-builder/select-query-builder.js +64 -15
- package/dist/esm/query-builder/update-query-builder.d.ts +52 -9
- package/dist/esm/query-builder/update-query-builder.js +57 -8
- package/dist/esm/query-compiler/default-query-compiler.d.ts +1 -2
- package/dist/esm/query-creator.d.ts +2 -2
- package/dist/esm/query-creator.js +2 -2
- package/dist/esm/schema/alter-table-builder.d.ts +30 -4
- package/dist/esm/schema/alter-table-builder.js +2 -5
- package/dist/esm/schema/column-definition-builder.d.ts +27 -2
- package/dist/esm/schema/create-view-builder.js +1 -1
- package/dist/esm/util/log.d.ts +1 -0
- package/dist/esm/util/log.js +3 -0
- package/dist/esm/util/object-utils.d.ts +5 -5
- package/dist/esm/util/object-utils.js +50 -9
- package/dist/esm/util/type-utils.d.ts +21 -0
- package/package.json +11 -5
- package/.prettierignore +0 -1
- package/dist/cjs/util/dynamic-import.d.ts +0 -2
- package/dist/cjs/util/dynamic-import.js +0 -32
- package/dist/esm/util/dynamic-import.d.ts +0 -2
- package/dist/esm/util/dynamic-import.js +0 -28
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as stream from 'stream';
|
|
3
|
-
import { ConnectionOptions } from 'tls';
|
|
4
1
|
import { Driver } from '../../driver/driver.js';
|
|
5
2
|
import { Kysely } from '../../kysely.js';
|
|
6
3
|
import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
7
4
|
import { Dialect } from '../dialect.js';
|
|
8
5
|
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
9
6
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
10
|
-
import {
|
|
7
|
+
import { PostgresDialectConfig } from './postgres-dialect-config.js';
|
|
11
8
|
/**
|
|
12
9
|
* PostgreSQL dialect that uses the [pg](https://node-postgres.com/) library.
|
|
13
10
|
*
|
|
@@ -42,102 +39,3 @@ export declare class PostgresDialect implements Dialect {
|
|
|
42
39
|
*/
|
|
43
40
|
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
44
41
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Config for the PostgreSQL dialect.
|
|
47
|
-
*
|
|
48
|
-
* This interface is equal to `pg` library's `Pool` config:
|
|
49
|
-
*
|
|
50
|
-
* https://node-postgres.com/api/pool
|
|
51
|
-
* https://node-postgres.com/api/client
|
|
52
|
-
*/
|
|
53
|
-
export interface PostgresDialectConfig {
|
|
54
|
-
/**
|
|
55
|
-
* defaults process.env.PGUSER || process.env.USER.
|
|
56
|
-
*/
|
|
57
|
-
user?: string;
|
|
58
|
-
/**
|
|
59
|
-
* default process.env.PGDATABASE || process.env.USER
|
|
60
|
-
*/
|
|
61
|
-
database?: string;
|
|
62
|
-
/**
|
|
63
|
-
* default process.env.PGPASSWORD
|
|
64
|
-
*/
|
|
65
|
-
password?: string | (() => string | Promise<string>);
|
|
66
|
-
/**
|
|
67
|
-
* default process.env.PGPORT
|
|
68
|
-
*/
|
|
69
|
-
port?: number;
|
|
70
|
-
/**
|
|
71
|
-
* default process.env.PGHOST
|
|
72
|
-
*/
|
|
73
|
-
host?: string;
|
|
74
|
-
/**
|
|
75
|
-
* e.g. postgres:*user:password@host:5432/database
|
|
76
|
-
*/
|
|
77
|
-
connectionString?: string;
|
|
78
|
-
/**
|
|
79
|
-
* passed directly to node.TLSSocket, supports all tls.connect options
|
|
80
|
-
*/
|
|
81
|
-
ssl?: boolean | ConnectionOptions;
|
|
82
|
-
/**
|
|
83
|
-
* Number of milliseconds to wait before timing out when connecting a new client
|
|
84
|
-
* by default this is 0 which means no timeout.
|
|
85
|
-
*/
|
|
86
|
-
connectionTimeoutMillis?: number;
|
|
87
|
-
/**
|
|
88
|
-
* Maximum number of clients the pool should contain. by default this is set to 10.
|
|
89
|
-
*/
|
|
90
|
-
max?: number;
|
|
91
|
-
/**
|
|
92
|
-
* Minimum number of clients the pool should contain
|
|
93
|
-
*/
|
|
94
|
-
min?: number;
|
|
95
|
-
/**
|
|
96
|
-
* Number of milliseconds a client must sit idle in the pool and not be checked out
|
|
97
|
-
* before it is disconnected from the backend and discarded.
|
|
98
|
-
*
|
|
99
|
-
* default is 10000 (10 seconds) - set to 0 to disable auto-disconnection of idle clients.
|
|
100
|
-
*/
|
|
101
|
-
idleTimeoutMillis?: number;
|
|
102
|
-
/**
|
|
103
|
-
* Default behavior is the pool will keep clients open & connected to the backend
|
|
104
|
-
* until idleTimeoutMillis expire for each client and node will maintain a ref
|
|
105
|
-
* to the socket on the client, keeping the event loop alive until all clients are closed
|
|
106
|
-
* after being idle or the pool is manually shutdown with `pool.end()`.
|
|
107
|
-
*
|
|
108
|
-
* Setting `allowExitOnIdle: true` in the config will allow the node event loop to exit
|
|
109
|
-
* as soon as all clients in the pool are idle, even if their socket is still open
|
|
110
|
-
* to the PostgreSQL server. This can be handy in scripts & tests
|
|
111
|
-
* where you don't want to wait for your clients to go idle before your process exits.
|
|
112
|
-
*/
|
|
113
|
-
allowExitOnIdle?: boolean;
|
|
114
|
-
log?: (...messages: any[]) => void;
|
|
115
|
-
/**
|
|
116
|
-
* Number of milliseconds before a statement in query will time out, default is no timeout.
|
|
117
|
-
*/
|
|
118
|
-
statement_timeout?: false | number;
|
|
119
|
-
/**
|
|
120
|
-
* Number of milliseconds before terminating any session with an open idle transaction.
|
|
121
|
-
* Default is no timeout.
|
|
122
|
-
*/
|
|
123
|
-
idle_in_transaction_session_timeout?: number;
|
|
124
|
-
/**
|
|
125
|
-
* Number of milliseconds before a query call will timeout, default is no timeout.
|
|
126
|
-
*/
|
|
127
|
-
query_timeout?: number;
|
|
128
|
-
/**
|
|
129
|
-
* The name of the application that created this Client instance.
|
|
130
|
-
*/
|
|
131
|
-
application_name?: string;
|
|
132
|
-
/**
|
|
133
|
-
* Called once for each created connection.
|
|
134
|
-
*
|
|
135
|
-
* This is a Kysely specific feature and does not come from the `pg` module.
|
|
136
|
-
*/
|
|
137
|
-
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
138
|
-
keepAlive?: boolean;
|
|
139
|
-
keepAliveInitialDelayMillis?: number;
|
|
140
|
-
types?: any;
|
|
141
|
-
stream?: stream.Duplex;
|
|
142
|
-
parseInputDatesAsUTC?: boolean;
|
|
143
|
-
}
|
|
@@ -3,6 +3,7 @@ import { PostgresDriver } from './postgres-driver.js';
|
|
|
3
3
|
import { PostgresIntrospector } from './postgres-introspector.js';
|
|
4
4
|
import { PostgresQueryCompiler } from './postgres-query-compiler.js';
|
|
5
5
|
import { PostgresAdapter } from './postgres-adapter.js';
|
|
6
|
+
import { freeze } from '../../util/object-utils.js';
|
|
6
7
|
/**
|
|
7
8
|
* PostgreSQL dialect that uses the [pg](https://node-postgres.com/) library.
|
|
8
9
|
*
|
|
@@ -16,7 +17,7 @@ import { PostgresAdapter } from './postgres-adapter.js';
|
|
|
16
17
|
export class PostgresDialect {
|
|
17
18
|
#config;
|
|
18
19
|
constructor(config) {
|
|
19
|
-
this.#config = config;
|
|
20
|
+
this.#config = freeze({ ...config });
|
|
20
21
|
}
|
|
21
22
|
createDriver() {
|
|
22
23
|
return new PostgresDriver(this.#config);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
2
2
|
import { Driver, TransactionSettings } from '../../driver/driver.js';
|
|
3
|
-
import { PostgresDialectConfig } from './postgres-dialect.js';
|
|
3
|
+
import { PostgresDialectConfig } from './postgres-dialect-config.js';
|
|
4
4
|
export declare class PostgresDriver implements Driver {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(config: PostgresDialectConfig);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="./postgres-driver.d.ts" />
|
|
2
2
|
import { CompiledQuery } from '../../query-compiler/compiled-query.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isFunction, freeze } from '../../util/object-utils.js';
|
|
4
4
|
const PRIVATE_RELEASE_METHOD = Symbol();
|
|
5
5
|
export class PostgresDriver {
|
|
6
6
|
#config;
|
|
7
7
|
#connections = new WeakMap();
|
|
8
8
|
#pool = null;
|
|
9
9
|
constructor(config) {
|
|
10
|
-
this.#config = config;
|
|
10
|
+
this.#config = freeze({ ...config });
|
|
11
11
|
}
|
|
12
12
|
async init() {
|
|
13
13
|
// Import the `pg` module here instead at the top of the file
|
|
@@ -63,7 +63,16 @@ export class PostgresDriver {
|
|
|
63
63
|
}
|
|
64
64
|
async function importPgPool() {
|
|
65
65
|
try {
|
|
66
|
-
|
|
66
|
+
// The imported module name must be a string literal to make
|
|
67
|
+
// some bundlers work. So don't move this code behind a helper
|
|
68
|
+
// for example.
|
|
69
|
+
const pgModule = await import('pg');
|
|
70
|
+
if (isFunction(pgModule.Pool)) {
|
|
71
|
+
return pgModule.Pool;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return pgModule.default.Pool;
|
|
75
|
+
}
|
|
67
76
|
}
|
|
68
77
|
catch (error) {
|
|
69
78
|
throw new Error('Postgres client not installed. Please run `npm install pg`');
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
2
|
+
/**
|
|
3
|
+
* Config for the SQLite dialect.
|
|
4
|
+
*
|
|
5
|
+
* This interface is equal to `better-sqlite3` library's `Databse` class's constructor parameters.
|
|
6
|
+
*
|
|
7
|
+
* https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options
|
|
8
|
+
*/
|
|
9
|
+
export interface SqliteDialectConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The database file path.
|
|
12
|
+
*
|
|
13
|
+
* This is passed as the first argument for the [Database](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options)
|
|
14
|
+
* class constructor.
|
|
15
|
+
*/
|
|
16
|
+
databasePath: string;
|
|
17
|
+
/**
|
|
18
|
+
* Open the database connection in readonly mode (default: false)
|
|
19
|
+
*/
|
|
20
|
+
readonly?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If the database does not exist, an Error will be thrown instead of creating a new file.
|
|
23
|
+
* This option is ignored for in-memory, temporary, or readonly database connections
|
|
24
|
+
* (default: false)
|
|
25
|
+
*/
|
|
26
|
+
fileMustExist?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The number of milliseconds to wait when executing queries on a locked database,
|
|
29
|
+
* before throwing a SQLITE_BUSY error (default: 5000)
|
|
30
|
+
*/
|
|
31
|
+
timeout?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Provide a function that gets called with every SQL string executed by the database connection
|
|
34
|
+
* (default: null)
|
|
35
|
+
*/
|
|
36
|
+
verbose?: (sql: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Called once when the first query is executed.
|
|
39
|
+
*
|
|
40
|
+
* This is a Kysely specific feature and does not come from the `better-sqlite3` module.
|
|
41
|
+
*/
|
|
42
|
+
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
43
|
+
}
|
|
@@ -4,7 +4,7 @@ import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
|
4
4
|
import { Dialect } from '../dialect.js';
|
|
5
5
|
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
6
6
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
7
|
-
import {
|
|
7
|
+
import { SqliteDialectConfig } from './sqlite-dialect-config.js';
|
|
8
8
|
/**
|
|
9
9
|
* SQLite dialect that uses the [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) library.
|
|
10
10
|
*
|
|
@@ -36,45 +36,3 @@ export declare class SqliteDialect implements Dialect {
|
|
|
36
36
|
*/
|
|
37
37
|
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Config for the SQLite dialect.
|
|
41
|
-
*
|
|
42
|
-
* This interface is equal to `better-sqlite3` library's `Databse` class's constructor parameters.
|
|
43
|
-
*
|
|
44
|
-
* https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options
|
|
45
|
-
*/
|
|
46
|
-
export interface SqliteDialectConfig {
|
|
47
|
-
/**
|
|
48
|
-
* The database file path.
|
|
49
|
-
*
|
|
50
|
-
* This is passed as the first argument for the [Database](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options)
|
|
51
|
-
* class constructor.
|
|
52
|
-
*/
|
|
53
|
-
databasePath: string;
|
|
54
|
-
/**
|
|
55
|
-
* Open the database connection in readonly mode (default: false)
|
|
56
|
-
*/
|
|
57
|
-
readonly?: boolean;
|
|
58
|
-
/**
|
|
59
|
-
* If the database does not exist, an Error will be thrown instead of creating a new file.
|
|
60
|
-
* This option is ignored for in-memory, temporary, or readonly database connections
|
|
61
|
-
* (default: false)
|
|
62
|
-
*/
|
|
63
|
-
fileMustExist?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* The number of milliseconds to wait when executing queries on a locked database,
|
|
66
|
-
* before throwing a SQLITE_BUSY error (default: 5000)
|
|
67
|
-
*/
|
|
68
|
-
timeout?: number;
|
|
69
|
-
/**
|
|
70
|
-
* Provide a function that gets called with every SQL string executed by the database connection
|
|
71
|
-
* (default: null)
|
|
72
|
-
*/
|
|
73
|
-
verbose?: (sql: string) => void;
|
|
74
|
-
/**
|
|
75
|
-
* Called once when the first query is executed.
|
|
76
|
-
*
|
|
77
|
-
* This is a Kysely specific feature and does not come from the `better-sqlite3` module.
|
|
78
|
-
*/
|
|
79
|
-
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
80
|
-
}
|
|
@@ -3,6 +3,7 @@ import { SqliteDriver } from './sqlite-driver.js';
|
|
|
3
3
|
import { SqliteQueryCompiler } from './sqlite-query-compiler.js';
|
|
4
4
|
import { SqliteIntrospector } from './sqlite-introspector.js';
|
|
5
5
|
import { SqliteAdapter } from './sqlite-adapter.js';
|
|
6
|
+
import { freeze } from '../../util/object-utils.js';
|
|
6
7
|
/**
|
|
7
8
|
* SQLite dialect that uses the [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) library.
|
|
8
9
|
*
|
|
@@ -13,7 +14,7 @@ import { SqliteAdapter } from './sqlite-adapter.js';
|
|
|
13
14
|
export class SqliteDialect {
|
|
14
15
|
#config;
|
|
15
16
|
constructor(config) {
|
|
16
|
-
this.#config = config;
|
|
17
|
+
this.#config = freeze({ ...config });
|
|
17
18
|
}
|
|
18
19
|
createDriver() {
|
|
19
20
|
return new SqliteDriver(this.#config);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
2
2
|
import { Driver } from '../../driver/driver.js';
|
|
3
|
-
import { SqliteDialectConfig } from './sqlite-dialect.js';
|
|
3
|
+
import { SqliteDialectConfig } from './sqlite-dialect-config.js';
|
|
4
4
|
export declare class SqliteDriver implements Driver {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(config: SqliteDialectConfig);
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/// <reference types="./sqlite-driver.d.ts" />
|
|
2
2
|
import { CompiledQuery } from '../../query-compiler/compiled-query.js';
|
|
3
|
-
import {
|
|
4
|
-
import { isBoolean, isFunction, isNumber } from '../../util/object-utils.js';
|
|
3
|
+
import { freeze, isBoolean, isFunction, isNumber, } from '../../util/object-utils.js';
|
|
5
4
|
export class SqliteDriver {
|
|
6
5
|
#config;
|
|
7
6
|
#connectionMutex = new ConnectionMutex();
|
|
8
7
|
#db;
|
|
9
8
|
#connection;
|
|
10
9
|
constructor(config) {
|
|
11
|
-
this.#config = config;
|
|
10
|
+
this.#config = freeze({ ...config });
|
|
12
11
|
}
|
|
13
12
|
async init() {
|
|
14
13
|
// Import the `better-sqlite3` module here instead at the top of the file
|
|
@@ -60,7 +59,16 @@ export class SqliteDriver {
|
|
|
60
59
|
}
|
|
61
60
|
async function importBetterSqlite3Database() {
|
|
62
61
|
try {
|
|
63
|
-
|
|
62
|
+
// The imported module name must be a string literal to make
|
|
63
|
+
// some bundlers work. So don't move this code behind a helper
|
|
64
|
+
// for example.
|
|
65
|
+
const sqliteModule = await import('better-sqlite3');
|
|
66
|
+
if (isFunction(sqliteModule)) {
|
|
67
|
+
return sqliteModule;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return sqliteModule.default;
|
|
71
|
+
}
|
|
64
72
|
}
|
|
65
73
|
catch (error) {
|
|
66
74
|
throw new Error('SQLite client not installed. Please run `npm install better-sqlite3`');
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DatabaseConnection } from './database-connection.js';
|
|
2
|
+
import { Driver } from './driver.js';
|
|
3
|
+
/**
|
|
4
|
+
* A driver that does absolutely nothing.
|
|
5
|
+
*
|
|
6
|
+
* You can use this to create Kysely instances solely for building queries
|
|
7
|
+
*
|
|
8
|
+
* ### Examples
|
|
9
|
+
*
|
|
10
|
+
* This example creates a Kysely instance for building postgres queries:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const db = new Kysely<Database>({
|
|
14
|
+
* dialect: {
|
|
15
|
+
* createAdapter() {
|
|
16
|
+
* return new PostgresAdapter()
|
|
17
|
+
* },
|
|
18
|
+
* createDriver() {
|
|
19
|
+
* return new DummyDriver()
|
|
20
|
+
* },
|
|
21
|
+
* createIntrospector(db: Kysely<any>) {
|
|
22
|
+
* return new PostgresIntrospector(db)
|
|
23
|
+
* },
|
|
24
|
+
* createQueryCompiler() {
|
|
25
|
+
* return new PostgresQueryCompiler()
|
|
26
|
+
* },
|
|
27
|
+
* },
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class DummyDriver implements Driver {
|
|
32
|
+
/**
|
|
33
|
+
* Initializes the driver.
|
|
34
|
+
*
|
|
35
|
+
* After calling this method the driver should be usable and `acquireConnection` etc.
|
|
36
|
+
* methods should be callable.
|
|
37
|
+
*
|
|
38
|
+
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
|
|
39
|
+
* should be imported inside this function, not at the top of the driver file! This is
|
|
40
|
+
* important so that Kysely is usable without installing all database driver libraries
|
|
41
|
+
* it supports.
|
|
42
|
+
*/
|
|
43
|
+
init(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Acquires a new connection from the pool.
|
|
46
|
+
*/
|
|
47
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
48
|
+
/**
|
|
49
|
+
* Begins a transaction.
|
|
50
|
+
*/
|
|
51
|
+
beginTransaction(): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Commits a transaction.
|
|
54
|
+
*/
|
|
55
|
+
commitTransaction(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Rolls back a transaction.
|
|
58
|
+
*/
|
|
59
|
+
rollbackTransaction(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Releases a connection back to the pool.
|
|
62
|
+
*/
|
|
63
|
+
releaseConnection(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Destroys the driver and releases all resources.
|
|
66
|
+
*/
|
|
67
|
+
destroy(): Promise<void>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="./dummy-driver.d.ts" />
|
|
2
|
+
/**
|
|
3
|
+
* A driver that does absolutely nothing.
|
|
4
|
+
*
|
|
5
|
+
* You can use this to create Kysely instances solely for building queries
|
|
6
|
+
*
|
|
7
|
+
* ### Examples
|
|
8
|
+
*
|
|
9
|
+
* This example creates a Kysely instance for building postgres queries:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const db = new Kysely<Database>({
|
|
13
|
+
* dialect: {
|
|
14
|
+
* createAdapter() {
|
|
15
|
+
* return new PostgresAdapter()
|
|
16
|
+
* },
|
|
17
|
+
* createDriver() {
|
|
18
|
+
* return new DummyDriver()
|
|
19
|
+
* },
|
|
20
|
+
* createIntrospector(db: Kysely<any>) {
|
|
21
|
+
* return new PostgresIntrospector(db)
|
|
22
|
+
* },
|
|
23
|
+
* createQueryCompiler() {
|
|
24
|
+
* return new PostgresQueryCompiler()
|
|
25
|
+
* },
|
|
26
|
+
* },
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class DummyDriver {
|
|
31
|
+
async init() {
|
|
32
|
+
// Nothing to do here.
|
|
33
|
+
}
|
|
34
|
+
async acquireConnection() {
|
|
35
|
+
return new DummyConnection();
|
|
36
|
+
}
|
|
37
|
+
async beginTransaction() {
|
|
38
|
+
// Nothing to do here.
|
|
39
|
+
}
|
|
40
|
+
async commitTransaction() {
|
|
41
|
+
// Nothing to do here.
|
|
42
|
+
}
|
|
43
|
+
async rollbackTransaction() {
|
|
44
|
+
// Nothing to do here.
|
|
45
|
+
}
|
|
46
|
+
async releaseConnection() {
|
|
47
|
+
// Nothing to do here.
|
|
48
|
+
}
|
|
49
|
+
async destroy() {
|
|
50
|
+
// Nothing to do here.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class DummyConnection {
|
|
54
|
+
async executeQuery() {
|
|
55
|
+
return {
|
|
56
|
+
rows: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -28,7 +28,7 @@ export declare class RuntimeDriver implements Driver {
|
|
|
28
28
|
/**
|
|
29
29
|
* Releases a connection back to the pool.
|
|
30
30
|
*/
|
|
31
|
-
releaseConnection(
|
|
31
|
+
releaseConnection(connection: DatabaseConnection): Promise<void>;
|
|
32
32
|
/**
|
|
33
33
|
* Begins a transaction.
|
|
34
34
|
*/
|
|
@@ -10,7 +10,7 @@ export class RuntimeDriver {
|
|
|
10
10
|
#log;
|
|
11
11
|
#initPromise;
|
|
12
12
|
#destroyPromise;
|
|
13
|
-
#connections = new
|
|
13
|
+
#connections = new WeakSet();
|
|
14
14
|
constructor(driver, log) {
|
|
15
15
|
this.#driver = driver;
|
|
16
16
|
this.#log = log;
|
|
@@ -27,17 +27,16 @@ export class RuntimeDriver {
|
|
|
27
27
|
async acquireConnection() {
|
|
28
28
|
await this.init();
|
|
29
29
|
const connection = await this.#driver.acquireConnection();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
if (!this.#connections.has(connection)) {
|
|
31
|
+
if (this.#needsLogging()) {
|
|
32
|
+
this.#addLogging(connection);
|
|
33
|
+
}
|
|
34
|
+
this.#connections.add(connection);
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return connection;
|
|
36
37
|
}
|
|
37
|
-
async releaseConnection(
|
|
38
|
-
|
|
39
|
-
await this.#driver.releaseConnection(runtimeConnection.connection);
|
|
40
|
-
}
|
|
38
|
+
async releaseConnection(connection) {
|
|
39
|
+
await this.#driver.releaseConnection(connection);
|
|
41
40
|
}
|
|
42
41
|
beginTransaction(connection, settings) {
|
|
43
42
|
return this.#driver.beginTransaction(connection, settings);
|
|
@@ -61,29 +60,27 @@ export class RuntimeDriver {
|
|
|
61
60
|
}
|
|
62
61
|
await this.#destroyPromise;
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
#connection;
|
|
67
|
-
#log;
|
|
68
|
-
get connection() {
|
|
69
|
-
return this.#connection;
|
|
70
|
-
}
|
|
71
|
-
constructor(connection, log) {
|
|
72
|
-
this.#connection = connection;
|
|
73
|
-
this.#log = log;
|
|
63
|
+
#needsLogging() {
|
|
64
|
+
return (this.#log.isLevelEnabled('query') || this.#log.isLevelEnabled('error'));
|
|
74
65
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
// This method monkey patches the database connection's executeQuery method
|
|
67
|
+
// by adding logging code around it. Monkey patching is not pretty, but it's
|
|
68
|
+
// the best option in this case.
|
|
69
|
+
#addLogging(connection) {
|
|
70
|
+
const executeQuery = connection.executeQuery;
|
|
71
|
+
connection.executeQuery = async (compiledQuery) => {
|
|
72
|
+
const startTime = performanceNow();
|
|
73
|
+
try {
|
|
74
|
+
return await executeQuery.call(connection, compiledQuery);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.#logError(error);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
this.#logQuery(compiledQuery, startTime);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
87
84
|
}
|
|
88
85
|
#logError(error) {
|
|
89
86
|
this.#log.error(() => ({
|
|
@@ -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';
|
|
@@ -58,6 +59,7 @@ export * from './query-compiler/query-compiler.js';
|
|
|
58
59
|
export * from './migration/migrator.js';
|
|
59
60
|
export * from './plugin/kysely-plugin.js';
|
|
60
61
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
62
|
+
export * from './plugin/deduplicate-joins/deduplicate-joins-plugin.js';
|
|
61
63
|
export * from './operation-node/add-column-node.js';
|
|
62
64
|
export * from './operation-node/add-constraint-node.js';
|
|
63
65
|
export * from './operation-node/alias-node.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';
|
|
@@ -59,6 +60,7 @@ export * from './query-compiler/query-compiler.js';
|
|
|
59
60
|
export * from './migration/migrator.js';
|
|
60
61
|
export * from './plugin/kysely-plugin.js';
|
|
61
62
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
63
|
+
export * from './plugin/deduplicate-joins/deduplicate-joins-plugin.js';
|
|
62
64
|
export * from './operation-node/add-column-node.js';
|
|
63
65
|
export * from './operation-node/add-constraint-node.js';
|
|
64
66
|
export * from './operation-node/alias-node.js';
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export * from './index-nodeless.js';
|
|
2
2
|
export * from './migration/file-migration-provider.js';
|
|
3
3
|
export * from './dialect/sqlite/sqlite-dialect.js';
|
|
4
|
+
export * from './dialect/sqlite/sqlite-dialect-config.js';
|
|
4
5
|
export * from './dialect/sqlite/sqlite-driver.js';
|
|
5
6
|
export * from './dialect/mysql/mysql-dialect.js';
|
|
7
|
+
export * from './dialect/mysql/mysql-dialect-config.js';
|
|
6
8
|
export * from './dialect/mysql/mysql-driver.js';
|
|
7
9
|
export * from './dialect/postgres/postgres-driver.js';
|
|
10
|
+
export * from './dialect/postgres/postgres-dialect-config.js';
|
|
8
11
|
export * from './dialect/postgres/postgres-dialect.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
export * from './index-nodeless.js';
|
|
3
3
|
export * from './migration/file-migration-provider.js';
|
|
4
4
|
export * from './dialect/sqlite/sqlite-dialect.js';
|
|
5
|
+
export * from './dialect/sqlite/sqlite-dialect-config.js';
|
|
5
6
|
export * from './dialect/sqlite/sqlite-driver.js';
|
|
6
7
|
export * from './dialect/mysql/mysql-dialect.js';
|
|
8
|
+
export * from './dialect/mysql/mysql-dialect-config.js';
|
|
7
9
|
export * from './dialect/mysql/mysql-driver.js';
|
|
8
10
|
export * from './dialect/postgres/postgres-driver.js';
|
|
11
|
+
export * from './dialect/postgres/postgres-dialect-config.js';
|
|
9
12
|
export * from './dialect/postgres/postgres-dialect.js';
|
package/dist/esm/kysely.d.ts
CHANGED
|
@@ -22,22 +22,24 @@ import { DialectAdapter } from './dialect/dialect-adapter.js';
|
|
|
22
22
|
* This example assumes your database has tables `person` and `pet`:
|
|
23
23
|
*
|
|
24
24
|
* ```ts
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* import { Kysely, Generated, PostgresDialect } from 'kysely'
|
|
26
|
+
*
|
|
27
|
+
* interface PersonTable {
|
|
28
|
+
* id: Generated<number>
|
|
27
29
|
* first_name: string
|
|
28
30
|
* last_name: string
|
|
29
31
|
* }
|
|
30
32
|
*
|
|
31
|
-
* interface
|
|
32
|
-
* id: number
|
|
33
|
+
* interface PetTable {
|
|
34
|
+
* id: Generated<number>
|
|
33
35
|
* owner_id: number
|
|
34
36
|
* name: string
|
|
35
37
|
* species 'cat' | 'dog'
|
|
36
38
|
* }
|
|
37
39
|
*
|
|
38
40
|
* interface Database {
|
|
39
|
-
* person:
|
|
40
|
-
* pet:
|
|
41
|
+
* person: PersonTable,
|
|
42
|
+
* pet: PetTable
|
|
41
43
|
* }
|
|
42
44
|
*
|
|
43
45
|
* const db = new Kysely<Database>({
|