pqb 0.5.1 → 0.5.2
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.esm.js +7 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/queryMethods/create.ts +13 -4
- package/src/queryMethods/update.ts +19 -0
package/package.json
CHANGED
|
@@ -219,14 +219,23 @@ const processCreateItem = (
|
|
|
219
219
|
item[key] as Record<string, unknown>,
|
|
220
220
|
]);
|
|
221
221
|
} else {
|
|
222
|
+
const value = item[key] as NestedInsertItem;
|
|
223
|
+
if (
|
|
224
|
+
(!value.create ||
|
|
225
|
+
(Array.isArray(value.create) && value.create.length === 0)) &&
|
|
226
|
+
(!value.connect ||
|
|
227
|
+
(Array.isArray(value.connect) && value.connect.length === 0)) &&
|
|
228
|
+
(!value.connectOrCreate ||
|
|
229
|
+
(Array.isArray(value.connectOrCreate) &&
|
|
230
|
+
value.connectOrCreate.length === 0))
|
|
231
|
+
)
|
|
232
|
+
return;
|
|
233
|
+
|
|
222
234
|
ctx.requiredReturning[ctx.relations[key].primaryKey] = true;
|
|
223
235
|
|
|
224
236
|
if (!ctx.appendRelations[key]) ctx.appendRelations[key] = [];
|
|
225
237
|
|
|
226
|
-
ctx.appendRelations[key].push([
|
|
227
|
-
rowIndex,
|
|
228
|
-
item[key] as NestedInsertItem,
|
|
229
|
-
]);
|
|
238
|
+
ctx.appendRelations[key].push([rowIndex, value]);
|
|
230
239
|
}
|
|
231
240
|
} else if (
|
|
232
241
|
columnsMap[key] === undefined &&
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
HasManyRelation,
|
|
9
9
|
HasOneNestedUpdate,
|
|
10
10
|
HasOneRelation,
|
|
11
|
+
NestedUpdateItem,
|
|
11
12
|
NestedUpdateOneItem,
|
|
12
13
|
Relation,
|
|
13
14
|
} from '../relations';
|
|
@@ -192,6 +193,24 @@ export class Update {
|
|
|
192
193
|
if (relations[key].type === 'belongsTo') {
|
|
193
194
|
prependRelations[key] = data[key] as Record<string, unknown>;
|
|
194
195
|
} else {
|
|
196
|
+
const value = data[key] as NestedUpdateItem;
|
|
197
|
+
|
|
198
|
+
if (
|
|
199
|
+
!value.set &&
|
|
200
|
+
!('upsert' in value) &&
|
|
201
|
+
(!value.disconnect ||
|
|
202
|
+
(Array.isArray(value.disconnect) &&
|
|
203
|
+
value.disconnect.length === 0)) &&
|
|
204
|
+
(!value.delete ||
|
|
205
|
+
(Array.isArray(value.delete) && value.delete.length === 0)) &&
|
|
206
|
+
(!value.update ||
|
|
207
|
+
(Array.isArray(value.update.where) &&
|
|
208
|
+
value.update.where.length === 0)) &&
|
|
209
|
+
(!value.create ||
|
|
210
|
+
(Array.isArray(value.create) && value.create.length === 0))
|
|
211
|
+
)
|
|
212
|
+
continue;
|
|
213
|
+
|
|
195
214
|
if (!query.select?.includes('*')) {
|
|
196
215
|
const primaryKey = relations[key].primaryKey;
|
|
197
216
|
if (!query.select?.includes(primaryKey)) {
|