kysely 0.29.5 → 0.29.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 +1 -1
- package/dist/dialect/mysql/mysql-dialect-config.d.ts +10 -0
- package/dist/dialect/pglite/pglite-dialect-config.d.ts +10 -0
- package/dist/dialect/postgres/postgres-dialect-config.d.ts +10 -0
- package/dist/dialect/postgres/postgres-driver.js +5 -0
- package/dist/dialect/sqlite/sqlite-dialect-config.d.ts +10 -0
- package/dist/helpers/mssql.d.ts +3 -1
- package/dist/helpers/mssql.js +4 -2
- package/dist/kysely.d.ts +40 -2
- package/dist/kysely.js +82 -27
- package/dist/query-builder/on-conflict-builder.d.ts +5 -2
- package/package.json +23 -24
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[](https://stand-with-ukraine.pp.ua)
|
|
2
2
|
|
|
3
3
|
[](https://github.com/kysely-org/kysely/releases/latest)
|
|
4
|
-
[](https://socket.dev/npm/package/kysely/overview/0.29.7)
|
|
5
5
|
[](https://github.com/kysely-org/kysely)
|
|
6
6
|
[](https://github.com/kysely-org/kysely/blob/master/LICENSE)
|
|
7
7
|
[](https://github.com/kysely-org/kysely/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)
|
|
@@ -19,6 +19,16 @@ export interface MysqlDialectConfig {
|
|
|
19
19
|
*
|
|
20
20
|
* If a function is provided, it's called once when the first query is executed.
|
|
21
21
|
*
|
|
22
|
+
* Once the driver has initialized, {@link Kysely.destroy} calls
|
|
23
|
+
* `pool.end(callback)`, whether the pool is supplied directly or returned by a
|
|
24
|
+
* function. If initialization hasn't started, `db.destroy()` does nothing,
|
|
25
|
+
* even if the supplied pool has been used outside Kysely.
|
|
26
|
+
*
|
|
27
|
+
* If Kysely is not the sole consumer of the pool, or the pool's lifecycle is
|
|
28
|
+
* managed elsewhere, skip `db.destroy()`. Let the application call
|
|
29
|
+
* `pool.end(callback)` once all consumers, including Kysely, have finished. No
|
|
30
|
+
* separate cleanup of the `Kysely` instance is needed.
|
|
31
|
+
*
|
|
22
32
|
* https://github.com/sidorares/node-mysql2#using-connection-pools
|
|
23
33
|
*/
|
|
24
34
|
pool: MysqlPool | ((options?: AbortableOperationOptions) => Promise<MysqlPool>);
|
|
@@ -16,6 +16,16 @@ export interface PGliteDialectConfig {
|
|
|
16
16
|
*
|
|
17
17
|
* If a function is provided, it's called once when the first query is executed.
|
|
18
18
|
*
|
|
19
|
+
* Once the driver has initialized, {@link Kysely.destroy} calls `pglite.close()`
|
|
20
|
+
* if the instance is still open, whether it is supplied directly or returned
|
|
21
|
+
* by a function. If initialization hasn't started, `db.destroy()` does nothing,
|
|
22
|
+
* even if the supplied instance has been used outside Kysely.
|
|
23
|
+
*
|
|
24
|
+
* If Kysely is not the sole consumer of the instance, or its lifecycle is
|
|
25
|
+
* managed elsewhere, skip `db.destroy()`. Let the application call
|
|
26
|
+
* `pglite.close()` once all consumers, including Kysely, have finished. No
|
|
27
|
+
* separate cleanup of the `Kysely` instance is needed.
|
|
28
|
+
*
|
|
19
29
|
* https://pglite.dev/docs/api#main-constructor
|
|
20
30
|
*/
|
|
21
31
|
pglite: PGlite | ((options?: AbortableOperationOptions) => PGlite | Promise<PGlite>);
|
|
@@ -42,6 +42,16 @@ export interface PostgresDialectConfig {
|
|
|
42
42
|
*
|
|
43
43
|
* If a function is provided, it's called once when the first query is executed.
|
|
44
44
|
*
|
|
45
|
+
* Once the driver has initialized, {@link Kysely.destroy} calls `pool.end()`,
|
|
46
|
+
* whether the pool is supplied directly or returned by a function. If
|
|
47
|
+
* initialization hasn't started, `db.destroy()` does nothing, even if the
|
|
48
|
+
* supplied pool has been used outside Kysely.
|
|
49
|
+
*
|
|
50
|
+
* If Kysely is not the sole consumer of the pool, or the pool's lifecycle is
|
|
51
|
+
* managed elsewhere, skip `db.destroy()`. Let the application call `pool.end()`
|
|
52
|
+
* once all consumers, including Kysely, have finished. No separate cleanup of
|
|
53
|
+
* the `Kysely` instance is needed.
|
|
54
|
+
*
|
|
45
55
|
* https://node-postgres.com/apis/pool
|
|
46
56
|
*/
|
|
47
57
|
pool: PostgresPool | ((options?: AbortableOperationOptions) => Promise<PostgresPool>);
|
|
@@ -19,6 +19,11 @@ export class PostgresDriver {
|
|
|
19
19
|
}
|
|
20
20
|
async acquireConnection(options) {
|
|
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, {
|
|
@@ -9,6 +9,16 @@ export interface SqliteDialectConfig {
|
|
|
9
9
|
*
|
|
10
10
|
* If a function is provided, it's called once when the first query is executed.
|
|
11
11
|
*
|
|
12
|
+
* Once the driver has initialized, {@link Kysely.destroy} calls
|
|
13
|
+
* `database.close()`, whether the database is supplied directly or returned by
|
|
14
|
+
* a function. If initialization hasn't started, `db.destroy()` does nothing,
|
|
15
|
+
* even if the supplied database has been used outside Kysely.
|
|
16
|
+
*
|
|
17
|
+
* If Kysely is not the sole consumer of the database, or the database's
|
|
18
|
+
* lifecycle is managed elsewhere, skip `db.destroy()`. Let the application
|
|
19
|
+
* call `database.close()` once all consumers, including Kysely, have finished.
|
|
20
|
+
* No separate cleanup of the `Kysely` instance is needed.
|
|
21
|
+
*
|
|
12
22
|
* https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options
|
|
13
23
|
*/
|
|
14
24
|
database: SqliteDatabase | ((options?: AbortableOperationOptions) => Promise<SqliteDatabase>);
|
package/dist/helpers/mssql.d.ts
CHANGED
|
@@ -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
|
-
* '{"
|
|
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
|
* ```
|
package/dist/helpers/mssql.js
CHANGED
|
@@ -205,11 +205,13 @@ export function jsonObjectFrom(expr) {
|
|
|
205
205
|
*
|
|
206
206
|
* ```sql
|
|
207
207
|
* select "id", json_query(
|
|
208
|
-
* '{"
|
|
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.
|
|
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
|
}
|
package/dist/kysely.d.ts
CHANGED
|
@@ -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.
|
|
32
|
+
* constructor. The dialect manages database connections and may use a shared
|
|
33
|
+
* pool or database instance.
|
|
33
34
|
*
|
|
34
35
|
* ### Examples
|
|
35
36
|
*
|
|
@@ -450,7 +451,16 @@ export declare class Kysely<DB> extends QueryCreator<DB> implements QueryExecuto
|
|
|
450
451
|
/**
|
|
451
452
|
* Releases all resources and disconnects from the database.
|
|
452
453
|
*
|
|
453
|
-
*
|
|
454
|
+
* Call this when you are done using the `Kysely` instance and Kysely is
|
|
455
|
+
* responsible for closing its connections, pool, or database instance.
|
|
456
|
+
*
|
|
457
|
+
* If the pool or database instance is shared with other consumers or its
|
|
458
|
+
* lifecycle is managed elsewhere, skip this call. Let the application close it
|
|
459
|
+
* once all consumers, including Kysely, have finished. No separate cleanup of
|
|
460
|
+
* the `Kysely` instance is needed.
|
|
461
|
+
*
|
|
462
|
+
* The driver is initialized lazily. If initialization hasn't started, this
|
|
463
|
+
* method does nothing.
|
|
454
464
|
*/
|
|
455
465
|
destroy(): Promise<void>;
|
|
456
466
|
/**
|
|
@@ -616,6 +626,10 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
|
|
|
616
626
|
/**
|
|
617
627
|
* Commits the transaction.
|
|
618
628
|
*
|
|
629
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
630
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
631
|
+
* exit the loop before committing.
|
|
632
|
+
*
|
|
619
633
|
* See {@link rollback}.
|
|
620
634
|
*
|
|
621
635
|
* ### Examples
|
|
@@ -641,6 +655,13 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
|
|
|
641
655
|
/**
|
|
642
656
|
* Rolls back the transaction.
|
|
643
657
|
*
|
|
658
|
+
* The connection is released even if the rollback fails, so the transaction
|
|
659
|
+
* cannot be used afterwards in either case.
|
|
660
|
+
*
|
|
661
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
662
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
663
|
+
* exit the loop before rolling back.
|
|
664
|
+
*
|
|
644
665
|
* See {@link commit} and {@link rollbackToSavepoint}.
|
|
645
666
|
*
|
|
646
667
|
* ### Examples
|
|
@@ -666,6 +687,10 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
|
|
|
666
687
|
/**
|
|
667
688
|
* Creates a savepoint with a given name.
|
|
668
689
|
*
|
|
690
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
691
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
692
|
+
* exit the loop before creating a savepoint.
|
|
693
|
+
*
|
|
669
694
|
* See {@link rollbackToSavepoint} and {@link releaseSavepoint}.
|
|
670
695
|
*
|
|
671
696
|
* For a type-safe experience, you should use the returned instance from now on.
|
|
@@ -696,6 +721,10 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
|
|
|
696
721
|
/**
|
|
697
722
|
* Rolls back to a savepoint with a given name.
|
|
698
723
|
*
|
|
724
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
725
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
726
|
+
* exit the loop before rolling back to a savepoint.
|
|
727
|
+
*
|
|
699
728
|
* See {@link savepoint} and {@link releaseSavepoint}.
|
|
700
729
|
*
|
|
701
730
|
* You must use the same instance returned by {@link savepoint}, or
|
|
@@ -727,6 +756,10 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
|
|
|
727
756
|
/**
|
|
728
757
|
* Releases a savepoint with a given name.
|
|
729
758
|
*
|
|
759
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
760
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
761
|
+
* exit the loop before releasing a savepoint.
|
|
762
|
+
*
|
|
730
763
|
* See {@link savepoint} and {@link rollbackToSavepoint}.
|
|
731
764
|
*
|
|
732
765
|
* You must use the same instance returned by {@link savepoint}, or
|
|
@@ -782,8 +815,13 @@ export declare class ControlledTransaction<DB, S extends string[] = []> extends
|
|
|
782
815
|
$omitTables<T extends keyof DB>(): ControlledTransaction<DB extends object ? Omit<DB, T> : DB, S>;
|
|
783
816
|
$pickTables<T extends keyof DB>(): ControlledTransaction<DB extends object ? Pick<DB, T> : DB, S>;
|
|
784
817
|
}
|
|
818
|
+
interface ControlledTransctionState {
|
|
819
|
+
isCommitted: boolean;
|
|
820
|
+
isRolledBack: boolean;
|
|
821
|
+
}
|
|
785
822
|
interface ControlledTransactionProps extends KyselyProps {
|
|
786
823
|
readonly connection: ControlledConnection;
|
|
824
|
+
readonly state: ControlledTransctionState;
|
|
787
825
|
}
|
|
788
826
|
export declare class Command<T> {
|
|
789
827
|
#private;
|
package/dist/kysely.js
CHANGED
|
@@ -23,7 +23,8 @@ Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
|
|
|
23
23
|
* The main Kysely class.
|
|
24
24
|
*
|
|
25
25
|
* You should create one instance of `Kysely` per database using the {@link Kysely}
|
|
26
|
-
* constructor.
|
|
26
|
+
* constructor. The dialect manages database connections and may use a shared
|
|
27
|
+
* pool or database instance.
|
|
27
28
|
*
|
|
28
29
|
* ### Examples
|
|
29
30
|
*
|
|
@@ -505,7 +506,16 @@ export class Kysely extends QueryCreator {
|
|
|
505
506
|
/**
|
|
506
507
|
* Releases all resources and disconnects from the database.
|
|
507
508
|
*
|
|
508
|
-
*
|
|
509
|
+
* Call this when you are done using the `Kysely` instance and Kysely is
|
|
510
|
+
* responsible for closing its connections, pool, or database instance.
|
|
511
|
+
*
|
|
512
|
+
* If the pool or database instance is shared with other consumers or its
|
|
513
|
+
* lifecycle is managed elsewhere, skip this call. Let the application close it
|
|
514
|
+
* once all consumers, including Kysely, have finished. No separate cleanup of
|
|
515
|
+
* the `Kysely` instance is needed.
|
|
516
|
+
*
|
|
517
|
+
* The driver is initialized lazily. If initialization hasn't started, this
|
|
518
|
+
* method does nothing.
|
|
509
519
|
*/
|
|
510
520
|
async destroy() {
|
|
511
521
|
await this.#props.driver.destroy();
|
|
@@ -714,10 +724,17 @@ export class ControlledTransactionBuilder {
|
|
|
714
724
|
const settings = { isolationLevel, accessMode };
|
|
715
725
|
validateTransactionSettings(settings);
|
|
716
726
|
const connection = await provideControlledConnection(this.#props.executor);
|
|
717
|
-
|
|
727
|
+
try {
|
|
728
|
+
await this.#props.driver.beginTransaction(connection.connection, settings);
|
|
729
|
+
}
|
|
730
|
+
catch (error) {
|
|
731
|
+
connection.release();
|
|
732
|
+
throw error;
|
|
733
|
+
}
|
|
718
734
|
return new ControlledTransaction({
|
|
719
735
|
...props,
|
|
720
736
|
connection,
|
|
737
|
+
state: { isCommitted: false, isRolledBack: false },
|
|
721
738
|
executor: this.#props.executor.withConnectionProvider(new SingleConnectionProvider(connection.connection)),
|
|
722
739
|
});
|
|
723
740
|
}
|
|
@@ -725,29 +742,30 @@ export class ControlledTransactionBuilder {
|
|
|
725
742
|
export class ControlledTransaction extends Transaction {
|
|
726
743
|
#props;
|
|
727
744
|
#compileQuery;
|
|
728
|
-
#state;
|
|
729
745
|
constructor(props) {
|
|
730
|
-
const state = { isCommitted: false, isRolledBack: false };
|
|
731
746
|
props = {
|
|
732
747
|
...props,
|
|
733
|
-
executor: new NotCommittedOrRolledBackAssertingExecutor(props.executor, state),
|
|
748
|
+
executor: new NotCommittedOrRolledBackAssertingExecutor(props.executor, props.state),
|
|
734
749
|
};
|
|
735
|
-
const { connection, ...transactionProps } = props;
|
|
750
|
+
const { connection, state, ...transactionProps } = props;
|
|
736
751
|
super(transactionProps);
|
|
737
752
|
this.#props = freeze(props);
|
|
738
|
-
this.#state = state;
|
|
739
753
|
const queryId = createQueryId();
|
|
740
754
|
this.#compileQuery = (node) => props.executor.compileQuery(node, queryId);
|
|
741
755
|
}
|
|
742
756
|
get isCommitted() {
|
|
743
|
-
return this.#state.isCommitted;
|
|
757
|
+
return this.#props.state.isCommitted;
|
|
744
758
|
}
|
|
745
759
|
get isRolledBack() {
|
|
746
|
-
return this.#state.isRolledBack;
|
|
760
|
+
return this.#props.state.isRolledBack;
|
|
747
761
|
}
|
|
748
762
|
/**
|
|
749
763
|
* Commits the transaction.
|
|
750
764
|
*
|
|
765
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
766
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
767
|
+
* exit the loop before committing.
|
|
768
|
+
*
|
|
751
769
|
* See {@link rollback}.
|
|
752
770
|
*
|
|
753
771
|
* ### Examples
|
|
@@ -770,16 +788,24 @@ export class ControlledTransaction extends Transaction {
|
|
|
770
788
|
* ```
|
|
771
789
|
*/
|
|
772
790
|
commit() {
|
|
773
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
774
791
|
return new Command(async () => {
|
|
775
|
-
await this.#props.
|
|
776
|
-
|
|
777
|
-
|
|
792
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
793
|
+
await this.#props.driver.commitTransaction(connection);
|
|
794
|
+
this.#props.state.isCommitted = true;
|
|
795
|
+
this.#props.connection.release();
|
|
796
|
+
});
|
|
778
797
|
});
|
|
779
798
|
}
|
|
780
799
|
/**
|
|
781
800
|
* Rolls back the transaction.
|
|
782
801
|
*
|
|
802
|
+
* The connection is released even if the rollback fails, so the transaction
|
|
803
|
+
* cannot be used afterwards in either case.
|
|
804
|
+
*
|
|
805
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
806
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
807
|
+
* exit the loop before rolling back.
|
|
808
|
+
*
|
|
783
809
|
* See {@link commit} and {@link rollbackToSavepoint}.
|
|
784
810
|
*
|
|
785
811
|
* ### Examples
|
|
@@ -802,16 +828,26 @@ export class ControlledTransaction extends Transaction {
|
|
|
802
828
|
* ```
|
|
803
829
|
*/
|
|
804
830
|
rollback() {
|
|
805
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
806
831
|
return new Command(async () => {
|
|
807
|
-
await this.#props.
|
|
808
|
-
|
|
809
|
-
|
|
832
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
833
|
+
// A failed rollback can't be meaningfully retried (e.g. dead connection).
|
|
834
|
+
try {
|
|
835
|
+
await this.#props.driver.rollbackTransaction(connection);
|
|
836
|
+
}
|
|
837
|
+
finally {
|
|
838
|
+
this.#props.state.isRolledBack = true;
|
|
839
|
+
this.#props.connection.release();
|
|
840
|
+
}
|
|
841
|
+
});
|
|
810
842
|
});
|
|
811
843
|
}
|
|
812
844
|
/**
|
|
813
845
|
* Creates a savepoint with a given name.
|
|
814
846
|
*
|
|
847
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
848
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
849
|
+
* exit the loop before creating a savepoint.
|
|
850
|
+
*
|
|
815
851
|
* See {@link rollbackToSavepoint} and {@link releaseSavepoint}.
|
|
816
852
|
*
|
|
817
853
|
* For a type-safe experience, you should use the returned instance from now on.
|
|
@@ -839,15 +875,20 @@ export class ControlledTransaction extends Transaction {
|
|
|
839
875
|
* ```
|
|
840
876
|
*/
|
|
841
877
|
savepoint(savepointName) {
|
|
842
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
843
878
|
return new Command(async () => {
|
|
844
|
-
await this.#props.
|
|
879
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
880
|
+
await this.#props.driver.savepoint?.(connection, savepointName, this.#compileQuery);
|
|
881
|
+
});
|
|
845
882
|
return new ControlledTransaction({ ...this.#props });
|
|
846
883
|
});
|
|
847
884
|
}
|
|
848
885
|
/**
|
|
849
886
|
* Rolls back to a savepoint with a given name.
|
|
850
887
|
*
|
|
888
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
889
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
890
|
+
* exit the loop before rolling back to a savepoint.
|
|
891
|
+
*
|
|
851
892
|
* See {@link savepoint} and {@link releaseSavepoint}.
|
|
852
893
|
*
|
|
853
894
|
* You must use the same instance returned by {@link savepoint}, or
|
|
@@ -876,15 +917,20 @@ export class ControlledTransaction extends Transaction {
|
|
|
876
917
|
* ```
|
|
877
918
|
*/
|
|
878
919
|
rollbackToSavepoint(savepointName) {
|
|
879
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
880
920
|
return new Command(async () => {
|
|
881
|
-
await this.#props.
|
|
921
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
922
|
+
await this.#props.driver.rollbackToSavepoint?.(connection, savepointName, this.#compileQuery);
|
|
923
|
+
});
|
|
882
924
|
return new ControlledTransaction({ ...this.#props });
|
|
883
925
|
});
|
|
884
926
|
}
|
|
885
927
|
/**
|
|
886
928
|
* Releases a savepoint with a given name.
|
|
887
929
|
*
|
|
930
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
931
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
932
|
+
* exit the loop before releasing a savepoint.
|
|
933
|
+
*
|
|
888
934
|
* See {@link savepoint} and {@link rollbackToSavepoint}.
|
|
889
935
|
*
|
|
890
936
|
* You must use the same instance returned by {@link savepoint}, or
|
|
@@ -918,9 +964,10 @@ export class ControlledTransaction extends Transaction {
|
|
|
918
964
|
* ```
|
|
919
965
|
*/
|
|
920
966
|
releaseSavepoint(savepointName) {
|
|
921
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
922
967
|
return new Command(async () => {
|
|
923
|
-
await this.#props.
|
|
968
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
969
|
+
await this.#props.driver.releaseSavepoint?.(connection, savepointName, this.#compileQuery);
|
|
970
|
+
});
|
|
924
971
|
return new ControlledTransaction({ ...this.#props });
|
|
925
972
|
});
|
|
926
973
|
}
|
|
@@ -1004,15 +1051,23 @@ class NotCommittedOrRolledBackAssertingExecutor {
|
|
|
1004
1051
|
return this.#executor.compileQuery(node, queryId);
|
|
1005
1052
|
}
|
|
1006
1053
|
provideConnection(consumer, options) {
|
|
1007
|
-
|
|
1054
|
+
assertNotCommittedOrRolledBack(this.#state);
|
|
1055
|
+
return this.#executor.provideConnection(async (connection) => {
|
|
1056
|
+
assertNotCommittedOrRolledBack(this.#state);
|
|
1057
|
+
return await consumer(connection);
|
|
1058
|
+
}, options);
|
|
1008
1059
|
}
|
|
1009
1060
|
executeQuery(compiledQuery, options) {
|
|
1010
1061
|
assertNotCommittedOrRolledBack(this.#state);
|
|
1011
|
-
return this.#executor
|
|
1062
|
+
return this.#executor
|
|
1063
|
+
.withConnectionProvider(this)
|
|
1064
|
+
.executeQuery(compiledQuery, options);
|
|
1012
1065
|
}
|
|
1013
1066
|
stream(compiledQuery, chunkSize, options) {
|
|
1014
1067
|
assertNotCommittedOrRolledBack(this.#state);
|
|
1015
|
-
return this.#executor
|
|
1068
|
+
return this.#executor
|
|
1069
|
+
.withConnectionProvider(this)
|
|
1070
|
+
.stream(compiledQuery, chunkSize, options);
|
|
1016
1071
|
}
|
|
1017
1072
|
withConnectionProvider(connectionProvider) {
|
|
1018
1073
|
return new NotCommittedOrRolledBackAssertingExecutor(this.#executor.withConnectionProvider(connectionProvider), this.#state);
|
|
@@ -506,7 +506,7 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
506
506
|
* "last_name" = excluded."last_name"
|
|
507
507
|
* ```
|
|
508
508
|
*/
|
|
509
|
-
doUpdateSet(update: UpdateObjectExpression<
|
|
509
|
+
doUpdateSet(update: UpdateObjectExpression<OnConflictUpdateDatabase<DB, TB>, OnConflictTables<TB>, OnConflictTables<TB>>): OnConflictUpdateBuilder<OnConflictDatabase<DB, TB>, OnConflictTables<TB>>;
|
|
510
510
|
/**
|
|
511
511
|
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
|
512
512
|
* what the provided function returns.
|
|
@@ -516,9 +516,12 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
516
516
|
export interface OnConflictBuilderProps {
|
|
517
517
|
readonly onConflictNode: OnConflictNode;
|
|
518
518
|
}
|
|
519
|
-
export type
|
|
519
|
+
export type OnConflictUpdateDatabase<DB, TB extends keyof DB> = {
|
|
520
520
|
[K in keyof DB | 'excluded']: Updateable<K extends keyof DB ? DB[K] : DB[TB]>;
|
|
521
521
|
};
|
|
522
|
+
export type OnConflictDatabase<DB, TB extends keyof DB> = {
|
|
523
|
+
[K in keyof DB | 'excluded']: K extends keyof DB ? DB[K] : DB[TB];
|
|
524
|
+
};
|
|
522
525
|
export type OnConflictTables<TB> = TB | 'excluded';
|
|
523
526
|
export declare class OnConflictDoNothingBuilder<DB, _TB extends keyof DB> implements OperationNodeSource {
|
|
524
527
|
#private;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kysely",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.7",
|
|
4
4
|
"description": "Type safe SQL query builder",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -62,68 +62,67 @@
|
|
|
62
62
|
],
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@arethetypeswrong/cli": "0.18.5",
|
|
65
|
-
"@electric-sql/pglite": "0.5.
|
|
65
|
+
"@electric-sql/pglite": "0.5.10",
|
|
66
66
|
"@types/better-sqlite3": "9.6.0",
|
|
67
67
|
"@types/chai": "5.2.3",
|
|
68
68
|
"@types/chai-as-promised": "8.0.2",
|
|
69
69
|
"@types/mocha": "10.0.10",
|
|
70
|
-
"@types/node": "26.
|
|
71
|
-
"@types/pg": "8.
|
|
70
|
+
"@types/node": "26.6.5",
|
|
71
|
+
"@types/pg": "8.23.1",
|
|
72
72
|
"@types/pg-cursor": "2.7.2",
|
|
73
73
|
"@types/prototype-pollution-vulnerable-lodash.merge-dont-upgrade": "npm:@types/lodash.merge@4.6.1",
|
|
74
74
|
"@types/semver": "7.8.0",
|
|
75
75
|
"@types/sinon": "22.0.0",
|
|
76
76
|
"better-sqlite3": "13.0.3",
|
|
77
|
-
"chai": "6.
|
|
77
|
+
"chai": "6.3.0",
|
|
78
78
|
"chai-as-promised": "8.0.2",
|
|
79
79
|
"esbuild": "0.28.2",
|
|
80
80
|
"jsr": "0.14.3",
|
|
81
|
-
"mocha": "
|
|
82
|
-
"mysql2": "3.
|
|
81
|
+
"mocha": "12.0.3",
|
|
82
|
+
"mysql2": "3.24.6",
|
|
83
83
|
"pathe": "2.0.3",
|
|
84
|
-
"pg": "8.23.
|
|
85
|
-
"pg-cursor": "2.22.
|
|
86
|
-
"playwright": "1.
|
|
87
|
-
"prettier": "3.9.
|
|
84
|
+
"pg": "8.23.1",
|
|
85
|
+
"pg-cursor": "2.22.1",
|
|
86
|
+
"playwright": "1.64.1",
|
|
87
|
+
"prettier": "3.9.10",
|
|
88
88
|
"prototype-pollution-vulnerable-lodash.merge-dont-upgrade": "npm:lodash.merge@4.6.1",
|
|
89
|
-
"remeda": "2.
|
|
89
|
+
"remeda": "2.51.0",
|
|
90
90
|
"semver": "7.8.5",
|
|
91
91
|
"sinon": "22.1.0",
|
|
92
|
-
"std-env": "4.2.0",
|
|
93
92
|
"tarn": "3.1.2",
|
|
94
|
-
"tedious": "20.
|
|
93
|
+
"tedious": "20.3.7",
|
|
95
94
|
"tsd": "0.33.0",
|
|
96
|
-
"tsx": "4.23.
|
|
95
|
+
"tsx": "4.23.15",
|
|
97
96
|
"typescript": "7.0.2",
|
|
98
97
|
"typescript-6": "npm:typescript@6.0.3"
|
|
99
98
|
},
|
|
100
99
|
"scripts": {
|
|
101
100
|
"clean": "rm -rf dist & rm -rf test/node/dist & rm -rf test/browser/bundle.js",
|
|
102
|
-
"bench:ts": "pnpm build && node --experimental-strip-types ./test/ts-benchmarks/index.ts",
|
|
103
|
-
"test": "pnpm build && pnpm test:node:build && pnpm test:node:run && pnpm test:typings && pnpm test:esmimports && pnpm test:exports",
|
|
101
|
+
"bench:ts": "pnpm run build && node --experimental-strip-types ./test/ts-benchmarks/index.ts",
|
|
102
|
+
"test": "pnpm run build && pnpm run test:node:build && pnpm run test:node:run && pnpm run test:typings && pnpm run test:esmimports && pnpm run test:exports",
|
|
104
103
|
"test:node:build": "tsc -p test/node",
|
|
105
|
-
"test:node": "pnpm build && pnpm test:node:build && pnpm test:node:run",
|
|
104
|
+
"test:node": "pnpm run build && pnpm run test:node:build && pnpm run test:node:run",
|
|
106
105
|
"test:node:run": "mocha --timeout 15000 test/node/dist/**/*.test.js",
|
|
107
106
|
"test:browser:build": "rm -rf test/browser/bundle.js && esbuild test/browser/main.ts --bundle --outfile=test/browser/bundle.js",
|
|
108
|
-
"test:browser": "pnpm build && pnpm test:browser:build && node test/browser/test.js",
|
|
109
|
-
"test:bun": "pnpm build && bun link && cd test/bun && bun install && bun run test",
|
|
110
|
-
"test:cloudflare-workers": "pnpm build && pnpm -r
|
|
107
|
+
"test:browser": "pnpm run build && pnpm run test:browser:build && node test/browser/test.js",
|
|
108
|
+
"test:bun": "pnpm run build && bun link && cd test/bun && bun install && bun run test",
|
|
109
|
+
"test:cloudflare-workers": "pnpm run build && pnpm -r --filter kysely-cloudflare-workers-test run test",
|
|
111
110
|
"test:deno": "deno run --allow-env --allow-read --allow-net --no-lock test/deno/test.ts",
|
|
112
111
|
"test:typings": "tsd test/typings",
|
|
113
112
|
"test:esmimports": "node scripts/check-esm-imports.cjs",
|
|
114
113
|
"test:esbuild": "esbuild --bundle --platform=node --external:pg-native dist/index.js --outfile=/dev/null",
|
|
115
114
|
"test:exports": "attw --profile esm-only --pack . && node scripts/check-exports.cjs",
|
|
116
115
|
"test:jsdocs": "deno check --doc-only --no-lock --unstable-sloppy-imports --config=\"deno.check.json\" ./src",
|
|
117
|
-
"test:outdatedts": "pnpm build && cd test/outdated-ts && pnpm i && pnpm test",
|
|
116
|
+
"test:outdatedts": "pnpm run build && cd test/outdated-ts && pnpm i && pnpm run test",
|
|
118
117
|
"lint:deno": "deno lint --config=\"deno.lint.json\" ./src",
|
|
119
118
|
"prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
|
|
120
|
-
"build": "pnpm clean && tsc && pnpm script:add-deno-type-references && pnpm script:copy-interface-doc",
|
|
119
|
+
"build": "pnpm run clean && tsc && pnpm run script:add-deno-type-references && pnpm run script:copy-interface-doc",
|
|
121
120
|
"script:copy-interface-doc": "node scripts/copy-interface-documentation.cjs",
|
|
122
121
|
"script:add-deno-type-references": "node scripts/add-deno-type-references.cjs",
|
|
123
122
|
"script:align-versions": "node --experimental-strip-types scripts/align-versions.mts",
|
|
124
123
|
"script:generate-site-examples": "node scripts/generate-site-examples.mts",
|
|
125
124
|
"script:override-tsconfig-target": "node --experimental-strip-types scripts/override-tsconfig-target.mts",
|
|
126
125
|
"script:remove-global-augmentations": "node --experimental-strip-types scripts/remove-global-augmentations.mts",
|
|
127
|
-
"version": "pnpm script:align-versions && git add ."
|
|
126
|
+
"version": "pnpm run script:align-versions && git add ."
|
|
128
127
|
}
|
|
129
128
|
}
|