pqb 0.2.5 → 0.2.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/dist/index.d.ts +56 -59
- 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/queryMethods/insert.ts +8 -9
- package/src/queryMethods/update.test.ts +25 -0
- package/src/queryMethods/update.ts +74 -79
- package/src/sql/update.ts +3 -5
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;
|
|
@@ -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>>;
|
package/dist/index.esm.js
CHANGED
|
@@ -2756,20 +2756,20 @@ const pushUpdateSql = (ctx, model, query, quotedAs) => {
|
|
|
2756
2756
|
ctx.sql.push(`AS ${quotedAs}`);
|
|
2757
2757
|
}
|
|
2758
2758
|
ctx.sql.push("SET");
|
|
2759
|
+
const set = [];
|
|
2759
2760
|
query.data.forEach((item) => {
|
|
2760
2761
|
if (isRaw(item)) {
|
|
2761
|
-
|
|
2762
|
+
set.push(getRaw(item, ctx.values));
|
|
2762
2763
|
} else {
|
|
2763
|
-
const set = [];
|
|
2764
2764
|
for (const key in item) {
|
|
2765
2765
|
const value = item[key];
|
|
2766
2766
|
if (value !== void 0) {
|
|
2767
2767
|
set.push(`${q(key)} = ${processValue(ctx.values, key, value)}`);
|
|
2768
2768
|
}
|
|
2769
2769
|
}
|
|
2770
|
-
ctx.sql.push(set.join(", "));
|
|
2771
2770
|
}
|
|
2772
2771
|
});
|
|
2772
|
+
ctx.sql.push(set.join(", "));
|
|
2773
2773
|
pushWhereStatementSql(ctx, model, query, quotedAs);
|
|
2774
2774
|
pushReturningSql(ctx, model, query, quotedAs);
|
|
2775
2775
|
};
|