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.
Files changed (150) hide show
  1. package/README.md +122 -9
  2. package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +205 -0
  3. package/dist/cjs/dialect/mysql/mysql-dialect-config.js +2 -0
  4. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -205
  5. package/dist/cjs/dialect/mysql/mysql-dialect.js +2 -1
  6. package/dist/cjs/dialect/mysql/mysql-driver.d.ts +1 -1
  7. package/dist/cjs/dialect/mysql/mysql-driver.js +11 -3
  8. package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +103 -0
  9. package/dist/cjs/dialect/postgres/postgres-dialect-config.js +2 -0
  10. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -103
  11. package/dist/cjs/dialect/postgres/postgres-dialect.js +2 -1
  12. package/dist/cjs/dialect/postgres/postgres-driver.d.ts +1 -1
  13. package/dist/cjs/dialect/postgres/postgres-driver.js +12 -3
  14. package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +43 -0
  15. package/dist/cjs/dialect/sqlite/sqlite-dialect-config.js +2 -0
  16. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -43
  17. package/dist/cjs/dialect/sqlite/sqlite-dialect.js +2 -1
  18. package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +1 -1
  19. package/dist/cjs/dialect/sqlite/sqlite-driver.js +11 -3
  20. package/dist/cjs/driver/dummy-driver.d.ts +68 -0
  21. package/dist/cjs/driver/dummy-driver.js +62 -0
  22. package/dist/cjs/driver/runtime-driver.d.ts +1 -1
  23. package/dist/cjs/driver/runtime-driver.js +30 -33
  24. package/dist/cjs/index-nodeless.d.ts +2 -0
  25. package/dist/cjs/index-nodeless.js +2 -0
  26. package/dist/cjs/index.d.ts +3 -0
  27. package/dist/cjs/index.js +3 -0
  28. package/dist/cjs/kysely.d.ts +8 -6
  29. package/dist/cjs/kysely.js +8 -6
  30. package/dist/cjs/migration/migrator.d.ts +2 -2
  31. package/dist/cjs/operation-node/primitive-value-list-node.d.ts +2 -3
  32. package/dist/cjs/operation-node/value-node.d.ts +3 -4
  33. package/dist/cjs/parser/complex-expression-parser.d.ts +1 -0
  34. package/dist/cjs/parser/complex-expression-parser.js +5 -1
  35. package/dist/cjs/parser/default-value-parser.d.ts +2 -3
  36. package/dist/cjs/parser/default-value-parser.js +2 -2
  37. package/dist/cjs/parser/insert-values-parser.js +4 -3
  38. package/dist/cjs/parser/reference-parser.d.ts +2 -3
  39. package/dist/cjs/parser/value-parser.d.ts +2 -3
  40. package/dist/cjs/parser/value-parser.js +6 -7
  41. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
  42. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.js +19 -0
  43. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
  44. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.js +42 -0
  45. package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
  46. package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
  47. package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
  48. package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
  49. package/dist/cjs/query-builder/delete-query-builder.d.ts +51 -9
  50. package/dist/cjs/query-builder/delete-query-builder.js +56 -8
  51. package/dist/cjs/query-builder/expression-builder.d.ts +1 -1
  52. package/dist/cjs/query-builder/expression-builder.js +2 -2
  53. package/dist/cjs/query-builder/function-builder.d.ts +29 -5
  54. package/dist/cjs/query-builder/function-builder.js +31 -7
  55. package/dist/cjs/query-builder/insert-query-builder.d.ts +53 -11
  56. package/dist/cjs/query-builder/insert-query-builder.js +58 -10
  57. package/dist/cjs/query-builder/select-query-builder.d.ts +58 -16
  58. package/dist/cjs/query-builder/select-query-builder.js +64 -15
  59. package/dist/cjs/query-builder/update-query-builder.d.ts +52 -9
  60. package/dist/cjs/query-builder/update-query-builder.js +57 -8
  61. package/dist/cjs/query-compiler/default-query-compiler.d.ts +1 -2
  62. package/dist/cjs/query-creator.d.ts +2 -2
  63. package/dist/cjs/query-creator.js +2 -2
  64. package/dist/cjs/schema/alter-table-builder.d.ts +30 -4
  65. package/dist/cjs/schema/alter-table-builder.js +2 -5
  66. package/dist/cjs/schema/column-definition-builder.d.ts +27 -2
  67. package/dist/cjs/schema/create-view-builder.js +1 -1
  68. package/dist/cjs/util/log.d.ts +1 -0
  69. package/dist/cjs/util/log.js +3 -0
  70. package/dist/cjs/util/object-utils.d.ts +5 -5
  71. package/dist/cjs/util/object-utils.js +52 -11
  72. package/dist/cjs/util/type-utils.d.ts +21 -0
  73. package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +205 -0
  74. package/dist/esm/dialect/mysql/mysql-dialect-config.js +2 -0
  75. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -205
  76. package/dist/esm/dialect/mysql/mysql-dialect.js +2 -1
  77. package/dist/esm/dialect/mysql/mysql-driver.d.ts +1 -1
  78. package/dist/esm/dialect/mysql/mysql-driver.js +12 -4
  79. package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +103 -0
  80. package/dist/esm/dialect/postgres/postgres-dialect-config.js +2 -0
  81. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -103
  82. package/dist/esm/dialect/postgres/postgres-dialect.js +2 -1
  83. package/dist/esm/dialect/postgres/postgres-driver.d.ts +1 -1
  84. package/dist/esm/dialect/postgres/postgres-driver.js +12 -3
  85. package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +43 -0
  86. package/dist/esm/dialect/sqlite/sqlite-dialect-config.js +2 -0
  87. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -43
  88. package/dist/esm/dialect/sqlite/sqlite-dialect.js +2 -1
  89. package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +1 -1
  90. package/dist/esm/dialect/sqlite/sqlite-driver.js +12 -4
  91. package/dist/esm/driver/dummy-driver.d.ts +68 -0
  92. package/dist/esm/driver/dummy-driver.js +59 -0
  93. package/dist/esm/driver/runtime-driver.d.ts +1 -1
  94. package/dist/esm/driver/runtime-driver.js +29 -32
  95. package/dist/esm/index-nodeless.d.ts +2 -0
  96. package/dist/esm/index-nodeless.js +2 -0
  97. package/dist/esm/index.d.ts +3 -0
  98. package/dist/esm/index.js +3 -0
  99. package/dist/esm/kysely.d.ts +8 -6
  100. package/dist/esm/kysely.js +8 -6
  101. package/dist/esm/migration/migrator.d.ts +2 -2
  102. package/dist/esm/operation-node/primitive-value-list-node.d.ts +2 -3
  103. package/dist/esm/operation-node/value-node.d.ts +3 -4
  104. package/dist/esm/parser/complex-expression-parser.d.ts +1 -0
  105. package/dist/esm/parser/complex-expression-parser.js +3 -0
  106. package/dist/esm/parser/default-value-parser.d.ts +2 -3
  107. package/dist/esm/parser/default-value-parser.js +2 -2
  108. package/dist/esm/parser/insert-values-parser.js +5 -4
  109. package/dist/esm/parser/reference-parser.d.ts +2 -3
  110. package/dist/esm/parser/reference-parser.js +1 -1
  111. package/dist/esm/parser/value-parser.d.ts +2 -3
  112. package/dist/esm/parser/value-parser.js +8 -9
  113. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
  114. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.js +16 -0
  115. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
  116. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.js +39 -0
  117. package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
  118. package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
  119. package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
  120. package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
  121. package/dist/esm/query-builder/delete-query-builder.d.ts +51 -9
  122. package/dist/esm/query-builder/delete-query-builder.js +56 -8
  123. package/dist/esm/query-builder/expression-builder.d.ts +1 -1
  124. package/dist/esm/query-builder/expression-builder.js +1 -1
  125. package/dist/esm/query-builder/function-builder.d.ts +29 -5
  126. package/dist/esm/query-builder/function-builder.js +31 -7
  127. package/dist/esm/query-builder/insert-query-builder.d.ts +53 -11
  128. package/dist/esm/query-builder/insert-query-builder.js +58 -10
  129. package/dist/esm/query-builder/select-query-builder.d.ts +58 -16
  130. package/dist/esm/query-builder/select-query-builder.js +64 -15
  131. package/dist/esm/query-builder/update-query-builder.d.ts +52 -9
  132. package/dist/esm/query-builder/update-query-builder.js +57 -8
  133. package/dist/esm/query-compiler/default-query-compiler.d.ts +1 -2
  134. package/dist/esm/query-creator.d.ts +2 -2
  135. package/dist/esm/query-creator.js +2 -2
  136. package/dist/esm/schema/alter-table-builder.d.ts +30 -4
  137. package/dist/esm/schema/alter-table-builder.js +2 -5
  138. package/dist/esm/schema/column-definition-builder.d.ts +27 -2
  139. package/dist/esm/schema/create-view-builder.js +1 -1
  140. package/dist/esm/util/log.d.ts +1 -0
  141. package/dist/esm/util/log.js +3 -0
  142. package/dist/esm/util/object-utils.d.ts +5 -5
  143. package/dist/esm/util/object-utils.js +50 -9
  144. package/dist/esm/util/type-utils.d.ts +21 -0
  145. package/package.json +11 -5
  146. package/.prettierignore +0 -1
  147. package/dist/cjs/util/dynamic-import.d.ts +0 -2
  148. package/dist/cjs/util/dynamic-import.js +0 -32
  149. package/dist/esm/util/dynamic-import.d.ts +0 -2
  150. package/dist/esm/util/dynamic-import.js +0 -28
@@ -0,0 +1,103 @@
1
+ /// <reference types="node" />
2
+ import * as stream from 'stream';
3
+ import { ConnectionOptions } from 'tls';
4
+ import { DatabaseConnection } from '../../driver/database-connection.js';
5
+ /**
6
+ * Config for the PostgreSQL dialect.
7
+ *
8
+ * This interface is equal to `pg` library's `Pool` config:
9
+ *
10
+ * https://node-postgres.com/api/pool
11
+ * https://node-postgres.com/api/client
12
+ */
13
+ export interface PostgresDialectConfig {
14
+ /**
15
+ * defaults process.env.PGUSER || process.env.USER.
16
+ */
17
+ user?: string;
18
+ /**
19
+ * default process.env.PGDATABASE || process.env.USER
20
+ */
21
+ database?: string;
22
+ /**
23
+ * default process.env.PGPASSWORD
24
+ */
25
+ password?: string | (() => string | Promise<string>);
26
+ /**
27
+ * default process.env.PGPORT
28
+ */
29
+ port?: number;
30
+ /**
31
+ * default process.env.PGHOST
32
+ */
33
+ host?: string;
34
+ /**
35
+ * e.g. postgres:*user:password@host:5432/database
36
+ */
37
+ connectionString?: string;
38
+ /**
39
+ * passed directly to node.TLSSocket, supports all tls.connect options
40
+ */
41
+ ssl?: boolean | ConnectionOptions;
42
+ /**
43
+ * Number of milliseconds to wait before timing out when connecting a new client
44
+ * by default this is 0 which means no timeout.
45
+ */
46
+ connectionTimeoutMillis?: number;
47
+ /**
48
+ * Maximum number of clients the pool should contain. by default this is set to 10.
49
+ */
50
+ max?: number;
51
+ /**
52
+ * Minimum number of clients the pool should contain
53
+ */
54
+ min?: number;
55
+ /**
56
+ * Number of milliseconds a client must sit idle in the pool and not be checked out
57
+ * before it is disconnected from the backend and discarded.
58
+ *
59
+ * default is 10000 (10 seconds) - set to 0 to disable auto-disconnection of idle clients.
60
+ */
61
+ idleTimeoutMillis?: number;
62
+ /**
63
+ * Default behavior is the pool will keep clients open & connected to the backend
64
+ * until idleTimeoutMillis expire for each client and node will maintain a ref
65
+ * to the socket on the client, keeping the event loop alive until all clients are closed
66
+ * after being idle or the pool is manually shutdown with `pool.end()`.
67
+ *
68
+ * Setting `allowExitOnIdle: true` in the config will allow the node event loop to exit
69
+ * as soon as all clients in the pool are idle, even if their socket is still open
70
+ * to the PostgreSQL server. This can be handy in scripts & tests
71
+ * where you don't want to wait for your clients to go idle before your process exits.
72
+ */
73
+ allowExitOnIdle?: boolean;
74
+ log?: (...messages: any[]) => void;
75
+ /**
76
+ * Number of milliseconds before a statement in query will time out, default is no timeout.
77
+ */
78
+ statement_timeout?: false | number;
79
+ /**
80
+ * Number of milliseconds before terminating any session with an open idle transaction.
81
+ * Default is no timeout.
82
+ */
83
+ idle_in_transaction_session_timeout?: number;
84
+ /**
85
+ * Number of milliseconds before a query call will timeout, default is no timeout.
86
+ */
87
+ query_timeout?: number;
88
+ /**
89
+ * The name of the application that created this Client instance.
90
+ */
91
+ application_name?: string;
92
+ /**
93
+ * Called once for each created connection.
94
+ *
95
+ * This is a Kysely specific feature and does not come from the `pg` module.
96
+ */
97
+ onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
98
+ keepAlive?: boolean;
99
+ keepAliveInitialDelayMillis?: number;
100
+ types?: any;
101
+ stream?: stream.Duplex;
102
+ parseInputDatesAsUTC?: boolean;
103
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 { DatabaseConnection } from '../../driver/database-connection.js';
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
- }
@@ -5,6 +5,7 @@ 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
+ const object_utils_js_1 = require("../../util/object-utils.js");
8
9
  /**
9
10
  * PostgreSQL dialect that uses the [pg](https://node-postgres.com/) library.
10
11
  *
@@ -18,7 +19,7 @@ const postgres_adapter_js_1 = require("./postgres-adapter.js");
18
19
  class PostgresDialect {
19
20
  #config;
20
21
  constructor(config) {
21
- this.#config = config;
22
+ this.#config = (0, object_utils_js_1.freeze)({ ...config });
22
23
  }
23
24
  createDriver() {
24
25
  return new postgres_driver_js_1.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);
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostgresDriver = void 0;
4
4
  const compiled_query_js_1 = require("../../query-compiler/compiled-query.js");
5
- const dynamic_import_js_1 = require("../../util/dynamic-import.js");
5
+ const object_utils_js_1 = require("../../util/object-utils.js");
6
6
  const PRIVATE_RELEASE_METHOD = Symbol();
7
7
  class PostgresDriver {
8
8
  #config;
9
9
  #connections = new WeakMap();
10
10
  #pool = null;
11
11
  constructor(config) {
12
- this.#config = config;
12
+ this.#config = (0, object_utils_js_1.freeze)({ ...config });
13
13
  }
14
14
  async init() {
15
15
  // Import the `pg` module here instead at the top of the file
@@ -66,7 +66,16 @@ class PostgresDriver {
66
66
  exports.PostgresDriver = PostgresDriver;
67
67
  async function importPgPool() {
68
68
  try {
69
- return await (0, dynamic_import_js_1.importNamedFunction)('pg', 'Pool');
69
+ // The imported module name must be a string literal to make
70
+ // some bundlers work. So don't move this code behind a helper
71
+ // for example.
72
+ const pgModule = await Promise.resolve().then(() => require('pg'));
73
+ if ((0, object_utils_js_1.isFunction)(pgModule.Pool)) {
74
+ return pgModule.Pool;
75
+ }
76
+ else {
77
+ return pgModule.default.Pool;
78
+ }
70
79
  }
71
80
  catch (error) {
72
81
  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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 { DatabaseConnection } from '../../driver/database-connection.js';
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
- }
@@ -5,6 +5,7 @@ const sqlite_driver_js_1 = require("./sqlite-driver.js");
5
5
  const sqlite_query_compiler_js_1 = require("./sqlite-query-compiler.js");
6
6
  const sqlite_introspector_js_1 = require("./sqlite-introspector.js");
7
7
  const sqlite_adapter_js_1 = require("./sqlite-adapter.js");
8
+ const object_utils_js_1 = require("../../util/object-utils.js");
8
9
  /**
9
10
  * SQLite dialect that uses the [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) library.
10
11
  *
@@ -15,7 +16,7 @@ const sqlite_adapter_js_1 = require("./sqlite-adapter.js");
15
16
  class SqliteDialect {
16
17
  #config;
17
18
  constructor(config) {
18
- this.#config = config;
19
+ this.#config = (0, object_utils_js_1.freeze)({ ...config });
19
20
  }
20
21
  createDriver() {
21
22
  return new sqlite_driver_js_1.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);
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqliteDriver = void 0;
4
4
  const compiled_query_js_1 = require("../../query-compiler/compiled-query.js");
5
- const dynamic_import_js_1 = require("../../util/dynamic-import.js");
6
5
  const object_utils_js_1 = require("../../util/object-utils.js");
7
6
  class SqliteDriver {
8
7
  #config;
@@ -10,7 +9,7 @@ class SqliteDriver {
10
9
  #db;
11
10
  #connection;
12
11
  constructor(config) {
13
- this.#config = config;
12
+ this.#config = (0, object_utils_js_1.freeze)({ ...config });
14
13
  }
15
14
  async init() {
16
15
  // Import the `better-sqlite3` module here instead at the top of the file
@@ -63,7 +62,16 @@ class SqliteDriver {
63
62
  exports.SqliteDriver = SqliteDriver;
64
63
  async function importBetterSqlite3Database() {
65
64
  try {
66
- return await (0, dynamic_import_js_1.importFunction)('better-sqlite3');
65
+ // The imported module name must be a string literal to make
66
+ // some bundlers work. So don't move this code behind a helper
67
+ // for example.
68
+ const sqliteModule = await Promise.resolve().then(() => require('better-sqlite3'));
69
+ if ((0, object_utils_js_1.isFunction)(sqliteModule)) {
70
+ return sqliteModule;
71
+ }
72
+ else {
73
+ return sqliteModule.default;
74
+ }
67
75
  }
68
76
  catch (error) {
69
77
  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,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DummyDriver = void 0;
4
+ /**
5
+ * A driver that does absolutely nothing.
6
+ *
7
+ * You can use this to create Kysely instances solely for building queries
8
+ *
9
+ * ### Examples
10
+ *
11
+ * This example creates a Kysely instance for building postgres queries:
12
+ *
13
+ * ```ts
14
+ * const db = new Kysely<Database>({
15
+ * dialect: {
16
+ * createAdapter() {
17
+ * return new PostgresAdapter()
18
+ * },
19
+ * createDriver() {
20
+ * return new DummyDriver()
21
+ * },
22
+ * createIntrospector(db: Kysely<any>) {
23
+ * return new PostgresIntrospector(db)
24
+ * },
25
+ * createQueryCompiler() {
26
+ * return new PostgresQueryCompiler()
27
+ * },
28
+ * },
29
+ * })
30
+ * ```
31
+ */
32
+ class DummyDriver {
33
+ async init() {
34
+ // Nothing to do here.
35
+ }
36
+ async acquireConnection() {
37
+ return new DummyConnection();
38
+ }
39
+ async beginTransaction() {
40
+ // Nothing to do here.
41
+ }
42
+ async commitTransaction() {
43
+ // Nothing to do here.
44
+ }
45
+ async rollbackTransaction() {
46
+ // Nothing to do here.
47
+ }
48
+ async releaseConnection() {
49
+ // Nothing to do here.
50
+ }
51
+ async destroy() {
52
+ // Nothing to do here.
53
+ }
54
+ }
55
+ exports.DummyDriver = DummyDriver;
56
+ class DummyConnection {
57
+ async executeQuery() {
58
+ return {
59
+ rows: [],
60
+ };
61
+ }
62
+ }
@@ -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(runtimeConnection: DatabaseConnection): Promise<void>;
31
+ releaseConnection(connection: DatabaseConnection): Promise<void>;
32
32
  /**
33
33
  * Begins a transaction.
34
34
  */