MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / execute

Function execute

packages/sql/src/AbstractSqlConnection.ts:287–308  ·  view source on GitHub ↗

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,
  )

Source from the content-addressed store, hash-verified

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>>(

Callers

nothing calls this directly

Calls 3

extractAbortOptionsFunction · 0.85
executeQueryMethod · 0.45
transformRawResultMethod · 0.45

Tested by

no test coverage detected