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
@@ -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
  }
@@ -2,6 +2,7 @@
2
2
  import { DEFAULT_MIGRATION_TABLE } from '../../migration/migrator.js';
3
3
  import { sql } from '../../raw-builder/sql.js';
4
4
  import { DialectAdapterBase } from '../dialect-adapter-base.js';
5
+ const LOCK_PRINCIPAL = 'dbo';
5
6
  export class MssqlAdapter extends DialectAdapterBase {
6
7
  get supportsCreateIfNotExists() {
7
8
  return false;
@@ -12,14 +13,19 @@ export class MssqlAdapter extends DialectAdapterBase {
12
13
  get supportsOutput() {
13
14
  return true;
14
15
  }
15
- async acquireMigrationLock(db) {
16
- // Acquire a transaction-level exclusive lock on the migrations table.
16
+ async acquireMigrationLock(db, _opt) {
17
+ // Acquire a session-level exclusive lock on the migrations table. A
18
+ // session-level lock (as opposed to the default transaction-level lock)
19
+ // stays held after the migration transaction commits and until we release
20
+ // it explicitly in `releaseMigrationLock` OR the session ends. This way we
21
+ // know the lock is either released by us after successful or failed
22
+ // migrations OR it's released by SQL Server if the connection dies.
17
23
  // https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-getapplock-transact-sql?view=sql-server-ver16
18
- await sql `exec sp_getapplock @DbPrincipal = ${sql.lit('dbo')}, @Resource = ${sql.lit(DEFAULT_MIGRATION_TABLE)}, @LockMode = ${sql.lit('Exclusive')}`.execute(db);
24
+ await sql `exec sp_getapplock @DbPrincipal = ${sql.lit(LOCK_PRINCIPAL)}, @Resource = ${sql.lit(DEFAULT_MIGRATION_TABLE)}, @LockMode = ${sql.lit('Exclusive')}, @LockOwner = ${sql.lit('Session')}`.execute(db);
19
25
  }
20
- async releaseMigrationLock() {
21
- // Nothing to do here. `sp_getapplock` is automatically released at the
22
- // end of the transaction and since `supportsTransactionalDdl` true, we know
23
- // the `db` instance passed to acquireMigrationLock is actually a transaction.
26
+ async releaseMigrationLock(db, _opt) {
27
+ // Release the session-level lock acquired in `acquireMigrationLock`.
28
+ // https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-releaseapplock-transact-sql?view=sql-server-ver16
29
+ await sql `exec sp_releaseapplock @DbPrincipal = ${sql.lit(LOCK_PRINCIPAL)}, @Resource = ${sql.lit(DEFAULT_MIGRATION_TABLE)}, @LockOwner = ${sql.lit('Session')}`.execute(db);
24
30
  }
25
31
  }
@@ -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
  }
@@ -1,7 +1,8 @@
1
1
  /// <reference types="./mysql-query-compiler.d.ts" />
2
2
  import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
3
- const LITERAL_ESCAPE_REGEX = /\\|'/g;
3
+ const LITERAL_ESCAPE_REGEX = /[\\']/g;
4
4
  const ID_WRAP_REGEX = /`/g;
5
+ const JSON_PATH_MEMBER_ESCAPE_REGEX = /[\\'"]/g;
5
6
  export class MysqlQueryCompiler extends DefaultQueryCompiler {
6
7
  getCurrentParameterPlaceholder() {
7
8
  return '?';
@@ -37,6 +38,14 @@ export class MysqlQueryCompiler extends DefaultQueryCompiler {
37
38
  sanitizeStringLiteral(value) {
38
39
  return value.replace(LITERAL_ESCAPE_REGEX, (char) => char === '\\' ? '\\\\' : "''");
39
40
  }
41
+ /**
42
+ * Member values appear inside `"..."` in the JSON path, which itself sits
43
+ * inside a SQL string literal. They must therefore be escaped twice — once
44
+ * for the JSON path grammar, then again for MySQL's string literal parser.
45
+ */
46
+ sanitizeJSONPathMemberValue(value) {
47
+ return value.replace(JSON_PATH_MEMBER_ESCAPE_REGEX, (char) => char === '\\' ? '\\\\\\\\' : char === "'" ? "''" : '\\\\"');
48
+ }
40
49
  visitCreateIndex(node) {
41
50
  this.append('create ');
42
51
  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
  }
@@ -1,8 +1,8 @@
1
1
  /// <reference types="./postgres-adapter.d.ts" />
2
2
  import { sql } from '../../raw-builder/sql.js';
3
3
  import { DialectAdapterBase } from '../dialect-adapter-base.js';
4
- // Random id for our transaction lock.
5
4
  const LOCK_ID = BigInt('3853314791062309107');
5
+ const LOCK_TIMEOUT_MILLISECONDS = 60 * 60 * 1_000;
6
6
  export class PostgresAdapter extends DialectAdapterBase {
7
7
  get supportsTransactionalDdl() {
8
8
  return true;
@@ -11,12 +11,18 @@ export class PostgresAdapter extends DialectAdapterBase {
11
11
  return true;
12
12
  }
13
13
  async acquireMigrationLock(db, _opt) {
14
- // Acquire a transaction level advisory lock.
15
- await sql `select pg_advisory_xact_lock(${sql.lit(LOCK_ID)})`.execute(db);
14
+ // in 1 RTT, acquire a session-level advisory lock with a timeout.
15
+ //
16
+ // if ever this runs inside a transaction, niche edge case we support - the
17
+ // user is responsible to set a different timeout value or disable (`0` value).
18
+ await sql `
19
+ with set_timeout as (
20
+ select set_config('lock_timeout', '${sql.lit(LOCK_TIMEOUT_MILLISECONDS)}', true) as config_val
21
+ )
22
+ select pg_advisory_lock(${sql.lit(LOCK_ID)})
23
+ from set_timeout`.execute(db);
16
24
  }
17
- async releaseMigrationLock(_db, _opt) {
18
- // Nothing to do here. `pg_advisory_xact_lock` is automatically released at the
19
- // end of the transaction and since `supportsTransactionalDdl` true, we know
20
- // the `db` instance passed to acquireMigrationLock is actually a transaction.
25
+ async releaseMigrationLock(db, _opt) {
26
+ await sql `select pg_advisory_unlock(${sql.lit(LOCK_ID)})`.execute(db);
21
27
  }
22
28
  }
@@ -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>);
@@ -19,6 +19,11 @@ export class PostgresDriver {
19
19
  }
20
20
  async acquireConnection() {
21
21
  const client = await this.#pool.connect();
22
+ // `destroy` was called while the connection was being acquired.
23
+ if (!this.#pool) {
24
+ client.release();
25
+ throw new Error('driver has already been destroyed');
26
+ }
22
27
  let connection = this.#connections.get(client);
23
28
  if (!connection) {
24
29
  connection = new PostgresConnection(client, {
@@ -71,20 +71,26 @@ export class PostgresIntrospector {
71
71
  };
72
72
  }
73
73
  #parseTableMetadata(columns) {
74
- const tableDictionary = new Map();
75
- for (let i = 0, len = columns.length; i < len; i++) {
76
- const column = columns[i];
77
- const { schema, table } = column;
78
- const tableKey = `schema:${schema};table:${table}`;
79
- if (!tableDictionary.has(tableKey)) {
80
- tableDictionary.set(tableKey, freeze({
74
+ const tables = [];
75
+ const schemas = new Map();
76
+ for (const column of columns) {
77
+ let schema = schemas.get(column.schema);
78
+ if (!schema) {
79
+ schema = new Map();
80
+ schemas.set(column.schema, schema);
81
+ }
82
+ let table = schema.get(column.table);
83
+ if (!table) {
84
+ table = freeze({
81
85
  columns: [],
82
86
  isView: column.table_type === 'v',
83
- name: table,
84
- schema,
85
- }));
87
+ name: column.table,
88
+ schema: column.schema,
89
+ });
90
+ schema.set(column.table, table);
91
+ tables.push(table);
86
92
  }
87
- tableDictionary.get(tableKey).columns.push(freeze({
93
+ table.columns.push(freeze({
88
94
  comment: column.column_description ?? undefined,
89
95
  dataType: column.type,
90
96
  dataTypeSchema: column.type_schema,
@@ -94,6 +100,6 @@ export class PostgresIntrospector {
94
100
  name: column.column,
95
101
  }));
96
102
  }
97
- return Array.from(tableDictionary.values());
103
+ return tables;
98
104
  }
99
105
  }
@@ -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
  }
@@ -1,6 +1,7 @@
1
1
  /// <reference types="./sqlite-query-compiler.d.ts" />
2
2
  import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
3
3
  const ID_WRAP_REGEX = /"/g;
4
+ const JSON_PATH_MEMBER_ESCAPE_REGEX = /[\\'"]/g;
4
5
  export class SqliteQueryCompiler extends DefaultQueryCompiler {
5
6
  visitOrAction(node) {
6
7
  this.append('or ');
@@ -27,6 +28,9 @@ export class SqliteQueryCompiler extends DefaultQueryCompiler {
27
28
  sanitizeIdentifier(identifier) {
28
29
  return identifier.replace(ID_WRAP_REGEX, '""');
29
30
  }
31
+ sanitizeJSONPathMemberValue(value) {
32
+ return value.replace(JSON_PATH_MEMBER_ESCAPE_REGEX, (char) => char === '\\' ? '\\\\' : char === "'" ? "''" : '\\"');
33
+ }
30
34
  visitDefaultInsertValue(_) {
31
35
  // sqlite doesn't support the `default` keyword in inserts.
32
36
  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
  * ```
@@ -205,11 +205,13 @@ export function jsonObjectFrom(expr) {
205
205
  *
206
206
  * ```sql
207
207
  * select "id", json_query(
208
- * '{"first":"'+"first_name"+',"last":"'+"last_name"+',"full":"'+concat("first_name", ' ', "last_name")+'"}'
208
+ * '{"'+string_escape(N'first', 'json')+'":"'+string_escape("first_name", 'json')+
209
+ * '","'+string_escape(N'last', 'json')+'":"'+string_escape("last_name", 'json')+
210
+ * '","'+string_escape(N'full', 'json')+'":"'+string_escape(concat("first_name", ' ', "last_name"), 'json')+'"}'
209
211
  * ) as "name"
210
212
  * from "person"
211
213
  * ```
212
214
  */
213
215
  export function jsonBuildObject(obj) {
214
- return sql `json_query('{${sql.join(Object.keys(obj).map((k) => sql `"${sql.raw(k)}":"'+${obj[k]}+'"`), sql `,`)}}')`;
216
+ return sql `json_query('{${sql.join(Object.keys(obj).map((k) => sql `"'+string_escape(N${sql.lit(k)}, 'json')+'":"'+string_escape(${obj[k]}, 'json')+'"`), sql `,`)}}')`;
215
217
  }
@@ -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;