orchid-orm 1.9.6 → 1.9.8
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.js +7 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -239,7 +239,7 @@ const nestedInsert$3 = ({ query, primaryKey }) => {
|
|
|
239
239
|
};
|
|
240
240
|
const nestedUpdate$3 = ({ query, primaryKey, foreignKey }) => {
|
|
241
241
|
return (q, update, params, state) => {
|
|
242
|
-
var _a, _b;
|
|
242
|
+
var _a, _b, _c;
|
|
243
243
|
if (params.upsert && pqb.isQueryReturnsAll(q)) {
|
|
244
244
|
throw new Error("`upsert` option is not allowed in a batch update");
|
|
245
245
|
}
|
|
@@ -269,25 +269,16 @@ const nestedUpdate$3 = ({ query, primaryKey, foreignKey }) => {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
if (upsert) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
const { handleResult } = q.query;
|
|
277
|
-
q.query.handleResult = async (q2, queryResult) => {
|
|
278
|
-
const data = await handleResult(q2, queryResult);
|
|
279
|
-
const id = data[0][foreignKey];
|
|
272
|
+
((_c = state.queries) != null ? _c : state.queries = []).push(async (queryResult) => {
|
|
273
|
+
var _a2;
|
|
274
|
+
const id = queryResult.rows[0][foreignKey];
|
|
280
275
|
if (id !== null) {
|
|
281
276
|
await query.findBy({ [primaryKey]: id })._update(upsert.update);
|
|
282
277
|
} else {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
state.updateLater[foreignKey] = result[primaryKey];
|
|
286
|
-
})
|
|
287
|
-
);
|
|
278
|
+
const result = await query.select(primaryKey)._create(upsert.create);
|
|
279
|
+
((_a2 = state.updateData) != null ? _a2 : state.updateData = {})[foreignKey] = result[primaryKey];
|
|
288
280
|
}
|
|
289
|
-
|
|
290
|
-
};
|
|
281
|
+
});
|
|
291
282
|
} else if (params.delete || params.update) {
|
|
292
283
|
q._afterQuery(async (_, data) => {
|
|
293
284
|
const id = params.delete ? idForDelete : Array.isArray(data) ? data.length === 0 ? null : {
|