kysely 0.28.16 → 0.28.18

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 (66) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/dialect/mssql/mssql-adapter.d.ts +3 -2
  3. package/dist/cjs/dialect/mssql/mssql-adapter.js +13 -7
  4. package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +10 -0
  5. package/dist/cjs/dialect/mysql/mysql-query-compiler.d.ts +6 -0
  6. package/dist/cjs/dialect/mysql/mysql-query-compiler.js +10 -1
  7. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +1 -1
  8. package/dist/cjs/dialect/postgres/postgres-adapter.js +13 -7
  9. package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +10 -0
  10. package/dist/cjs/dialect/postgres/postgres-driver.js +5 -0
  11. package/dist/cjs/dialect/postgres/postgres-introspector.js +18 -12
  12. package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +10 -0
  13. package/dist/cjs/dialect/sqlite/sqlite-query-compiler.d.ts +1 -0
  14. package/dist/cjs/dialect/sqlite/sqlite-query-compiler.js +4 -0
  15. package/dist/cjs/helpers/mssql.d.ts +3 -1
  16. package/dist/cjs/helpers/mssql.js +4 -2
  17. package/dist/cjs/kysely.d.ts +50 -3
  18. package/dist/cjs/kysely.js +90 -30
  19. package/dist/cjs/migration/migrator.js +22 -19
  20. package/dist/cjs/query-builder/delete-query-builder.d.ts +2 -6
  21. package/dist/cjs/query-builder/insert-query-builder.d.ts +0 -4
  22. package/dist/cjs/query-builder/join-builder.d.ts +2 -2
  23. package/dist/cjs/query-builder/json-path-builder.js +8 -0
  24. package/dist/cjs/query-builder/merge-query-builder.d.ts +0 -8
  25. package/dist/cjs/query-builder/on-conflict-builder.d.ts +5 -2
  26. package/dist/cjs/query-builder/returning-interface.d.ts +0 -4
  27. package/dist/cjs/query-builder/select-query-builder.d.ts +28 -6
  28. package/dist/cjs/query-builder/update-query-builder.d.ts +1 -5
  29. package/dist/cjs/query-compiler/default-query-compiler.d.ts +1 -0
  30. package/dist/cjs/query-compiler/default-query-compiler.js +16 -8
  31. package/dist/cjs/schema/create-type-builder.d.ts +1 -1
  32. package/dist/cjs/schema/create-type-builder.js +1 -1
  33. package/dist/cjs/util/column-type.d.ts +1 -1
  34. package/dist/esm/dialect/mssql/mssql-adapter.d.ts +3 -2
  35. package/dist/esm/dialect/mssql/mssql-adapter.js +13 -7
  36. package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +10 -0
  37. package/dist/esm/dialect/mysql/mysql-query-compiler.d.ts +6 -0
  38. package/dist/esm/dialect/mysql/mysql-query-compiler.js +10 -1
  39. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +1 -1
  40. package/dist/esm/dialect/postgres/postgres-adapter.js +13 -7
  41. package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +10 -0
  42. package/dist/esm/dialect/postgres/postgres-driver.js +5 -0
  43. package/dist/esm/dialect/postgres/postgres-introspector.js +18 -12
  44. package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +10 -0
  45. package/dist/esm/dialect/sqlite/sqlite-query-compiler.d.ts +1 -0
  46. package/dist/esm/dialect/sqlite/sqlite-query-compiler.js +4 -0
  47. package/dist/esm/helpers/mssql.d.ts +3 -1
  48. package/dist/esm/helpers/mssql.js +4 -2
  49. package/dist/esm/kysely.d.ts +50 -3
  50. package/dist/esm/kysely.js +90 -30
  51. package/dist/esm/migration/migrator.js +22 -19
  52. package/dist/esm/query-builder/delete-query-builder.d.ts +2 -6
  53. package/dist/esm/query-builder/insert-query-builder.d.ts +0 -4
  54. package/dist/esm/query-builder/join-builder.d.ts +2 -2
  55. package/dist/esm/query-builder/json-path-builder.js +8 -0
  56. package/dist/esm/query-builder/merge-query-builder.d.ts +0 -8
  57. package/dist/esm/query-builder/on-conflict-builder.d.ts +5 -2
  58. package/dist/esm/query-builder/returning-interface.d.ts +0 -4
  59. package/dist/esm/query-builder/select-query-builder.d.ts +28 -6
  60. package/dist/esm/query-builder/update-query-builder.d.ts +1 -5
  61. package/dist/esm/query-compiler/default-query-compiler.d.ts +1 -0
  62. package/dist/esm/query-compiler/default-query-compiler.js +16 -8
  63. package/dist/esm/schema/create-type-builder.d.ts +1 -1
  64. package/dist/esm/schema/create-type-builder.js +1 -1
  65. package/dist/esm/util/column-type.d.ts +1 -1
  66. package/package.json +36 -34
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://stand-with-ukraine.pp.ua)
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/kysely?style=flat&label=latest)](https://github.com/kysely-org/kysely/releases/latest)
4
- [![Socket Badge](https://badge.socket.dev/npm/package/kysely/0.28.16)](https://socket.dev/npm/package/kysely/overview/0.28.16)
4
+ [![Socket Badge](https://badge.socket.dev/npm/package/kysely/0.28.18)](https://socket.dev/npm/package/kysely/overview/0.28.18)
5
5
  [![Tests](https://github.com/kysely-org/kysely/actions/workflows/test.yml/badge.svg)](https://github.com/kysely-org/kysely)
6
6
  [![License](https://img.shields.io/github/license/kysely-org/kysely?style=flat)](https://github.com/kysely-org/kysely/blob/master/LICENSE)
7
7
  [![Issues](https://img.shields.io/github/issues-closed/kysely-org/kysely?logo=github)](https://github.com/kysely-org/kysely/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)
@@ -1,5 +1,6 @@
1
1
  import type { Kysely } from '../../kysely.js';
2
2
  import { DialectAdapterBase } from '../dialect-adapter-base.js';
3
+ import type { MigrationLockOptions } from '../dialect-adapter.js';
3
4
  export declare class MssqlAdapter extends DialectAdapterBase {
4
5
  /**
5
6
  * Whether or not this dialect supports `if not exists` in creation of tables/schemas/views/etc.
@@ -70,7 +71,7 @@ export declare class MssqlAdapter extends DialectAdapterBase {
70
71
  * `db` is a single connection (session) that will be used to execute the
71
72
  * migrations.
72
73
  */
73
- acquireMigrationLock(db: Kysely<any>): Promise<void>;
74
+ acquireMigrationLock(db: Kysely<any>, _opt: MigrationLockOptions): Promise<void>;
74
75
  /**
75
76
  * Releases the migration lock. See {@link acquireMigrationLock}.
76
77
  *
@@ -79,5 +80,5 @@ export declare class MssqlAdapter extends DialectAdapterBase {
79
80
  * is a single connection (session) that was used to execute the migrations
80
81
  * and the `acquireMigrationLock` call.
81
82
  */
82
- releaseMigrationLock(): Promise<void>;
83
+ releaseMigrationLock(db: Kysely<any>, _opt: MigrationLockOptions): Promise<void>;
83
84
  }
@@ -4,6 +4,7 @@ exports.MssqlAdapter = void 0;
4
4
  const migrator_js_1 = require("../../migration/migrator.js");
5
5
  const sql_js_1 = require("../../raw-builder/sql.js");
6
6
  const dialect_adapter_base_js_1 = require("../dialect-adapter-base.js");
7
+ const LOCK_PRINCIPAL = 'dbo';
7
8
  class MssqlAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
8
9
  get supportsCreateIfNotExists() {
9
10
  return false;
@@ -14,15 +15,20 @@ class MssqlAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
14
15
  get supportsOutput() {
15
16
  return true;
16
17
  }
17
- async acquireMigrationLock(db) {
18
- // Acquire a transaction-level exclusive lock on the migrations table.
18
+ async acquireMigrationLock(db, _opt) {
19
+ // Acquire a session-level exclusive lock on the migrations table. A
20
+ // session-level lock (as opposed to the default transaction-level lock)
21
+ // stays held after the migration transaction commits and until we release
22
+ // it explicitly in `releaseMigrationLock` OR the session ends. This way we
23
+ // know the lock is either released by us after successful or failed
24
+ // migrations OR it's released by SQL Server if the connection dies.
19
25
  // https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-getapplock-transact-sql?view=sql-server-ver16
20
- await (0, sql_js_1.sql) `exec sp_getapplock @DbPrincipal = ${sql_js_1.sql.lit('dbo')}, @Resource = ${sql_js_1.sql.lit(migrator_js_1.DEFAULT_MIGRATION_TABLE)}, @LockMode = ${sql_js_1.sql.lit('Exclusive')}`.execute(db);
26
+ await (0, sql_js_1.sql) `exec sp_getapplock @DbPrincipal = ${sql_js_1.sql.lit(LOCK_PRINCIPAL)}, @Resource = ${sql_js_1.sql.lit(migrator_js_1.DEFAULT_MIGRATION_TABLE)}, @LockMode = ${sql_js_1.sql.lit('Exclusive')}, @LockOwner = ${sql_js_1.sql.lit('Session')}`.execute(db);
21
27
  }
22
- async releaseMigrationLock() {
23
- // Nothing to do here. `sp_getapplock` is automatically released at the
24
- // end of the transaction and since `supportsTransactionalDdl` true, we know
25
- // the `db` instance passed to acquireMigrationLock is actually a transaction.
28
+ async releaseMigrationLock(db, _opt) {
29
+ // Release the session-level lock acquired in `acquireMigrationLock`.
30
+ // https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-releaseapplock-transact-sql?view=sql-server-ver16
31
+ await (0, sql_js_1.sql) `exec sp_releaseapplock @DbPrincipal = ${sql_js_1.sql.lit(LOCK_PRINCIPAL)}, @Resource = ${sql_js_1.sql.lit(migrator_js_1.DEFAULT_MIGRATION_TABLE)}, @LockOwner = ${sql_js_1.sql.lit('Session')}`.execute(db);
26
32
  }
27
33
  }
28
34
  exports.MssqlAdapter = MssqlAdapter;
@@ -10,6 +10,16 @@ export interface MysqlDialectConfig {
10
10
  *
11
11
  * If a function is provided, it's called once when the first query is executed.
12
12
  *
13
+ * Once the driver has initialized, {@link Kysely.destroy} calls
14
+ * `pool.end(callback)`, whether the pool is supplied directly or returned by a
15
+ * function. If initialization hasn't started, `db.destroy()` does nothing,
16
+ * even if the supplied pool has been used outside Kysely.
17
+ *
18
+ * If Kysely is not the sole consumer of the pool, or the pool's lifecycle is
19
+ * managed elsewhere, skip `db.destroy()`. Let the application call
20
+ * `pool.end(callback)` once all consumers, including Kysely, have finished. No
21
+ * separate cleanup of the `Kysely` instance is needed.
22
+ *
13
23
  * https://github.com/sidorares/node-mysql2#using-connection-pools
14
24
  */
15
25
  pool: MysqlPool | (() => Promise<MysqlPool>);
@@ -17,5 +17,11 @@ export declare class MysqlQueryCompiler extends DefaultQueryCompiler {
17
17
  * @see https://dev.mysql.com/doc/refman/9.6/en/string-literals.html
18
18
  */
19
19
  protected sanitizeStringLiteral(value: string): string;
20
+ /**
21
+ * Member values appear inside `"..."` in the JSON path, which itself sits
22
+ * inside a SQL string literal. They must therefore be escaped twice — once
23
+ * for the JSON path grammar, then again for MySQL's string literal parser.
24
+ */
25
+ protected sanitizeJSONPathMemberValue(value: string): string;
20
26
  protected visitCreateIndex(node: CreateIndexNode): void;
21
27
  }
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MysqlQueryCompiler = void 0;
4
4
  const default_query_compiler_js_1 = require("../../query-compiler/default-query-compiler.js");
5
- const LITERAL_ESCAPE_REGEX = /\\|'/g;
5
+ const LITERAL_ESCAPE_REGEX = /[\\']/g;
6
6
  const ID_WRAP_REGEX = /`/g;
7
+ const JSON_PATH_MEMBER_ESCAPE_REGEX = /[\\'"]/g;
7
8
  class MysqlQueryCompiler extends default_query_compiler_js_1.DefaultQueryCompiler {
8
9
  getCurrentParameterPlaceholder() {
9
10
  return '?';
@@ -39,6 +40,14 @@ class MysqlQueryCompiler extends default_query_compiler_js_1.DefaultQueryCompile
39
40
  sanitizeStringLiteral(value) {
40
41
  return value.replace(LITERAL_ESCAPE_REGEX, (char) => char === '\\' ? '\\\\' : "''");
41
42
  }
43
+ /**
44
+ * Member values appear inside `"..."` in the JSON path, which itself sits
45
+ * inside a SQL string literal. They must therefore be escaped twice — once
46
+ * for the JSON path grammar, then again for MySQL's string literal parser.
47
+ */
48
+ sanitizeJSONPathMemberValue(value) {
49
+ return value.replace(JSON_PATH_MEMBER_ESCAPE_REGEX, (char) => char === '\\' ? '\\\\\\\\' : char === "'" ? "''" : '\\\\"');
50
+ }
42
51
  visitCreateIndex(node) {
43
52
  this.append('create ');
44
53
  if (node.unique) {
@@ -76,5 +76,5 @@ export declare class PostgresAdapter extends DialectAdapterBase {
76
76
  * is a single connection (session) that was used to execute the migrations
77
77
  * and the `acquireMigrationLock` call.
78
78
  */
79
- releaseMigrationLock(_db: Kysely<any>, _opt: MigrationLockOptions): Promise<void>;
79
+ releaseMigrationLock(db: Kysely<any>, _opt: MigrationLockOptions): Promise<void>;
80
80
  }
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostgresAdapter = void 0;
4
4
  const sql_js_1 = require("../../raw-builder/sql.js");
5
5
  const dialect_adapter_base_js_1 = require("../dialect-adapter-base.js");
6
- // Random id for our transaction lock.
7
6
  const LOCK_ID = BigInt('3853314791062309107');
7
+ const LOCK_TIMEOUT_MILLISECONDS = 60 * 60 * 1_000;
8
8
  class PostgresAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
9
9
  get supportsTransactionalDdl() {
10
10
  return true;
@@ -13,13 +13,19 @@ class PostgresAdapter extends dialect_adapter_base_js_1.DialectAdapterBase {
13
13
  return true;
14
14
  }
15
15
  async acquireMigrationLock(db, _opt) {
16
- // Acquire a transaction level advisory lock.
17
- await (0, sql_js_1.sql) `select pg_advisory_xact_lock(${sql_js_1.sql.lit(LOCK_ID)})`.execute(db);
16
+ // in 1 RTT, acquire a session-level advisory lock with a timeout.
17
+ //
18
+ // if ever this runs inside a transaction, niche edge case we support - the
19
+ // user is responsible to set a different timeout value or disable (`0` value).
20
+ await (0, sql_js_1.sql) `
21
+ with set_timeout as (
22
+ select set_config('lock_timeout', '${sql_js_1.sql.lit(LOCK_TIMEOUT_MILLISECONDS)}', true) as config_val
23
+ )
24
+ select pg_advisory_lock(${sql_js_1.sql.lit(LOCK_ID)})
25
+ from set_timeout`.execute(db);
18
26
  }
19
- async releaseMigrationLock(_db, _opt) {
20
- // Nothing to do here. `pg_advisory_xact_lock` is automatically released at the
21
- // end of the transaction and since `supportsTransactionalDdl` true, we know
22
- // the `db` instance passed to acquireMigrationLock is actually a transaction.
27
+ async releaseMigrationLock(db, _opt) {
28
+ await (0, sql_js_1.sql) `select pg_advisory_unlock(${sql_js_1.sql.lit(LOCK_ID)})`.execute(db);
23
29
  }
24
30
  }
25
31
  exports.PostgresAdapter = PostgresAdapter;
@@ -8,6 +8,16 @@ export interface PostgresDialectConfig {
8
8
  *
9
9
  * If a function is provided, it's called once when the first query is executed.
10
10
  *
11
+ * Once the driver has initialized, {@link Kysely.destroy} calls `pool.end()`,
12
+ * whether the pool is supplied directly or returned by a function. If
13
+ * initialization hasn't started, `db.destroy()` does nothing, even if the
14
+ * supplied pool has been used outside Kysely.
15
+ *
16
+ * If Kysely is not the sole consumer of the pool, or the pool's lifecycle is
17
+ * managed elsewhere, skip `db.destroy()`. Let the application call `pool.end()`
18
+ * once all consumers, including Kysely, have finished. No separate cleanup of
19
+ * the `Kysely` instance is needed.
20
+ *
11
21
  * https://node-postgres.com/apis/pool
12
22
  */
13
23
  pool: PostgresPool | (() => Promise<PostgresPool>);
@@ -21,6 +21,11 @@ class PostgresDriver {
21
21
  }
22
22
  async acquireConnection() {
23
23
  const client = await this.#pool.connect();
24
+ // `destroy` was called while the connection was being acquired.
25
+ if (!this.#pool) {
26
+ client.release();
27
+ throw new Error('driver has already been destroyed');
28
+ }
24
29
  let connection = this.#connections.get(client);
25
30
  if (!connection) {
26
31
  connection = new PostgresConnection(client, {
@@ -73,20 +73,26 @@ class PostgresIntrospector {
73
73
  };
74
74
  }
75
75
  #parseTableMetadata(columns) {
76
- const tableDictionary = new Map();
77
- for (let i = 0, len = columns.length; i < len; i++) {
78
- const column = columns[i];
79
- const { schema, table } = column;
80
- const tableKey = `schema:${schema};table:${table}`;
81
- if (!tableDictionary.has(tableKey)) {
82
- tableDictionary.set(tableKey, (0, object_utils_js_1.freeze)({
76
+ const tables = [];
77
+ const schemas = new Map();
78
+ for (const column of columns) {
79
+ let schema = schemas.get(column.schema);
80
+ if (!schema) {
81
+ schema = new Map();
82
+ schemas.set(column.schema, schema);
83
+ }
84
+ let table = schema.get(column.table);
85
+ if (!table) {
86
+ table = (0, object_utils_js_1.freeze)({
83
87
  columns: [],
84
88
  isView: column.table_type === 'v',
85
- name: table,
86
- schema,
87
- }));
89
+ name: column.table,
90
+ schema: column.schema,
91
+ });
92
+ schema.set(column.table, table);
93
+ tables.push(table);
88
94
  }
89
- tableDictionary.get(tableKey).columns.push((0, object_utils_js_1.freeze)({
95
+ table.columns.push((0, object_utils_js_1.freeze)({
90
96
  comment: column.column_description ?? undefined,
91
97
  dataType: column.type,
92
98
  dataTypeSchema: column.type_schema,
@@ -96,7 +102,7 @@ class PostgresIntrospector {
96
102
  name: column.column,
97
103
  }));
98
104
  }
99
- return Array.from(tableDictionary.values());
105
+ return tables;
100
106
  }
101
107
  }
102
108
  exports.PostgresIntrospector = PostgresIntrospector;
@@ -8,6 +8,16 @@ export interface SqliteDialectConfig {
8
8
  *
9
9
  * If a function is provided, it's called once when the first query is executed.
10
10
  *
11
+ * Once the driver has initialized, {@link Kysely.destroy} calls
12
+ * `database.close()`, whether the database is supplied directly or returned by
13
+ * a function. If initialization hasn't started, `db.destroy()` does nothing,
14
+ * even if the supplied database has been used outside Kysely.
15
+ *
16
+ * If Kysely is not the sole consumer of the database, or the database's
17
+ * lifecycle is managed elsewhere, skip `db.destroy()`. Let the application
18
+ * call `database.close()` once all consumers, including Kysely, have finished.
19
+ * No separate cleanup of the `Kysely` instance is needed.
20
+ *
11
21
  * https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options
12
22
  */
13
23
  database: SqliteDatabase | (() => Promise<SqliteDatabase>);
@@ -10,5 +10,6 @@ export declare class SqliteQueryCompiler extends DefaultQueryCompiler {
10
10
  protected getRightIdentifierWrapper(): string;
11
11
  protected getAutoIncrement(): string;
12
12
  protected sanitizeIdentifier(identifier: string): string;
13
+ protected sanitizeJSONPathMemberValue(value: string): string;
13
14
  protected visitDefaultInsertValue(_: DefaultInsertValueNode): void;
14
15
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqliteQueryCompiler = void 0;
4
4
  const default_query_compiler_js_1 = require("../../query-compiler/default-query-compiler.js");
5
5
  const ID_WRAP_REGEX = /"/g;
6
+ const JSON_PATH_MEMBER_ESCAPE_REGEX = /[\\'"]/g;
6
7
  class SqliteQueryCompiler extends default_query_compiler_js_1.DefaultQueryCompiler {
7
8
  visitOrAction(node) {
8
9
  this.append('or ');
@@ -29,6 +30,9 @@ class SqliteQueryCompiler extends default_query_compiler_js_1.DefaultQueryCompil
29
30
  sanitizeIdentifier(identifier) {
30
31
  return identifier.replace(ID_WRAP_REGEX, '""');
31
32
  }
33
+ sanitizeJSONPathMemberValue(value) {
34
+ return value.replace(JSON_PATH_MEMBER_ESCAPE_REGEX, (char) => char === '\\' ? '\\\\' : char === "'" ? "''" : '\\"');
35
+ }
32
36
  visitDefaultInsertValue(_) {
33
37
  // sqlite doesn't support the `default` keyword in inserts.
34
38
  this.append('null');
@@ -202,7 +202,9 @@ export declare function jsonObjectFrom<O>(expr: Expression<O>): RawBuilder<Simpl
202
202
  *
203
203
  * ```sql
204
204
  * select "id", json_query(
205
- * '{"first":"'+"first_name"+',"last":"'+"last_name"+',"full":"'+concat("first_name", ' ', "last_name")+'"}'
205
+ * '{"'+string_escape(N'first', 'json')+'":"'+string_escape("first_name", 'json')+
206
+ * '","'+string_escape(N'last', 'json')+'":"'+string_escape("last_name", 'json')+
207
+ * '","'+string_escape(N'full', 'json')+'":"'+string_escape(concat("first_name", ' ', "last_name"), 'json')+'"}'
206
208
  * ) as "name"
207
209
  * from "person"
208
210
  * ```
@@ -209,11 +209,13 @@ function jsonObjectFrom(expr) {
209
209
  *
210
210
  * ```sql
211
211
  * select "id", json_query(
212
- * '{"first":"'+"first_name"+',"last":"'+"last_name"+',"full":"'+concat("first_name", ' ', "last_name")+'"}'
212
+ * '{"'+string_escape(N'first', 'json')+'":"'+string_escape("first_name", 'json')+
213
+ * '","'+string_escape(N'last', 'json')+'":"'+string_escape("last_name", 'json')+
214
+ * '","'+string_escape(N'full', 'json')+'":"'+string_escape(concat("first_name", ' ', "last_name"), 'json')+'"}'
213
215
  * ) as "name"
214
216
  * from "person"
215
217
  * ```
216
218
  */
217
219
  function jsonBuildObject(obj) {
218
- return (0, sql_js_1.sql) `json_query('{${sql_js_1.sql.join(Object.keys(obj).map((k) => (0, sql_js_1.sql) `"${sql_js_1.sql.raw(k)}":"'+${obj[k]}+'"`), (0, sql_js_1.sql) `,`)}}')`;
220
+ return (0, sql_js_1.sql) `json_query('{${sql_js_1.sql.join(Object.keys(obj).map((k) => (0, sql_js_1.sql) `"'+string_escape(N${sql_js_1.sql.lit(k)}, 'json')+'":"'+string_escape(${obj[k]}, 'json')+'"`), (0, sql_js_1.sql) `,`)}}')`;
219
221
  }
@@ -29,7 +29,8 @@ declare global {
29
29
  * The main Kysely class.
30
30
  *
31
31
  * You should create one instance of `Kysely` per database using the {@link Kysely}
32
- * constructor. Each `Kysely` instance maintains its own connection pool.
32
+ * constructor. The dialect manages database connections and may use a shared
33
+ * pool or database instance.
33
34
  *
34
35
  * ### Examples
35
36
  *
@@ -384,7 +385,16 @@ export declare class Kysely<DB> extends QueryCreator<DB> implements QueryExecuto
384
385
  /**
385
386
  * Releases all resources and disconnects from the database.
386
387
  *
387
- * You need to call this when you are done using the `Kysely` instance.
388
+ * Call this when you are done using the `Kysely` instance and Kysely is
389
+ * responsible for closing its connections, pool, or database instance.
390
+ *
391
+ * If the pool or database instance is shared with other consumers or its
392
+ * lifecycle is managed elsewhere, skip this call. Let the application close it
393
+ * once all consumers, including Kysely, have finished. No separate cleanup of
394
+ * the `Kysely` instance is needed.
395
+ *
396
+ * The driver is initialized lazily. If initialization hasn't started, this
397
+ * method does nothing.
388
398
  */
389
399
  destroy(): Promise<void>;
390
400
  /**
@@ -511,7 +521,16 @@ export declare class Transaction<DB> extends Kysely<DB> {
511
521
  /**
512
522
  * Releases all resources and disconnects from the database.
513
523
  *
514
- * You need to call this when you are done using the `Kysely` instance.
524
+ * Call this when you are done using the `Kysely` instance and Kysely is
525
+ * responsible for closing its connections, pool, or database instance.
526
+ *
527
+ * If the pool or database instance is shared with other consumers or its
528
+ * lifecycle is managed elsewhere, skip this call. Let the application close it
529
+ * once all consumers, including Kysely, have finished. No separate cleanup of
530
+ * the `Kysely` instance is needed.
531
+ *
532
+ * The driver is initialized lazily. If initialization hasn't started, this
533
+ * method does nothing.
515
534
  */
516
535
  destroy(): Promise<void>;
517
536
  /**
@@ -646,6 +665,10 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
646
665
  /**
647
666
  * Commits the transaction.
648
667
  *
668
+ * Waits for ongoing queries to finish. Streams must be exhausted or closed
669
+ * before awaiting this command. When consuming a stream with `for await`,
670
+ * exit the loop before committing.
671
+ *
649
672
  * See {@link rollback}.
650
673
  *
651
674
  * ### Examples
@@ -671,6 +694,13 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
671
694
  /**
672
695
  * Rolls back the transaction.
673
696
  *
697
+ * The connection is released even if the rollback fails, so the transaction
698
+ * cannot be used afterwards in either case.
699
+ *
700
+ * Waits for ongoing queries to finish. Streams must be exhausted or closed
701
+ * before awaiting this command. When consuming a stream with `for await`,
702
+ * exit the loop before rolling back.
703
+ *
674
704
  * See {@link commit} and {@link rollbackToSavepoint}.
675
705
  *
676
706
  * ### Examples
@@ -696,6 +726,10 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
696
726
  /**
697
727
  * Creates a savepoint with a given name.
698
728
  *
729
+ * Waits for ongoing queries to finish. Streams must be exhausted or closed
730
+ * before awaiting this command. When consuming a stream with `for await`,
731
+ * exit the loop before creating a savepoint.
732
+ *
699
733
  * See {@link rollbackToSavepoint} and {@link releaseSavepoint}.
700
734
  *
701
735
  * For a type-safe experience, you should use the returned instance from now on.
@@ -726,6 +760,10 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
726
760
  /**
727
761
  * Rolls back to a savepoint with a given name.
728
762
  *
763
+ * Waits for ongoing queries to finish. Streams must be exhausted or closed
764
+ * before awaiting this command. When consuming a stream with `for await`,
765
+ * exit the loop before rolling back to a savepoint.
766
+ *
729
767
  * See {@link savepoint} and {@link releaseSavepoint}.
730
768
  *
731
769
  * You must use the same instance returned by {@link savepoint}, or
@@ -757,6 +795,10 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
757
795
  /**
758
796
  * Releases a savepoint with a given name.
759
797
  *
798
+ * Waits for ongoing queries to finish. Streams must be exhausted or closed
799
+ * before awaiting this command. When consuming a stream with `for await`,
800
+ * exit the loop before releasing a savepoint.
801
+ *
760
802
  * See {@link savepoint} and {@link rollbackToSavepoint}.
761
803
  *
762
804
  * You must use the same instance returned by {@link savepoint}, or
@@ -834,8 +876,13 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
834
876
  */
835
877
  withTables<T extends Record<string, Record<string, any>>>(): ControlledTransaction<DrainOuterGeneric<DB & T>, S>;
836
878
  }
879
+ interface ControlledTransctionState {
880
+ isCommitted: boolean;
881
+ isRolledBack: boolean;
882
+ }
837
883
  interface ControlledTransactionProps extends KyselyProps {
838
884
  readonly connection: ControlledConnection;
885
+ readonly state?: ControlledTransctionState;
839
886
  }
840
887
  export declare class Command<T> {
841
888
  #private;