pqb 0.4.3 → 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.3",
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('*')) {