orchid-orm 1.9.5 → 1.9.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.mjs CHANGED
@@ -220,7 +220,7 @@ const nestedInsert$3 = ({ query, primaryKey }) => {
220
220
  };
221
221
  const nestedUpdate$3 = ({ query, primaryKey, foreignKey }) => {
222
222
  return (q, update, params, state) => {
223
- var _a, _b;
223
+ var _a, _b, _c;
224
224
  if (params.upsert && isQueryReturnsAll(q)) {
225
225
  throw new Error("`upsert` option is not allowed in a batch update");
226
226
  }
@@ -250,25 +250,16 @@ const nestedUpdate$3 = ({ query, primaryKey, foreignKey }) => {
250
250
  }
251
251
  }
252
252
  if (upsert) {
253
- if (!state.updateLater) {
254
- state.updateLater = {};
255
- state.updateLaterPromises = [];
256
- }
257
- const { handleResult } = q.query;
258
- q.query.handleResult = async (q2, queryResult) => {
259
- const data = await handleResult(q2, queryResult);
260
- const id = data[0][foreignKey];
253
+ ((_c = state.queries) != null ? _c : state.queries = []).push(async (queryResult) => {
254
+ var _a2;
255
+ const id = queryResult.rows[0][foreignKey];
261
256
  if (id !== null) {
262
257
  await query.findBy({ [primaryKey]: id })._update(upsert.update);
263
258
  } else {
264
- state.updateLaterPromises.push(
265
- query.select(primaryKey)._create(upsert.create).then((result) => {
266
- state.updateLater[foreignKey] = result[primaryKey];
267
- })
268
- );
259
+ const result = await query.select(primaryKey)._create(upsert.create);
260
+ ((_a2 = state.updateData) != null ? _a2 : state.updateData = {})[foreignKey] = result[primaryKey];
269
261
  }
270
- return data;
271
- };
262
+ });
272
263
  } else if (params.delete || params.update) {
273
264
  q._afterQuery(async (_, data) => {
274
265
  const id = params.delete ? idForDelete : Array.isArray(data) ? data.length === 0 ? null : {