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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pqb",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Postgres query builder",
5
5
  "homepage": "https://porm.netlify.app/guide/query-builder.html",
6
6
  "repository": {
@@ -25,6 +25,7 @@ import { EmptyObject, SetOptional } from '../utils';
25
25
  import { InsertQueryData, OnConflictItem, OnConflictMergeUpdate } from '../sql';
26
26
  import { WhereArg } from './where';
27
27
  import { parseResult, queryMethodByReturnType } from './then';
28
+ import { NotFoundError } from '../errors';
28
29
 
29
30
  export type CreateData<
30
31
  T extends Query,
@@ -351,6 +352,19 @@ const insert = (
351
352
  );
352
353
  }
353
354
 
355
+ if (
356
+ returnType === 'oneOrThrow' ||
357
+ q.query.fromQuery?.query.returnType === 'oneOrThrow'
358
+ ) {
359
+ const { handleResult } = q.query;
360
+ q.query.handleResult = async (q, r) => {
361
+ if (r.rowCount === 0) {
362
+ throw new NotFoundError();
363
+ }
364
+ return await handleResult(q, r);
365
+ };
366
+ }
367
+
354
368
  const appendRelationsKeys = Object.keys(ctx.appendRelations);
355
369
  if (appendRelationsKeys.length) {
356
370
  if (!returning?.includes('*')) {
package/src/relations.ts CHANGED
@@ -188,11 +188,12 @@ type PrepareRelationQuery<
188
188
  T extends Query,
189
189
  RelationName extends PropertyKey,
190
190
  Required extends boolean,
191
+ Populate extends string,
191
192
  > = Omit<T, 'tableAlias'> & {
192
193
  tableAlias: RelationName extends string ? RelationName : never;
193
194
  [isRequiredRelationKey]: Required;
194
195
  [relationQueryKey]: string;
195
- };
196
+ } & { [defaultsKey]: Record<Populate, true> };
196
197
 
197
198
  export type RelationQuery<
198
199
  Name extends PropertyKey = string,
@@ -202,8 +203,8 @@ export type RelationQuery<
202
203
  Required extends boolean = boolean,
203
204
  ChainedCreate extends boolean = false,
204
205
  Q extends RelationQueryBase = ChainedCreate extends true
205
- ? PrepareRelationQuery<T, Name, Required>
206
- : PrepareRelationQuery<T, Name, Required> & {
206
+ ? PrepareRelationQuery<T, Name, Required, Populate>
207
+ : PrepareRelationQuery<T, Name, Required, Populate> & {
207
208
  [K in CreateMethodsNames]: never;
208
209
  },
209
- > = ((params: Params) => Q & { [defaultsKey]: Record<Populate, true> }) & Q;
210
+ > = ((params: Params) => Q) & Q;