pqb 0.2.4 → 0.2.6
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/dist/index.d.ts +59 -62
- package/dist/index.esm.js +3 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/adapter.test.ts +2 -2
- package/src/adapter.ts +2 -2
- package/src/db.ts +2 -2
- package/src/queryMethods/insert.ts +8 -9
- package/src/queryMethods/update.ts +74 -79
package/dist/index.d.ts
CHANGED
|
@@ -468,7 +468,7 @@ declare type OmitBelongsToForeignKeys<R extends RelationsBase, Data> = Omit<Data
|
|
|
468
468
|
[K in keyof R]: R[K] extends BelongsToRelation ? R[K]['options']['foreignKey'] : never;
|
|
469
469
|
}[keyof R]>;
|
|
470
470
|
declare type InsertRelationData<T extends Query> = {
|
|
471
|
-
[
|
|
471
|
+
[K in keyof T['relations']]: T['relations'][K] extends BelongsToRelation ? InsertBelongsToData<T, K, T['relations'][K]> : T['relations'][K] extends HasOneRelation ? InsertHasOneData<T, K, T['relations'][K]> : T['relations'][K] extends HasManyRelation | HasAndBelongsToManyRelation ? InsertHasManyData<T, K, T['relations'][K]> : EmptyObject;
|
|
472
472
|
}[keyof T['relations']];
|
|
473
473
|
declare type InsertBelongsToData<T extends Query, Key extends keyof T['relations'], Rel extends BelongsToRelation> = SetOptional<{
|
|
474
474
|
[K in Rel['options']['foreignKey']]: Rel['options']['foreignKey'] extends keyof T['inputType'] ? T['inputType'][Rel['options']['foreignKey']] : never;
|
|
@@ -690,7 +690,7 @@ declare class Adapter {
|
|
|
690
690
|
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
691
691
|
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
692
692
|
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
693
|
-
|
|
693
|
+
close(): Promise<void>;
|
|
694
694
|
}
|
|
695
695
|
declare class TransactionAdapter implements Adapter {
|
|
696
696
|
pool: Pool;
|
|
@@ -700,7 +700,7 @@ declare class TransactionAdapter implements Adapter {
|
|
|
700
700
|
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
701
701
|
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
702
702
|
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
703
|
-
|
|
703
|
+
close(): Promise<void>;
|
|
704
704
|
}
|
|
705
705
|
|
|
706
706
|
declare type ThenResult<Res> = (resolve?: (value: Res) => any, reject?: (error: any) => any) => Promise<Res | never>;
|
|
@@ -739,64 +739,61 @@ declare class Union {
|
|
|
739
739
|
declare type UpdateData<T extends Query> = {
|
|
740
740
|
[K in keyof T['type']]?: T['type'][K] | RawExpression;
|
|
741
741
|
} & (T['relations'] extends Record<string, Relation> ? {
|
|
742
|
-
[K in keyof T['relations']]?: T['relations'][K]['
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
create: InsertData<
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
create: InsertData<T['relations'][K]['nestedCreateQuery']>[];
|
|
798
|
-
} : never;
|
|
799
|
-
} : {});
|
|
742
|
+
[K in keyof T['relations']]?: T['relations'][K] extends BelongsToRelation ? UpdateBelongsToData<T, T['relations'][K]> : T['relations'][K] extends HasOneRelation ? UpdateHasOneData<T, T['relations'][K]> : T['relations'][K] extends HasManyRelation ? UpdateHasManyData<T, T['relations'][K]> : T['relations'][K] extends HasAndBelongsToManyRelation ? UpdateHasAndBelongsToManyData<T['relations'][K]> : never;
|
|
743
|
+
} : EmptyObject);
|
|
744
|
+
declare type UpdateBelongsToData<T extends Query, Rel extends BelongsToRelation> = {
|
|
745
|
+
disconnect: boolean;
|
|
746
|
+
} | {
|
|
747
|
+
set: WhereArg<Rel['model']>;
|
|
748
|
+
} | {
|
|
749
|
+
delete: boolean;
|
|
750
|
+
} | {
|
|
751
|
+
update: UpdateData<Rel['model']>;
|
|
752
|
+
} | {
|
|
753
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
754
|
+
} | (T['returnType'] extends 'one' | 'oneOrThrow' ? {
|
|
755
|
+
upsert: {
|
|
756
|
+
update: UpdateData<Rel['model']>;
|
|
757
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
758
|
+
};
|
|
759
|
+
} : never);
|
|
760
|
+
declare type UpdateHasOneData<T extends Query, Rel extends HasOneRelation> = {
|
|
761
|
+
disconnect: boolean;
|
|
762
|
+
} | {
|
|
763
|
+
delete: boolean;
|
|
764
|
+
} | {
|
|
765
|
+
update: UpdateData<Rel['model']>;
|
|
766
|
+
} | (T['returnType'] extends 'one' | 'oneOrThrow' ? {
|
|
767
|
+
set: WhereArg<Rel['model']>;
|
|
768
|
+
} | {
|
|
769
|
+
upsert: {
|
|
770
|
+
update: UpdateData<Rel['model']>;
|
|
771
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
772
|
+
};
|
|
773
|
+
} | {
|
|
774
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
775
|
+
} : never);
|
|
776
|
+
declare type UpdateHasManyData<T extends Query, Rel extends HasManyRelation> = {
|
|
777
|
+
disconnect?: MaybeArray<WhereArg<Rel['model']>>;
|
|
778
|
+
delete?: MaybeArray<WhereArg<Rel['model']>>;
|
|
779
|
+
update?: {
|
|
780
|
+
where: MaybeArray<WhereArg<Rel['model']>>;
|
|
781
|
+
data: UpdateData<Rel['model']>;
|
|
782
|
+
};
|
|
783
|
+
} & (T['returnType'] extends 'one' | 'oneOrThrow' ? {
|
|
784
|
+
set?: MaybeArray<WhereArg<Rel['model']>>;
|
|
785
|
+
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
786
|
+
} : EmptyObject);
|
|
787
|
+
declare type UpdateHasAndBelongsToManyData<Rel extends HasAndBelongsToManyRelation> = {
|
|
788
|
+
disconnect?: MaybeArray<WhereArg<Rel['model']>>;
|
|
789
|
+
set?: MaybeArray<WhereArg<Rel['model']>>;
|
|
790
|
+
delete?: MaybeArray<WhereArg<Rel['model']>>;
|
|
791
|
+
update?: {
|
|
792
|
+
where: MaybeArray<WhereArg<Rel['model']>>;
|
|
793
|
+
data: UpdateData<Rel['model']>;
|
|
794
|
+
};
|
|
795
|
+
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
796
|
+
};
|
|
800
797
|
declare type UpdateArgs<T extends Query, ForceAll extends boolean> = (T['hasWhere'] extends true ? true : ForceAll) extends true ? [update: RawExpression | UpdateData<T>, forceAll?: ForceAll] : [update: RawExpression | UpdateData<T>, forceAll: true];
|
|
801
798
|
declare type UpdateResult<T extends Query> = T['hasSelect'] extends false ? SetQueryReturnsRowCount<T> : T;
|
|
802
799
|
declare type ChangeCountArg<T extends Query> = keyof T['shape'] | Partial<Record<keyof T['shape'], number>>;
|
|
@@ -878,7 +875,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
878
875
|
declare type DbResult<CT extends ColumnTypesBase> = Db & {
|
|
879
876
|
<Table extends string, Shape extends ColumnsShape = ColumnsShape>(table: Table, shape?: ((t: CT) => Shape) | Shape, options?: DbTableOptions): Db<Table, Shape>;
|
|
880
877
|
adapter: Adapter;
|
|
881
|
-
|
|
878
|
+
close: Adapter['close'];
|
|
882
879
|
};
|
|
883
880
|
declare type DbOptions<CT extends ColumnTypesBase = ColumnTypes> = ({
|
|
884
881
|
adapter: Adapter;
|
package/dist/index.esm.js
CHANGED
|
@@ -3013,7 +3013,7 @@ class Adapter {
|
|
|
3013
3013
|
client.release();
|
|
3014
3014
|
}
|
|
3015
3015
|
}
|
|
3016
|
-
|
|
3016
|
+
close() {
|
|
3017
3017
|
return this.pool.end();
|
|
3018
3018
|
}
|
|
3019
3019
|
}
|
|
@@ -3055,7 +3055,7 @@ class TransactionAdapter {
|
|
|
3055
3055
|
async transaction(cb) {
|
|
3056
3056
|
return await cb(this);
|
|
3057
3057
|
}
|
|
3058
|
-
|
|
3058
|
+
close() {
|
|
3059
3059
|
return this.pool.end();
|
|
3060
3060
|
}
|
|
3061
3061
|
}
|
|
@@ -5455,7 +5455,7 @@ const createDb = (_a) => {
|
|
|
5455
5455
|
);
|
|
5456
5456
|
},
|
|
5457
5457
|
qb,
|
|
5458
|
-
{ adapter,
|
|
5458
|
+
{ adapter, close: () => adapter.close() }
|
|
5459
5459
|
);
|
|
5460
5460
|
Object.getOwnPropertyNames(Db.prototype).forEach((name) => {
|
|
5461
5461
|
db[name] = Db.prototype[name];
|