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.d.ts
CHANGED
|
@@ -142,16 +142,16 @@ declare type RelationQueryBase = Query & {
|
|
|
142
142
|
[relationQueryKey]: string;
|
|
143
143
|
[isRequiredRelationKey]: boolean;
|
|
144
144
|
};
|
|
145
|
-
declare type PrepareRelationQuery<T extends Query, RelationName extends PropertyKey, Required extends boolean> = Omit<T, 'tableAlias'> & {
|
|
145
|
+
declare type PrepareRelationQuery<T extends Query, RelationName extends PropertyKey, Required extends boolean, Populate extends string> = Omit<T, 'tableAlias'> & {
|
|
146
146
|
tableAlias: RelationName extends string ? RelationName : never;
|
|
147
147
|
[isRequiredRelationKey]: Required;
|
|
148
148
|
[relationQueryKey]: string;
|
|
149
|
+
} & {
|
|
150
|
+
[defaultsKey]: Record<Populate, true>;
|
|
149
151
|
};
|
|
150
|
-
declare type RelationQuery<Name extends PropertyKey = string, Params extends Record<string, unknown> = never, Populate extends string = never, T extends Query = Query, Required extends boolean = boolean, ChainedCreate extends boolean = false, Q extends RelationQueryBase = ChainedCreate extends true ? PrepareRelationQuery<T, Name, Required> : PrepareRelationQuery<T, Name, Required> & {
|
|
152
|
+
declare type RelationQuery<Name extends PropertyKey = string, Params extends Record<string, unknown> = never, Populate extends string = never, T extends Query = Query, Required extends boolean = boolean, ChainedCreate extends boolean = false, Q extends RelationQueryBase = ChainedCreate extends true ? PrepareRelationQuery<T, Name, Required, Populate> : PrepareRelationQuery<T, Name, Required, Populate> & {
|
|
151
153
|
[K in CreateMethodsNames]: never;
|
|
152
|
-
}> = ((params: Params) => Q &
|
|
153
|
-
[defaultsKey]: Record<Populate, true>;
|
|
154
|
-
}) & Q;
|
|
154
|
+
}> = ((params: Params) => Q) & Q;
|
|
155
155
|
|
|
156
156
|
interface QueryResultRow {
|
|
157
157
|
[column: string]: any;
|
package/dist/index.esm.js
CHANGED
|
@@ -4256,6 +4256,7 @@ const insert = (self, {
|
|
|
4256
4256
|
columns,
|
|
4257
4257
|
values
|
|
4258
4258
|
}, returnType, ctx) => {
|
|
4259
|
+
var _a;
|
|
4259
4260
|
const q = self;
|
|
4260
4261
|
const returning = q.query.select;
|
|
4261
4262
|
delete q.query.and;
|
|
@@ -4288,6 +4289,15 @@ const insert = (self, {
|
|
|
4288
4289
|
})
|
|
4289
4290
|
);
|
|
4290
4291
|
}
|
|
4292
|
+
if (returnType === "oneOrThrow" || ((_a = q.query.fromQuery) == null ? void 0 : _a.query.returnType) === "oneOrThrow") {
|
|
4293
|
+
const { handleResult } = q.query;
|
|
4294
|
+
q.query.handleResult = async (q2, r) => {
|
|
4295
|
+
if (r.rowCount === 0) {
|
|
4296
|
+
throw new NotFoundError();
|
|
4297
|
+
}
|
|
4298
|
+
return await handleResult(q2, r);
|
|
4299
|
+
};
|
|
4300
|
+
}
|
|
4291
4301
|
const appendRelationsKeys = Object.keys(ctx.appendRelations);
|
|
4292
4302
|
if (appendRelationsKeys.length) {
|
|
4293
4303
|
if (!(returning == null ? void 0 : returning.includes("*"))) {
|
|
@@ -4318,10 +4328,10 @@ const insert = (self, {
|
|
|
4318
4328
|
"afterQuery",
|
|
4319
4329
|
appendRelationsKeys.map((relationName) => {
|
|
4320
4330
|
return (q2, result) => {
|
|
4321
|
-
var
|
|
4331
|
+
var _a2, _b;
|
|
4322
4332
|
const all = resultOfTypeAll || result;
|
|
4323
|
-
return (_b = (
|
|
4324
|
-
|
|
4333
|
+
return (_b = (_a2 = ctx.relations[relationName]).nestedInsert) == null ? void 0 : _b.call(
|
|
4334
|
+
_a2,
|
|
4325
4335
|
q2,
|
|
4326
4336
|
ctx.appendRelations[relationName].map(([rowIndex, data]) => [
|
|
4327
4337
|
all[rowIndex],
|