pqb 0.2.5 → 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 +56 -59
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/queryMethods/insert.ts +8 -9
- package/src/queryMethods/update.ts +74 -79
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
Relation,
|
|
21
21
|
RelationsBase,
|
|
22
22
|
} from '../relations';
|
|
23
|
-
import { SetOptional } from '../utils';
|
|
23
|
+
import { EmptyObject, SetOptional } from '../utils';
|
|
24
24
|
import { InsertQueryData, OnConflictItem, OnConflictMergeUpdate } from '../sql';
|
|
25
25
|
import { WhereArg } from './where';
|
|
26
26
|
import { parseResult, queryMethodByReturnType } from './then';
|
|
@@ -43,14 +43,13 @@ type OmitBelongsToForeignKeys<R extends RelationsBase, Data> = Omit<
|
|
|
43
43
|
>;
|
|
44
44
|
|
|
45
45
|
type InsertRelationData<T extends Query> = {
|
|
46
|
-
[
|
|
47
|
-
? InsertBelongsToData<T,
|
|
48
|
-
: T['relations'][
|
|
49
|
-
? InsertHasOneData<T,
|
|
50
|
-
: T['relations'][
|
|
51
|
-
? InsertHasManyData<T,
|
|
52
|
-
:
|
|
53
|
-
{};
|
|
46
|
+
[K in keyof T['relations']]: T['relations'][K] extends BelongsToRelation
|
|
47
|
+
? InsertBelongsToData<T, K, T['relations'][K]>
|
|
48
|
+
: T['relations'][K] extends HasOneRelation
|
|
49
|
+
? InsertHasOneData<T, K, T['relations'][K]>
|
|
50
|
+
: T['relations'][K] extends HasManyRelation | HasAndBelongsToManyRelation
|
|
51
|
+
? InsertHasManyData<T, K, T['relations'][K]>
|
|
52
|
+
: EmptyObject;
|
|
54
53
|
}[keyof T['relations']];
|
|
55
54
|
|
|
56
55
|
type InsertBelongsToData<
|
|
@@ -3,12 +3,16 @@ import { pushQueryArray, pushQueryValue } from '../queryDataUtils';
|
|
|
3
3
|
import { isRaw, RawExpression, StringKey } from '../common';
|
|
4
4
|
import {
|
|
5
5
|
BelongsToNestedUpdate,
|
|
6
|
+
BelongsToRelation,
|
|
7
|
+
HasAndBelongsToManyRelation,
|
|
8
|
+
HasManyRelation,
|
|
6
9
|
HasOneNestedUpdate,
|
|
10
|
+
HasOneRelation,
|
|
7
11
|
NestedUpdateOneItem,
|
|
8
12
|
Relation,
|
|
9
13
|
} from '../relations';
|
|
10
14
|
import { WhereArg, WhereResult } from './where';
|
|
11
|
-
import { MaybeArray } from '../utils';
|
|
15
|
+
import { EmptyObject, MaybeArray } from '../utils';
|
|
12
16
|
import { InsertData } from './insert';
|
|
13
17
|
import { parseResult, queryMethodByReturnType } from './then';
|
|
14
18
|
|
|
@@ -16,86 +20,77 @@ export type UpdateData<T extends Query> = {
|
|
|
16
20
|
[K in keyof T['type']]?: T['type'][K] | RawExpression;
|
|
17
21
|
} & (T['relations'] extends Record<string, Relation>
|
|
18
22
|
? {
|
|
19
|
-
[K in keyof T['relations']]?: T['relations'][K]
|
|
20
|
-
?
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
| (T['returnType'] extends 'one' | 'oneOrThrow'
|
|
29
|
-
? {
|
|
30
|
-
upsert: {
|
|
31
|
-
update: UpdateData<T['relations'][K]['model']>;
|
|
32
|
-
create: InsertData<
|
|
33
|
-
T['relations'][K]['nestedCreateQuery']
|
|
34
|
-
>;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
: never)
|
|
38
|
-
: T['relations'][K]['type'] extends 'hasOne'
|
|
39
|
-
?
|
|
40
|
-
| { disconnect: boolean }
|
|
41
|
-
| { delete: boolean }
|
|
42
|
-
| { update: UpdateData<T['relations'][K]['model']> }
|
|
43
|
-
| (T['returnType'] extends 'one' | 'oneOrThrow'
|
|
44
|
-
?
|
|
45
|
-
| { set: WhereArg<T['relations'][K]['model']> }
|
|
46
|
-
| {
|
|
47
|
-
upsert: {
|
|
48
|
-
update: UpdateData<T['relations'][K]['model']>;
|
|
49
|
-
create: InsertData<
|
|
50
|
-
T['relations'][K]['nestedCreateQuery']
|
|
51
|
-
>;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
| {
|
|
55
|
-
create: InsertData<
|
|
56
|
-
T['relations'][K]['nestedCreateQuery']
|
|
57
|
-
>;
|
|
58
|
-
}
|
|
59
|
-
: never)
|
|
60
|
-
: T['relations'][K]['type'] extends 'hasMany'
|
|
61
|
-
?
|
|
62
|
-
| { disconnect: MaybeArray<WhereArg<T['relations'][K]['model']>> }
|
|
63
|
-
| { delete: MaybeArray<WhereArg<T['relations'][K]['model']>> }
|
|
64
|
-
| {
|
|
65
|
-
update: {
|
|
66
|
-
where: MaybeArray<WhereArg<T['relations'][K]['model']>>;
|
|
67
|
-
data: UpdateData<T['relations'][K]['model']>;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
| (T['returnType'] extends 'one' | 'oneOrThrow'
|
|
71
|
-
?
|
|
72
|
-
| { set: MaybeArray<WhereArg<T['relations'][K]['model']>> }
|
|
73
|
-
| {
|
|
74
|
-
create: InsertData<
|
|
75
|
-
T['relations'][K]['nestedCreateQuery']
|
|
76
|
-
>[];
|
|
77
|
-
}
|
|
78
|
-
: never)
|
|
79
|
-
: T['relations'][K]['type'] extends 'hasAndBelongsToMany'
|
|
80
|
-
?
|
|
81
|
-
| { disconnect: MaybeArray<WhereArg<T['relations'][K]['model']>> }
|
|
82
|
-
| {
|
|
83
|
-
set: MaybeArray<WhereArg<T['relations'][K]['model']>>;
|
|
84
|
-
}
|
|
85
|
-
| { delete: MaybeArray<WhereArg<T['relations'][K]['model']>> }
|
|
86
|
-
| {
|
|
87
|
-
update: {
|
|
88
|
-
where: MaybeArray<WhereArg<T['relations'][K]['model']>>;
|
|
89
|
-
data: UpdateData<T['relations'][K]['model']>;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
| {
|
|
93
|
-
create: InsertData<T['relations'][K]['nestedCreateQuery']>[];
|
|
94
|
-
}
|
|
23
|
+
[K in keyof T['relations']]?: T['relations'][K] extends BelongsToRelation
|
|
24
|
+
? UpdateBelongsToData<T, T['relations'][K]>
|
|
25
|
+
: T['relations'][K] extends HasOneRelation
|
|
26
|
+
? UpdateHasOneData<T, T['relations'][K]>
|
|
27
|
+
: T['relations'][K] extends HasManyRelation
|
|
28
|
+
? UpdateHasManyData<T, T['relations'][K]>
|
|
29
|
+
: T['relations'][K] extends HasAndBelongsToManyRelation
|
|
30
|
+
? UpdateHasAndBelongsToManyData<T['relations'][K]>
|
|
95
31
|
: never;
|
|
96
32
|
}
|
|
97
|
-
:
|
|
98
|
-
|
|
33
|
+
: EmptyObject);
|
|
34
|
+
|
|
35
|
+
type UpdateBelongsToData<T extends Query, Rel extends BelongsToRelation> =
|
|
36
|
+
| { disconnect: boolean }
|
|
37
|
+
| { set: WhereArg<Rel['model']> }
|
|
38
|
+
| { delete: boolean }
|
|
39
|
+
| { update: UpdateData<Rel['model']> }
|
|
40
|
+
| {
|
|
41
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
42
|
+
}
|
|
43
|
+
| (T['returnType'] extends 'one' | 'oneOrThrow'
|
|
44
|
+
? {
|
|
45
|
+
upsert: {
|
|
46
|
+
update: UpdateData<Rel['model']>;
|
|
47
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
: never);
|
|
51
|
+
|
|
52
|
+
type UpdateHasOneData<T extends Query, Rel extends HasOneRelation> =
|
|
53
|
+
| { disconnect: boolean }
|
|
54
|
+
| { delete: boolean }
|
|
55
|
+
| { update: UpdateData<Rel['model']> }
|
|
56
|
+
| (T['returnType'] extends 'one' | 'oneOrThrow'
|
|
57
|
+
?
|
|
58
|
+
| { set: WhereArg<Rel['model']> }
|
|
59
|
+
| {
|
|
60
|
+
upsert: {
|
|
61
|
+
update: UpdateData<Rel['model']>;
|
|
62
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
| {
|
|
66
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
67
|
+
}
|
|
68
|
+
: never);
|
|
69
|
+
|
|
70
|
+
type UpdateHasManyData<T extends Query, Rel extends HasManyRelation> = {
|
|
71
|
+
disconnect?: MaybeArray<WhereArg<Rel['model']>>;
|
|
72
|
+
delete?: MaybeArray<WhereArg<Rel['model']>>;
|
|
73
|
+
update?: {
|
|
74
|
+
where: MaybeArray<WhereArg<Rel['model']>>;
|
|
75
|
+
data: UpdateData<Rel['model']>;
|
|
76
|
+
};
|
|
77
|
+
} & (T['returnType'] extends 'one' | 'oneOrThrow'
|
|
78
|
+
? {
|
|
79
|
+
set?: MaybeArray<WhereArg<Rel['model']>>;
|
|
80
|
+
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
81
|
+
}
|
|
82
|
+
: EmptyObject);
|
|
83
|
+
|
|
84
|
+
type UpdateHasAndBelongsToManyData<Rel extends HasAndBelongsToManyRelation> = {
|
|
85
|
+
disconnect?: MaybeArray<WhereArg<Rel['model']>>;
|
|
86
|
+
set?: MaybeArray<WhereArg<Rel['model']>>;
|
|
87
|
+
delete?: MaybeArray<WhereArg<Rel['model']>>;
|
|
88
|
+
update?: {
|
|
89
|
+
where: MaybeArray<WhereArg<Rel['model']>>;
|
|
90
|
+
data: UpdateData<Rel['model']>;
|
|
91
|
+
};
|
|
92
|
+
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
93
|
+
};
|
|
99
94
|
|
|
100
95
|
type UpdateArgs<T extends Query, ForceAll extends boolean> = (
|
|
101
96
|
T['hasWhere'] extends true ? true : ForceAll
|