@@ -42,11 +42,7 @@ import { freeze } from '../util/object-utils.js'
4242import { KyselyPlugin } from '../plugin/kysely-plugin.js'
4343import { WhereInterface } from './where-interface.js'
4444import { MultiTableReturningInterface } from './returning-interface.js'
45- import {
46- isNoResultErrorConstructor ,
47- NoResultError ,
48- NoResultErrorConstructor ,
49- } from './no-result-error.js'
45+ import { isNoResultErrorConstructor , NoResultError } from './no-result-error.js'
5046import { DeleteResult } from './delete-result.js'
5147import { DeleteQueryNode } from '../operation-node/delete-query-node.js'
5248import { LimitNode } from '../operation-node/limit-node.js'
@@ -81,6 +77,11 @@ import {
8177} from './output-interface.js'
8278import { JoinType } from '../operation-node/join-node.js'
8379import { OrderByInterface } from './order-by-interface.js'
80+ import {
81+ Executable ,
82+ ExecuteOptions ,
83+ ExecuteOrThrowOptions ,
84+ } from '../util/executable.js'
8485
8586export class DeleteQueryBuilder < DB , TB extends keyof DB , O >
8687 implements
@@ -90,6 +91,7 @@ export class DeleteQueryBuilder<DB, TB extends keyof DB, O>
9091 OrderByInterface < DB , TB , { } > ,
9192 OperationNodeSource ,
9293 Compilable < O > ,
94+ Executable < O > ,
9395 Explainable ,
9496 Streamable < O >
9597{
@@ -1051,15 +1053,13 @@ export class DeleteQueryBuilder<DB, TB extends keyof DB, O>
10511053 )
10521054 }
10531055
1054- /**
1055- * Executes the query and returns an array of rows.
1056- *
1057- * Also see the {@link executeTakeFirst} and {@link executeTakeFirstOrThrow} methods.
1058- */
1059- async execute ( ) : Promise < SimplifyResult < O > [ ] > {
1056+ async execute ( options ?: ExecuteOptions ) : Promise < SimplifyResult < O > [ ] > {
10601057 const compiledQuery = this . compile ( )
10611058
1062- const result = await this . #props. executor . executeQuery < O > ( compiledQuery )
1059+ const result = await this . #props. executor . executeQuery < O > (
1060+ compiledQuery ,
1061+ options ,
1062+ )
10631063
10641064 const { adapter } = this . #props. executor
10651065 const query = compiledQuery . query as DeleteQueryNode
@@ -1068,45 +1068,45 @@ export class DeleteQueryBuilder<DB, TB extends keyof DB, O>
10681068 ( query . returning && adapter . supportsReturning ) ||
10691069 ( query . output && adapter . supportsOutput )
10701070 ) {
1071- return result . rows as any
1071+ return result . rows as never
10721072 }
10731073
1074- return [ new DeleteResult ( result . numAffectedRows ?? BigInt ( 0 ) ) as any ]
1074+ return [ new DeleteResult ( result . numAffectedRows ?? BigInt ( 0 ) ) as never ]
10751075 }
10761076
1077- /**
1078- * Executes the query and returns the first result or undefined if
1079- * the query returned no result.
1080- */
1081- async executeTakeFirst ( ) : Promise < SimplifySingleResult < O > > {
1082- const [ result ] = await this . execute ( )
1083- return result as SimplifySingleResult < O >
1077+ async executeTakeFirst (
1078+ options ?: ExecuteOptions ,
1079+ ) : Promise < SimplifySingleResult < O > > {
1080+ const [ result ] = await this . execute ( options )
1081+
1082+ return result
10841083 }
10851084
1086- /**
1087- * Executes the query and returns the first result or throws if
1088- * the query returned no result.
1089- *
1090- * By default an instance of {@link NoResultError} is thrown, but you can
1091- * provide a custom error class, or callback as the only argument to throw a different
1092- * error.
1093- */
10941085 async executeTakeFirstOrThrow (
1095- errorConstructor :
1096- | NoResultErrorConstructor
1097- | ( ( node : QueryNode ) => Error ) = NoResultError ,
1086+ errorConstructorOrOptions ? :
1087+ | ExecuteOrThrowOptions
1088+ | ExecuteOrThrowOptions [ 'errorConstructor' ] ,
10981089 ) : Promise < SimplifyResult < O > > {
1099- const result = await this . executeTakeFirst ( )
1090+ if ( typeof errorConstructorOrOptions === 'function' ) {
1091+ errorConstructorOrOptions = {
1092+ errorConstructor : errorConstructorOrOptions ,
1093+ }
1094+ }
1095+
1096+ const result = await this . executeTakeFirst ( errorConstructorOrOptions )
11001097
11011098 if ( result === undefined ) {
1099+ const errorConstructor =
1100+ errorConstructorOrOptions ?. errorConstructor ?? NoResultError
1101+
11021102 const error = isNoResultErrorConstructor ( errorConstructor )
11031103 ? new errorConstructor ( this . toOperationNode ( ) )
11041104 : errorConstructor ( this . toOperationNode ( ) )
11051105
11061106 throw error
11071107 }
11081108
1109- return result as SimplifyResult < O >
1109+ return result as never
11101110 }
11111111
11121112 async * stream ( chunkSize : number = 100 ) : AsyncIterableIterator < O > {
0 commit comments