pqb 0.4.2 → 0.4.4
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 +5 -5
- package/dist/index.esm.js +13 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/queryMethods/create.ts +14 -0
- package/src/relations.ts +5 -4
package/dist/index.js
CHANGED
|
@@ -4260,6 +4260,7 @@ const insert = (self, {
|
|
|
4260
4260
|
columns,
|
|
4261
4261
|
values
|
|
4262
4262
|
}, returnType, ctx) => {
|
|
4263
|
+
var _a;
|
|
4263
4264
|
const q = self;
|
|
4264
4265
|
const returning = q.query.select;
|
|
4265
4266
|
delete q.query.and;
|
|
@@ -4292,6 +4293,15 @@ const insert = (self, {
|
|
|
4292
4293
|
})
|
|
4293
4294
|
);
|
|
4294
4295
|
}
|
|
4296
|
+
if (returnType === "oneOrThrow" || ((_a = q.query.fromQuery) == null ? void 0 : _a.query.returnType) === "oneOrThrow") {
|
|
4297
|
+
const { handleResult } = q.query;
|
|
4298
|
+
q.query.handleResult = async (q2, r) => {
|
|
4299
|
+
if (r.rowCount === 0) {
|
|
4300
|
+
throw new NotFoundError();
|
|
4301
|
+
}
|
|
4302
|
+
return await handleResult(q2, r);
|
|
4303
|
+
};
|
|
4304
|
+
}
|
|
4295
4305
|
const appendRelationsKeys = Object.keys(ctx.appendRelations);
|
|
4296
4306
|
if (appendRelationsKeys.length) {
|
|
4297
4307
|
if (!(returning == null ? void 0 : returning.includes("*"))) {
|
|
@@ -4322,10 +4332,10 @@ const insert = (self, {
|
|
|
4322
4332
|
"afterQuery",
|
|
4323
4333
|
appendRelationsKeys.map((relationName) => {
|
|
4324
4334
|
return (q2, result) => {
|
|
4325
|
-
var
|
|
4335
|
+
var _a2, _b;
|
|
4326
4336
|
const all = resultOfTypeAll || result;
|
|
4327
|
-
return (_b = (
|
|
4328
|
-
|
|
4337
|
+
return (_b = (_a2 = ctx.relations[relationName]).nestedInsert) == null ? void 0 : _b.call(
|
|
4338
|
+
_a2,
|
|
4329
4339
|
q2,
|
|
4330
4340
|
ctx.appendRelations[relationName].map(([rowIndex, data]) => [
|
|
4331
4341
|
all[rowIndex],
|