Executes a SQL query and returns the result based on the method: `'all'` for rows, `'get'` for single row, `'run'` for affected count.
(
query: string | NativeQueryBuilder | RawQueryFragment,
params: readonly unknown[] = [],
method: 'all' | 'get' | 'run' = 'all',
ctx?: Transaction,
loggerContext?: LoggingOptions,
)
| 285 | |
| 286 | /** Executes a SQL query and returns the result based on the method: `'all'` for rows, `'get'` for single row, `'run'` for affected count. */ |
| 287 | async execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>( |
| 288 | query: string | NativeQueryBuilder | RawQueryFragment, |
| 289 | params: readonly unknown[] = [], |
| 290 | method: 'all' | 'get' | 'run' = 'all', |
| 291 | ctx?: Transaction, |
| 292 | loggerContext?: LoggingOptions, |
| 293 | ): Promise<T> { |
| 294 | await this.ensureConnection(); |
| 295 | const q = this.prepareQuery(query, params); |
| 296 | const sql = this.getSql(q.query, q.formatted, loggerContext); |
| 297 | const { abort, loggerContext: cleanCtx } = extractAbortOptions(loggerContext); |
| 298 | |
| 299 | return this.executeQuery<T>( |
| 300 | sql, |
| 301 | async () => { |
| 302 | const compiled = CompiledQuery.raw(q.formatted); |
| 303 | const res = await (ctx ?? this.#client).executeQuery(compiled, abort); |
| 304 | return this.transformRawResult<T>(res, method); |
| 305 | }, |
| 306 | { ...q, ...cleanCtx }, |
| 307 | ); |
| 308 | } |
| 309 | |
| 310 | /** Executes a SQL query and returns an async iterable that yields results row by row. */ |
| 311 | async *stream<T extends EntityData<AnyEntity>>( |
nothing calls this directly
no test coverage detected