kysely 0.28.17 → 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.
- package/README.md +1 -1
- package/dist/cjs/dialect/mssql/mssql-adapter.d.ts +3 -2
- package/dist/cjs/dialect/mssql/mssql-adapter.js +13 -7
- package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +10 -0
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-adapter.js +13 -7
- package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +10 -0
- package/dist/cjs/dialect/postgres/postgres-driver.js +5 -0
- package/dist/cjs/dialect/postgres/postgres-introspector.js +18 -12
- package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +10 -0
- package/dist/cjs/helpers/mssql.d.ts +3 -1
- package/dist/cjs/helpers/mssql.js +4 -2
- package/dist/cjs/kysely.d.ts +50 -3
- package/dist/cjs/kysely.js +90 -30
- package/dist/cjs/migration/migrator.js +22 -19
- package/dist/cjs/query-builder/delete-query-builder.d.ts +2 -2
- package/dist/cjs/query-builder/join-builder.d.ts +2 -2
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +5 -2
- package/dist/cjs/query-builder/select-query-builder.d.ts +28 -6
- package/dist/cjs/query-builder/update-query-builder.d.ts +1 -1
- package/dist/cjs/query-compiler/default-query-compiler.js +4 -4
- package/dist/cjs/schema/create-type-builder.d.ts +1 -1
- package/dist/cjs/schema/create-type-builder.js +1 -1
- package/dist/cjs/util/column-type.d.ts +1 -1
- package/dist/esm/dialect/mssql/mssql-adapter.d.ts +3 -2
- package/dist/esm/dialect/mssql/mssql-adapter.js +13 -7
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +10 -0
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-adapter.js +13 -7
- package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +10 -0
- package/dist/esm/dialect/postgres/postgres-driver.js +5 -0
- package/dist/esm/dialect/postgres/postgres-introspector.js +18 -12
- package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +10 -0
- package/dist/esm/helpers/mssql.d.ts +3 -1
- package/dist/esm/helpers/mssql.js +4 -2
- package/dist/esm/kysely.d.ts +50 -3
- package/dist/esm/kysely.js +90 -30
- package/dist/esm/migration/migrator.js +22 -19
- package/dist/esm/query-builder/delete-query-builder.d.ts +2 -2
- package/dist/esm/query-builder/join-builder.d.ts +2 -2
- package/dist/esm/query-builder/on-conflict-builder.d.ts +5 -2
- package/dist/esm/query-builder/select-query-builder.d.ts +28 -6
- package/dist/esm/query-builder/update-query-builder.d.ts +1 -1
- package/dist/esm/query-compiler/default-query-compiler.js +4 -4
- package/dist/esm/schema/create-type-builder.d.ts +1 -1
- package/dist/esm/schema/create-type-builder.js +1 -1
- package/dist/esm/util/column-type.d.ts +1 -1
- package/package.json +36 -34
package/dist/esm/kysely.js
CHANGED
|
@@ -24,7 +24,8 @@ Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
|
|
|
24
24
|
* The main Kysely class.
|
|
25
25
|
*
|
|
26
26
|
* You should create one instance of `Kysely` per database using the {@link Kysely}
|
|
27
|
-
* constructor.
|
|
27
|
+
* constructor. The dialect manages database connections and may use a shared
|
|
28
|
+
* pool or database instance.
|
|
28
29
|
*
|
|
29
30
|
* ### Examples
|
|
30
31
|
*
|
|
@@ -433,7 +434,16 @@ export class Kysely extends QueryCreator {
|
|
|
433
434
|
/**
|
|
434
435
|
* Releases all resources and disconnects from the database.
|
|
435
436
|
*
|
|
436
|
-
*
|
|
437
|
+
* Call this when you are done using the `Kysely` instance and Kysely is
|
|
438
|
+
* responsible for closing its connections, pool, or database instance.
|
|
439
|
+
*
|
|
440
|
+
* If the pool or database instance is shared with other consumers or its
|
|
441
|
+
* lifecycle is managed elsewhere, skip this call. Let the application close it
|
|
442
|
+
* once all consumers, including Kysely, have finished. No separate cleanup of
|
|
443
|
+
* the `Kysely` instance is needed.
|
|
444
|
+
*
|
|
445
|
+
* The driver is initialized lazily. If initialization hasn't started, this
|
|
446
|
+
* method does nothing.
|
|
437
447
|
*/
|
|
438
448
|
async destroy() {
|
|
439
449
|
await this.#props.driver.destroy();
|
|
@@ -606,10 +616,17 @@ export class ControlledTransactionBuilder {
|
|
|
606
616
|
const settings = { isolationLevel, accessMode };
|
|
607
617
|
validateTransactionSettings(settings);
|
|
608
618
|
const connection = await provideControlledConnection(this.#props.executor);
|
|
609
|
-
|
|
619
|
+
try {
|
|
620
|
+
await this.#props.driver.beginTransaction(connection.connection, settings);
|
|
621
|
+
}
|
|
622
|
+
catch (error) {
|
|
623
|
+
connection.release();
|
|
624
|
+
throw error;
|
|
625
|
+
}
|
|
610
626
|
return new ControlledTransaction({
|
|
611
627
|
...props,
|
|
612
628
|
connection,
|
|
629
|
+
state: { isCommitted: false, isRolledBack: false },
|
|
613
630
|
executor: this.#props.executor.withConnectionProvider(new SingleConnectionProvider(connection.connection)),
|
|
614
631
|
});
|
|
615
632
|
}
|
|
@@ -617,29 +634,35 @@ export class ControlledTransactionBuilder {
|
|
|
617
634
|
export class ControlledTransaction extends Transaction {
|
|
618
635
|
#props;
|
|
619
636
|
#compileQuery;
|
|
620
|
-
#state;
|
|
621
637
|
constructor(props) {
|
|
622
|
-
const
|
|
623
|
-
|
|
638
|
+
const transactionState = props.state ?? {
|
|
639
|
+
isCommitted: false,
|
|
640
|
+
isRolledBack: false,
|
|
641
|
+
};
|
|
642
|
+
const controlledProps = {
|
|
624
643
|
...props,
|
|
625
|
-
|
|
644
|
+
state: transactionState,
|
|
645
|
+
executor: new NotCommittedOrRolledBackAssertingExecutor(props.executor, transactionState),
|
|
626
646
|
};
|
|
627
|
-
const { connection, ...transactionProps } =
|
|
647
|
+
const { connection, state, ...transactionProps } = controlledProps;
|
|
628
648
|
super(transactionProps);
|
|
629
|
-
this.#props = freeze(
|
|
630
|
-
this.#state = state;
|
|
649
|
+
this.#props = freeze(controlledProps);
|
|
631
650
|
const queryId = createQueryId();
|
|
632
|
-
this.#compileQuery = (node) =>
|
|
651
|
+
this.#compileQuery = (node) => controlledProps.executor.compileQuery(node, queryId);
|
|
633
652
|
}
|
|
634
653
|
get isCommitted() {
|
|
635
|
-
return this.#state.isCommitted;
|
|
654
|
+
return this.#props.state.isCommitted;
|
|
636
655
|
}
|
|
637
656
|
get isRolledBack() {
|
|
638
|
-
return this.#state.isRolledBack;
|
|
657
|
+
return this.#props.state.isRolledBack;
|
|
639
658
|
}
|
|
640
659
|
/**
|
|
641
660
|
* Commits the transaction.
|
|
642
661
|
*
|
|
662
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
663
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
664
|
+
* exit the loop before committing.
|
|
665
|
+
*
|
|
643
666
|
* See {@link rollback}.
|
|
644
667
|
*
|
|
645
668
|
* ### Examples
|
|
@@ -662,16 +685,24 @@ export class ControlledTransaction extends Transaction {
|
|
|
662
685
|
* ```
|
|
663
686
|
*/
|
|
664
687
|
commit() {
|
|
665
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
666
688
|
return new Command(async () => {
|
|
667
|
-
await this.#props.
|
|
668
|
-
|
|
669
|
-
|
|
689
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
690
|
+
await this.#props.driver.commitTransaction(connection);
|
|
691
|
+
this.#props.state.isCommitted = true;
|
|
692
|
+
this.#props.connection.release();
|
|
693
|
+
});
|
|
670
694
|
});
|
|
671
695
|
}
|
|
672
696
|
/**
|
|
673
697
|
* Rolls back the transaction.
|
|
674
698
|
*
|
|
699
|
+
* The connection is released even if the rollback fails, so the transaction
|
|
700
|
+
* cannot be used afterwards in either case.
|
|
701
|
+
*
|
|
702
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
703
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
704
|
+
* exit the loop before rolling back.
|
|
705
|
+
*
|
|
675
706
|
* See {@link commit} and {@link rollbackToSavepoint}.
|
|
676
707
|
*
|
|
677
708
|
* ### Examples
|
|
@@ -694,16 +725,26 @@ export class ControlledTransaction extends Transaction {
|
|
|
694
725
|
* ```
|
|
695
726
|
*/
|
|
696
727
|
rollback() {
|
|
697
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
698
728
|
return new Command(async () => {
|
|
699
|
-
await this.#props.
|
|
700
|
-
|
|
701
|
-
|
|
729
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
730
|
+
// A failed rollback can't be meaningfully retried (e.g. dead connection).
|
|
731
|
+
try {
|
|
732
|
+
await this.#props.driver.rollbackTransaction(connection);
|
|
733
|
+
}
|
|
734
|
+
finally {
|
|
735
|
+
this.#props.state.isRolledBack = true;
|
|
736
|
+
this.#props.connection.release();
|
|
737
|
+
}
|
|
738
|
+
});
|
|
702
739
|
});
|
|
703
740
|
}
|
|
704
741
|
/**
|
|
705
742
|
* Creates a savepoint with a given name.
|
|
706
743
|
*
|
|
744
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
745
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
746
|
+
* exit the loop before creating a savepoint.
|
|
747
|
+
*
|
|
707
748
|
* See {@link rollbackToSavepoint} and {@link releaseSavepoint}.
|
|
708
749
|
*
|
|
709
750
|
* For a type-safe experience, you should use the returned instance from now on.
|
|
@@ -731,15 +772,20 @@ export class ControlledTransaction extends Transaction {
|
|
|
731
772
|
* ```
|
|
732
773
|
*/
|
|
733
774
|
savepoint(savepointName) {
|
|
734
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
735
775
|
return new Command(async () => {
|
|
736
|
-
await this.#props.
|
|
776
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
777
|
+
await this.#props.driver.savepoint?.(connection, savepointName, this.#compileQuery);
|
|
778
|
+
});
|
|
737
779
|
return new ControlledTransaction({ ...this.#props });
|
|
738
780
|
});
|
|
739
781
|
}
|
|
740
782
|
/**
|
|
741
783
|
* Rolls back to a savepoint with a given name.
|
|
742
784
|
*
|
|
785
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
786
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
787
|
+
* exit the loop before rolling back to a savepoint.
|
|
788
|
+
*
|
|
743
789
|
* See {@link savepoint} and {@link releaseSavepoint}.
|
|
744
790
|
*
|
|
745
791
|
* You must use the same instance returned by {@link savepoint}, or
|
|
@@ -768,15 +814,20 @@ export class ControlledTransaction extends Transaction {
|
|
|
768
814
|
* ```
|
|
769
815
|
*/
|
|
770
816
|
rollbackToSavepoint(savepointName) {
|
|
771
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
772
817
|
return new Command(async () => {
|
|
773
|
-
await this.#props.
|
|
818
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
819
|
+
await this.#props.driver.rollbackToSavepoint?.(connection, savepointName, this.#compileQuery);
|
|
820
|
+
});
|
|
774
821
|
return new ControlledTransaction({ ...this.#props });
|
|
775
822
|
});
|
|
776
823
|
}
|
|
777
824
|
/**
|
|
778
825
|
* Releases a savepoint with a given name.
|
|
779
826
|
*
|
|
827
|
+
* Waits for ongoing queries to finish. Streams must be exhausted or closed
|
|
828
|
+
* before awaiting this command. When consuming a stream with `for await`,
|
|
829
|
+
* exit the loop before releasing a savepoint.
|
|
830
|
+
*
|
|
780
831
|
* See {@link savepoint} and {@link rollbackToSavepoint}.
|
|
781
832
|
*
|
|
782
833
|
* You must use the same instance returned by {@link savepoint}, or
|
|
@@ -810,9 +861,10 @@ export class ControlledTransaction extends Transaction {
|
|
|
810
861
|
* ```
|
|
811
862
|
*/
|
|
812
863
|
releaseSavepoint(savepointName) {
|
|
813
|
-
assertNotCommittedOrRolledBack(this.#state);
|
|
814
864
|
return new Command(async () => {
|
|
815
|
-
await this.#props.
|
|
865
|
+
await this.#props.executor.provideConnection(async (connection) => {
|
|
866
|
+
await this.#props.driver.releaseSavepoint?.(connection, savepointName, this.#compileQuery);
|
|
867
|
+
});
|
|
816
868
|
return new ControlledTransaction({ ...this.#props });
|
|
817
869
|
});
|
|
818
870
|
}
|
|
@@ -889,15 +941,23 @@ class NotCommittedOrRolledBackAssertingExecutor {
|
|
|
889
941
|
return this.#executor.compileQuery(node, queryId);
|
|
890
942
|
}
|
|
891
943
|
provideConnection(consumer) {
|
|
892
|
-
|
|
944
|
+
assertNotCommittedOrRolledBack(this.#state);
|
|
945
|
+
return this.#executor.provideConnection(async (connection) => {
|
|
946
|
+
assertNotCommittedOrRolledBack(this.#state);
|
|
947
|
+
return await consumer(connection);
|
|
948
|
+
});
|
|
893
949
|
}
|
|
894
950
|
executeQuery(compiledQuery) {
|
|
895
951
|
assertNotCommittedOrRolledBack(this.#state);
|
|
896
|
-
return this.#executor
|
|
952
|
+
return this.#executor
|
|
953
|
+
.withConnectionProvider(this)
|
|
954
|
+
.executeQuery(compiledQuery);
|
|
897
955
|
}
|
|
898
956
|
stream(compiledQuery, chunkSize) {
|
|
899
957
|
assertNotCommittedOrRolledBack(this.#state);
|
|
900
|
-
return this.#executor
|
|
958
|
+
return this.#executor
|
|
959
|
+
.withConnectionProvider(this)
|
|
960
|
+
.stream(compiledQuery, chunkSize);
|
|
901
961
|
}
|
|
902
962
|
withConnectionProvider(connectionProvider) {
|
|
903
963
|
return new NotCommittedOrRolledBackAssertingExecutor(this.#executor.withConnectionProvider(connectionProvider), this.#state);
|
|
@@ -410,34 +410,37 @@ export class Migrator {
|
|
|
410
410
|
lockTableSchema: this.#props.migrationTableSchema,
|
|
411
411
|
});
|
|
412
412
|
const run = async (db) => {
|
|
413
|
+
const state = await this.#getState(db);
|
|
414
|
+
if (state.migrations.length === 0) {
|
|
415
|
+
return { results: [] };
|
|
416
|
+
}
|
|
417
|
+
const { direction, step } = getMigrationDirectionAndStep(state);
|
|
418
|
+
if (step <= 0) {
|
|
419
|
+
return { results: [] };
|
|
420
|
+
}
|
|
421
|
+
if (direction === 'Down') {
|
|
422
|
+
return await this.#migrateDown(db, state, step);
|
|
423
|
+
}
|
|
424
|
+
else if (direction === 'Up') {
|
|
425
|
+
return await this.#migrateUp(db, state, step);
|
|
426
|
+
}
|
|
427
|
+
return { results: [] };
|
|
428
|
+
};
|
|
429
|
+
const runWithLock = async (db, cb) => {
|
|
413
430
|
try {
|
|
414
431
|
await adapter.acquireMigrationLock(db, lockOptions);
|
|
415
|
-
|
|
416
|
-
if (state.migrations.length === 0) {
|
|
417
|
-
return { results: [] };
|
|
418
|
-
}
|
|
419
|
-
const { direction, step } = getMigrationDirectionAndStep(state);
|
|
420
|
-
if (step <= 0) {
|
|
421
|
-
return { results: [] };
|
|
422
|
-
}
|
|
423
|
-
if (direction === 'Down') {
|
|
424
|
-
return await this.#migrateDown(db, state, step);
|
|
425
|
-
}
|
|
426
|
-
else if (direction === 'Up') {
|
|
427
|
-
return await this.#migrateUp(db, state, step);
|
|
428
|
-
}
|
|
429
|
-
return { results: [] };
|
|
432
|
+
return await cb(db);
|
|
430
433
|
}
|
|
431
434
|
finally {
|
|
432
435
|
await adapter.releaseMigrationLock(db, lockOptions);
|
|
433
436
|
}
|
|
434
437
|
};
|
|
435
438
|
if (adapter.supportsTransactionalDdl && !this.#props.disableTransactions) {
|
|
436
|
-
return this.#props.db
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return this.#props.db.connection().execute(run);
|
|
439
|
+
return this.#props.db
|
|
440
|
+
.connection()
|
|
441
|
+
.execute((db) => runWithLock(db, (db) => db.transaction().execute((trx) => run(trx))));
|
|
440
442
|
}
|
|
443
|
+
return this.#props.db.connection().execute((db) => runWithLock(db, run));
|
|
441
444
|
}
|
|
442
445
|
async #getState(db) {
|
|
443
446
|
const migrations = await this.#resolveMigrations();
|
|
@@ -1039,7 +1039,7 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1039
1039
|
* delete from `pet` order by `created_at` limit ?
|
|
1040
1040
|
* ```
|
|
1041
1041
|
*/
|
|
1042
|
-
limit
|
|
1042
|
+
limit<VE extends ValueExpression<DB, TB, number>>(limit: VE): DeleteQueryBuilder<DB, TB, O>;
|
|
1043
1043
|
/**
|
|
1044
1044
|
* This can be used to add any additional SQL to the end of the query.
|
|
1045
1045
|
*
|
|
@@ -1122,7 +1122,7 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1122
1122
|
* }>
|
|
1123
1123
|
* ```
|
|
1124
1124
|
*/
|
|
1125
|
-
$if<O2>(condition: boolean, func: (qb: this) => DeleteQueryBuilder<any, any, O2>): O2 extends DeleteResult ? DeleteQueryBuilder<DB, TB, DeleteResult> : O2 extends O & infer E ? DeleteQueryBuilder<DB, TB, O & Partial<E>> : DeleteQueryBuilder<DB, TB, Partial<O2>>;
|
|
1125
|
+
$if<O2>(condition: boolean, func: (qb: this) => DeleteQueryBuilder<any, any, O2>): unknown extends O2 ? DeleteQueryBuilder<any, any, O2> : O2 extends DeleteResult ? DeleteQueryBuilder<DB, TB, DeleteResult> : O2 extends O & infer E ? DeleteQueryBuilder<DB, TB, O & Partial<E>> : DeleteQueryBuilder<DB, TB, Partial<O2>>;
|
|
1126
1126
|
/**
|
|
1127
1127
|
* Change the output type of the query.
|
|
1128
1128
|
*
|
|
@@ -14,14 +14,14 @@ export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNo
|
|
|
14
14
|
* See {@link WhereInterface.where} for documentation and examples.
|
|
15
15
|
*/
|
|
16
16
|
on<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: ComparisonOperatorExpression, rhs: OperandValueExpressionOrList<DB, TB, RE>): JoinBuilder<DB, TB>;
|
|
17
|
-
on
|
|
17
|
+
on<E extends ExpressionOrFactory<DB, TB, SqlBool>>(expression: E): JoinBuilder<DB, TB>;
|
|
18
18
|
/**
|
|
19
19
|
* Just like {@link WhereInterface.whereRef} but adds an item to the join's
|
|
20
20
|
* `on` clause instead.
|
|
21
21
|
*
|
|
22
22
|
* See {@link WhereInterface.whereRef} for documentation and examples.
|
|
23
23
|
*/
|
|
24
|
-
onRef
|
|
24
|
+
onRef<LRE extends ReferenceExpression<DB, TB>, RRE extends ReferenceExpression<DB, TB>>(lhs: LRE, op: ComparisonOperatorExpression, rhs: RRE): JoinBuilder<DB, TB>;
|
|
25
25
|
/**
|
|
26
26
|
* Adds `on true`.
|
|
27
27
|
*/
|
|
@@ -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;
|
|
@@ -1377,7 +1377,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
|
|
|
1377
1377
|
* select "first_name" from "person" limit $1 offset $2
|
|
1378
1378
|
* ```
|
|
1379
1379
|
*/
|
|
1380
|
-
limit
|
|
1380
|
+
limit<VE extends ValueExpression<DB, TB, number | bigint | null>>(limit: VE): SelectQueryBuilder<DB, TB, O>;
|
|
1381
1381
|
/**
|
|
1382
1382
|
* Adds an `offset` clause to the query.
|
|
1383
1383
|
*
|
|
@@ -1400,7 +1400,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O> extends WhereInt
|
|
|
1400
1400
|
* select "first_name" from "person" limit $1 offset $2
|
|
1401
1401
|
* ```
|
|
1402
1402
|
*/
|
|
1403
|
-
offset
|
|
1403
|
+
offset<VE extends ValueExpression<DB, TB, number | bigint>>(offset: VE): SelectQueryBuilder<DB, TB, O>;
|
|
1404
1404
|
/**
|
|
1405
1405
|
* Adds a `fetch` clause to the query.
|
|
1406
1406
|
*
|
|
@@ -2367,22 +2367,44 @@ export interface SelectQueryBuilderProps {
|
|
|
2367
2367
|
export interface AliasedSelectQueryBuilder<O = undefined, A extends string = never> extends AliasedExpression<O, A> {
|
|
2368
2368
|
get isAliasedSelectQueryBuilder(): true;
|
|
2369
2369
|
}
|
|
2370
|
-
|
|
2370
|
+
/**
|
|
2371
|
+
* Guards a join's result type against being computed for an unknown table
|
|
2372
|
+
* expression.
|
|
2373
|
+
*
|
|
2374
|
+
* `TableExpression<DB, TB> extends TE` only holds when `TE` is as wide as its
|
|
2375
|
+
* own constraint, which never happens at a call site - there `TE` is a specific
|
|
2376
|
+
* table name, alias or subquery. It does happen when the compiler asks what a
|
|
2377
|
+
* join returns for an arbitrary table expression, which is what it has to do
|
|
2378
|
+
* whenever it compares two `SelectQueryBuilder` types structurally.
|
|
2379
|
+
*
|
|
2380
|
+
* Without this guard that comparison never terminates on its own: computing the
|
|
2381
|
+
* join result yields a `SelectQueryBuilder` over a wider `DB`, whose own join
|
|
2382
|
+
* methods yield a wider one still, so the compiler only stops when it hits its
|
|
2383
|
+
* internal recursion limit. That limit differs between TypeScript versions - 7.0
|
|
2384
|
+
* searches a level deeper than 5.9 and 6.0 - which made comparing two select
|
|
2385
|
+
* query builders over 6x more expensive there.
|
|
2386
|
+
*
|
|
2387
|
+
* Collapsing to a fixed type makes the recursion converge instead: joining an
|
|
2388
|
+
* unknown table expression again produces the same type, so the compiler
|
|
2389
|
+
* recognises the pair it is already comparing and stops immediately.
|
|
2390
|
+
*/
|
|
2391
|
+
type JoinResultForUnknownTable<O> = SelectQueryBuilder<any, any, O>;
|
|
2392
|
+
export type SelectQueryBuilderWithInnerJoin<DB, TB extends keyof DB, O, TE extends TableExpression<DB, TB>> = TableExpression<DB, TB> extends TE ? JoinResultForUnknownTable<O> : TE extends `${infer T} as ${infer A}` ? T extends keyof DB ? InnerJoinedBuilder<DB, TB, O, A, DB[T]> : never : TE extends keyof DB ? SelectQueryBuilder<DB, TB | TE, O> : TE extends AliasedExpression<infer QO, infer QA> ? InnerJoinedBuilder<DB, TB, O, QA, QO> : TE extends (qb: any) => AliasedExpression<infer QO, infer QA> ? InnerJoinedBuilder<DB, TB, O, QA, QO> : never;
|
|
2371
2393
|
type InnerJoinedBuilder<DB, TB extends keyof DB, O, A extends string, R> = A extends keyof DB ? SelectQueryBuilder<InnerJoinedDB<DB, A, R>, TB | A, O> : SelectQueryBuilder<DB & ShallowRecord<A, R>, TB | A, O>;
|
|
2372
2394
|
type InnerJoinedDB<DB, A extends string, R> = DrainOuterGeneric<{
|
|
2373
2395
|
[C in keyof DB | A]: C extends A ? R : C extends keyof DB ? DB[C] : never;
|
|
2374
2396
|
}>;
|
|
2375
|
-
export type SelectQueryBuilderWithLeftJoin<DB, TB extends keyof DB, O, TE extends TableExpression<DB, TB>> = TE extends `${infer T} as ${infer A}` ? T extends keyof DB ? LeftJoinedBuilder<DB, TB, O, A, DB[T]> : never : TE extends keyof DB ? LeftJoinedBuilder<DB, TB, O, TE, DB[TE]> : TE extends AliasedExpression<infer QO, infer QA> ? LeftJoinedBuilder<DB, TB, O, QA, QO> : TE extends (qb: any) => AliasedExpression<infer QO, infer QA> ? LeftJoinedBuilder<DB, TB, O, QA, QO> : never;
|
|
2397
|
+
export type SelectQueryBuilderWithLeftJoin<DB, TB extends keyof DB, O, TE extends TableExpression<DB, TB>> = TableExpression<DB, TB> extends TE ? JoinResultForUnknownTable<O> : TE extends `${infer T} as ${infer A}` ? T extends keyof DB ? LeftJoinedBuilder<DB, TB, O, A, DB[T]> : never : TE extends keyof DB ? LeftJoinedBuilder<DB, TB, O, TE, DB[TE]> : TE extends AliasedExpression<infer QO, infer QA> ? LeftJoinedBuilder<DB, TB, O, QA, QO> : TE extends (qb: any) => AliasedExpression<infer QO, infer QA> ? LeftJoinedBuilder<DB, TB, O, QA, QO> : never;
|
|
2376
2398
|
type LeftJoinedBuilder<DB, TB extends keyof DB, O, A extends keyof any, R> = A extends keyof DB ? SelectQueryBuilder<LeftJoinedDB<DB, A, R>, TB | A, O> : SelectQueryBuilder<DB & ShallowRecord<A, Nullable<R>>, TB | A, O>;
|
|
2377
2399
|
type LeftJoinedDB<DB, A extends keyof any, R> = DrainOuterGeneric<{
|
|
2378
2400
|
[C in keyof DB | A]: C extends A ? Nullable<R> : C extends keyof DB ? DB[C] : never;
|
|
2379
2401
|
}>;
|
|
2380
|
-
export type SelectQueryBuilderWithRightJoin<DB, TB extends keyof DB, O, TE extends TableExpression<DB, TB>> = TE extends `${infer T} as ${infer A}` ? T extends keyof DB ? RightJoinedBuilder<DB, TB, O, A, DB[T]> : never : TE extends keyof DB ? RightJoinedBuilder<DB, TB, O, TE, DB[TE]> : TE extends AliasedExpression<infer QO, infer QA> ? RightJoinedBuilder<DB, TB, O, QA, QO> : TE extends (qb: any) => AliasedExpression<infer QO, infer QA> ? RightJoinedBuilder<DB, TB, O, QA, QO> : never;
|
|
2402
|
+
export type SelectQueryBuilderWithRightJoin<DB, TB extends keyof DB, O, TE extends TableExpression<DB, TB>> = TableExpression<DB, TB> extends TE ? JoinResultForUnknownTable<O> : TE extends `${infer T} as ${infer A}` ? T extends keyof DB ? RightJoinedBuilder<DB, TB, O, A, DB[T]> : never : TE extends keyof DB ? RightJoinedBuilder<DB, TB, O, TE, DB[TE]> : TE extends AliasedExpression<infer QO, infer QA> ? RightJoinedBuilder<DB, TB, O, QA, QO> : TE extends (qb: any) => AliasedExpression<infer QO, infer QA> ? RightJoinedBuilder<DB, TB, O, QA, QO> : never;
|
|
2381
2403
|
type RightJoinedBuilder<DB, TB extends keyof DB, O, A extends keyof any, R> = SelectQueryBuilder<RightJoinedDB<DB, TB, A, R>, TB | A, O>;
|
|
2382
2404
|
type RightJoinedDB<DB, TB extends keyof DB, A extends keyof any, R> = DrainOuterGeneric<{
|
|
2383
2405
|
[C in keyof DB | A]: C extends A ? R : C extends TB ? Nullable<DB[C]> : C extends keyof DB ? DB[C] : never;
|
|
2384
2406
|
}>;
|
|
2385
|
-
export type SelectQueryBuilderWithFullJoin<DB, TB extends keyof DB, O, TE extends TableExpression<DB, TB>> = TE extends `${infer T} as ${infer A}` ? T extends keyof DB ? OuterJoinedBuilder<DB, TB, O, A, DB[T]> : never : TE extends keyof DB ? OuterJoinedBuilder<DB, TB, O, TE, DB[TE]> : TE extends AliasedExpression<infer QO, infer QA> ? OuterJoinedBuilder<DB, TB, O, QA, QO> : TE extends (qb: any) => AliasedExpression<infer QO, infer QA> ? OuterJoinedBuilder<DB, TB, O, QA, QO> : never;
|
|
2407
|
+
export type SelectQueryBuilderWithFullJoin<DB, TB extends keyof DB, O, TE extends TableExpression<DB, TB>> = TableExpression<DB, TB> extends TE ? JoinResultForUnknownTable<O> : TE extends `${infer T} as ${infer A}` ? T extends keyof DB ? OuterJoinedBuilder<DB, TB, O, A, DB[T]> : never : TE extends keyof DB ? OuterJoinedBuilder<DB, TB, O, TE, DB[TE]> : TE extends AliasedExpression<infer QO, infer QA> ? OuterJoinedBuilder<DB, TB, O, QA, QO> : TE extends (qb: any) => AliasedExpression<infer QO, infer QA> ? OuterJoinedBuilder<DB, TB, O, QA, QO> : never;
|
|
2386
2408
|
type OuterJoinedBuilder<DB, TB extends keyof DB, O, A extends keyof any, R> = SelectQueryBuilder<OuterJoinedBuilderDB<DB, TB, A, R>, TB | A, O>;
|
|
2387
2409
|
type OuterJoinedBuilderDB<DB, TB extends keyof DB, A extends keyof any, R> = DrainOuterGeneric<{
|
|
2388
2410
|
[C in keyof DB | A]: C extends A ? Nullable<R> : C extends TB ? Nullable<DB[C]> : C extends keyof DB ? DB[C] : never;
|
|
@@ -1148,7 +1148,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
|
|
|
1148
1148
|
* }>
|
|
1149
1149
|
* ```
|
|
1150
1150
|
*/
|
|
1151
|
-
$if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<any, any, any, O2>): O2 extends UpdateResult ? UpdateQueryBuilder<DB, UT, TB, UpdateResult> : O2 extends O & infer E ? UpdateQueryBuilder<DB, UT, TB, O & Partial<E>> : UpdateQueryBuilder<DB, UT, TB, Partial<O2>>;
|
|
1151
|
+
$if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<any, any, any, O2>): unknown extends O2 ? UpdateQueryBuilder<any, any, any, O2> : O2 extends UpdateResult ? UpdateQueryBuilder<DB, UT, TB, UpdateResult> : O2 extends O & infer E ? UpdateQueryBuilder<DB, UT, TB, O & Partial<E>> : UpdateQueryBuilder<DB, UT, TB, Partial<O2>>;
|
|
1152
1152
|
/**
|
|
1153
1153
|
* Change the output type of the query.
|
|
1154
1154
|
*
|
|
@@ -260,6 +260,10 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
260
260
|
this.append(' ');
|
|
261
261
|
this.visitNode(node.where);
|
|
262
262
|
}
|
|
263
|
+
if (node.returning) {
|
|
264
|
+
this.append(' ');
|
|
265
|
+
this.visitNode(node.returning);
|
|
266
|
+
}
|
|
263
267
|
if (node.orderBy) {
|
|
264
268
|
this.append(' ');
|
|
265
269
|
this.visitNode(node.orderBy);
|
|
@@ -268,10 +272,6 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
268
272
|
this.append(' ');
|
|
269
273
|
this.visitNode(node.limit);
|
|
270
274
|
}
|
|
271
|
-
if (node.returning) {
|
|
272
|
-
this.append(' ');
|
|
273
|
-
this.visitNode(node.returning);
|
|
274
|
-
}
|
|
275
275
|
if (wrapInParens) {
|
|
276
276
|
this.append(')');
|
|
277
277
|
}
|
|
@@ -170,7 +170,7 @@ export type Insertable<R> = DrainOuterGeneric<object & {
|
|
|
170
170
|
* ```
|
|
171
171
|
*/
|
|
172
172
|
export type Updateable<R> = DrainOuterGeneric<{
|
|
173
|
-
[K in UpdateKeys<R>]?: UpdateType<R[K]
|
|
173
|
+
[K in UpdateKeys<R>]?: UpdateType<R[K]> | undefined;
|
|
174
174
|
}>;
|
|
175
175
|
/**
|
|
176
176
|
* Wrap your column type to opt-out from dehydration by {@link ShallowDehydrateValue},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kysely",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.18",
|
|
4
4
|
"description": "Type safe SQL query builder",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -70,6 +70,39 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"sideEffects": false,
|
|
73
|
+
"scripts": {
|
|
74
|
+
"clean": "rm -rf dist & rm -rf test/node/dist & rm -rf test/browser/bundle.js & rm -rf helpers",
|
|
75
|
+
"bench:ts": "pnpm build && cd ./test/ts-benchmarks && node --experimental-strip-types ./index.ts",
|
|
76
|
+
"test": "pnpm build && pnpm test:node:build && pnpm test:node:run && pnpm test:typings && pnpm test:esmimports && pnpm test:exports",
|
|
77
|
+
"test:node:build": "tsc -p test/node",
|
|
78
|
+
"test:node": "pnpm build && pnpm test:node:build && pnpm test:node:run",
|
|
79
|
+
"test:node:run": "mocha --timeout 15000 test/node/dist/**/*.test.js",
|
|
80
|
+
"test:browser:build": "rm -rf test/browser/bundle.js && esbuild test/browser/main.ts --bundle --outfile=test/browser/bundle.js",
|
|
81
|
+
"test:browser": "pnpm build && pnpm test:browser:build && node test/browser/test.js",
|
|
82
|
+
"test:bun": "pnpm build && bun link && cd test/bun && bun install && bun run test",
|
|
83
|
+
"test:cloudflare-workers": "pnpm build && pnpm -r test --filter kysely-cloudflare-workers-test",
|
|
84
|
+
"test:deno": "deno run --allow-env --allow-read --allow-net --no-lock test/deno/test.ts",
|
|
85
|
+
"test:typings": "tsd test/typings",
|
|
86
|
+
"test:esmimports": "node scripts/check-esm-imports.cjs",
|
|
87
|
+
"test:esbuild": "esbuild --bundle --platform=node --external:pg-native dist/esm/index.js --outfile=/dev/null",
|
|
88
|
+
"test:exports": "attw --pack . && node scripts/check-exports.cjs",
|
|
89
|
+
"test:jsdocs": "deno check --doc-only --no-lock --unstable-sloppy-imports --config=\"deno.check.json\" ./src",
|
|
90
|
+
"test:outdatedts": "pnpm build && cd test/outdated-ts && pnpm i && pnpm test",
|
|
91
|
+
"lint:deno": "deno lint --config=\"deno.lint.json\" ./src",
|
|
92
|
+
"prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
|
|
93
|
+
"build": "pnpm clean && (pnpm build:esm & pnpm build:cjs) && pnpm script:module-fixup && pnpm script:copy-interface-doc",
|
|
94
|
+
"build:esm": "tsc -p tsconfig.json && pnpm script:add-deno-type-references",
|
|
95
|
+
"build:cjs": "tsc -p tsconfig-cjs.json",
|
|
96
|
+
"script:module-fixup": "node scripts/module-fixup.cjs",
|
|
97
|
+
"script:copy-interface-doc": "node scripts/copy-interface-documentation.cjs",
|
|
98
|
+
"script:add-deno-type-references": "node scripts/add-deno-type-references.cjs",
|
|
99
|
+
"script:align-versions": "node --experimental-strip-types scripts/align-versions.mts",
|
|
100
|
+
"script:generate-site-examples": "node scripts/generate-site-examples.cjs",
|
|
101
|
+
"script:exclude-test-files-for-backwards-compat": "node --experimental-strip-types scripts/exclude-test-files-for-backwards-compat.mts",
|
|
102
|
+
"script:remove-global-augmentations": "node --experimental-strip-types scripts/remove-global-augmentations.mts",
|
|
103
|
+
"prepublishOnly": "pnpm build && pnpm test:exports",
|
|
104
|
+
"version": "pnpm script:align-versions && git add ."
|
|
105
|
+
},
|
|
73
106
|
"author": "Sami Koskimäki <sami@jakso.me>",
|
|
74
107
|
"license": "MIT",
|
|
75
108
|
"contributors": [
|
|
@@ -110,36 +143,5 @@
|
|
|
110
143
|
"tsd": "0.33.0",
|
|
111
144
|
"typescript": "6.0.2"
|
|
112
145
|
},
|
|
113
|
-
"
|
|
114
|
-
|
|
115
|
-
"bench:ts": "pnpm build && cd ./test/ts-benchmarks && node --experimental-strip-types ./index.ts",
|
|
116
|
-
"test": "pnpm build && pnpm test:node:build && pnpm test:node:run && pnpm test:typings && pnpm test:esmimports && pnpm test:exports",
|
|
117
|
-
"test:node:build": "tsc -p test/node",
|
|
118
|
-
"test:node": "pnpm build && pnpm test:node:build && pnpm test:node:run",
|
|
119
|
-
"test:node:run": "mocha --timeout 15000 test/node/dist/**/*.test.js",
|
|
120
|
-
"test:browser:build": "rm -rf test/browser/bundle.js && esbuild test/browser/main.ts --bundle --outfile=test/browser/bundle.js",
|
|
121
|
-
"test:browser": "pnpm build && pnpm test:browser:build && node test/browser/test.js",
|
|
122
|
-
"test:bun": "pnpm build && bun link && cd test/bun && bun install && bun run test",
|
|
123
|
-
"test:cloudflare-workers": "pnpm build && pnpm -r test --filter kysely-cloudflare-workers-test",
|
|
124
|
-
"test:deno": "deno run --allow-env --allow-read --allow-net --no-lock test/deno/test.ts",
|
|
125
|
-
"test:typings": "tsd test/typings",
|
|
126
|
-
"test:esmimports": "node scripts/check-esm-imports.cjs",
|
|
127
|
-
"test:esbuild": "esbuild --bundle --platform=node --external:pg-native dist/esm/index.js --outfile=/dev/null",
|
|
128
|
-
"test:exports": "attw --pack . && node scripts/check-exports.cjs",
|
|
129
|
-
"test:jsdocs": "deno check --doc-only --no-lock --unstable-sloppy-imports --config=\"deno.check.json\" ./src",
|
|
130
|
-
"test:outdatedts": "pnpm build && cd test/outdated-ts && pnpm i && pnpm test",
|
|
131
|
-
"lint:deno": "deno lint --config=\"deno.lint.json\" ./src",
|
|
132
|
-
"prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
|
|
133
|
-
"build": "pnpm clean && (pnpm build:esm & pnpm build:cjs) && pnpm script:module-fixup && pnpm script:copy-interface-doc",
|
|
134
|
-
"build:esm": "tsc -p tsconfig.json && pnpm script:add-deno-type-references",
|
|
135
|
-
"build:cjs": "tsc -p tsconfig-cjs.json",
|
|
136
|
-
"script:module-fixup": "node scripts/module-fixup.cjs",
|
|
137
|
-
"script:copy-interface-doc": "node scripts/copy-interface-documentation.cjs",
|
|
138
|
-
"script:add-deno-type-references": "node scripts/add-deno-type-references.cjs",
|
|
139
|
-
"script:align-versions": "node --experimental-strip-types scripts/align-versions.mts",
|
|
140
|
-
"script:generate-site-examples": "node scripts/generate-site-examples.cjs",
|
|
141
|
-
"script:exclude-test-files-for-backwards-compat": "node --experimental-strip-types scripts/exclude-test-files-for-backwards-compat.mts",
|
|
142
|
-
"script:remove-global-augmentations": "node --experimental-strip-types scripts/remove-global-augmentations.mts",
|
|
143
|
-
"version": "pnpm script:align-versions && git add ."
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
+
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
|
|
147
|
+
}
|