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

Method execute

packages/oracledb/src/OracleConnection.ts:142–197  ·  view source on GitHub ↗
(
    query: string | NativeQueryBuilder | RawQueryFragment,
    params: readonly unknown[] = [],
    method: 'all' | 'get' | 'run' = 'all',
    ctx?: Transaction,
    loggerContext?: LoggingOptions,
  )

Source from the content-addressed store, hash-verified

140 }
141
142 override async execute<
143 T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[],
144 >(
145 query: string | NativeQueryBuilder | RawQueryFragment,
146 params: readonly unknown[] = [],
147 method: 'all' | 'get' | 'run' = 'all',
148 ctx?: Transaction,
149 loggerContext?: LoggingOptions,
150 ): Promise<T> {
151 await this.ensureConnection();
152
153 if (query instanceof NativeQueryBuilder) {
154 query = query.toRaw();
155 }
156
157 if (isRaw(query)) {
158 params = query.params;
159 query = query.sql;
160 }
161
162 query = this.stripTrailingSemicolon(query);
163
164 let last: Dictionary | undefined;
165 let rawQuery: string | undefined;
166 const lastParam = params[params.length - 1];
167
168 if (Utils.isObject(lastParam) && '__outBindings' in lastParam && lastParam.__outBindings) {
169 rawQuery = lastParam.__rawQuery;
170 const { __outBindings, ...rest } = lastParam as Dictionary & { __outBindings: boolean };
171 last = rest;
172 params = [...params.slice(0, -1), last];
173 }
174
175 query = this.config.get('onQuery')(query, params);
176 const formatted = this.platform.formatQuery(query, params);
177 const sql = this.getSql(rawQuery ?? query, formatted, loggerContext);
178
179 return this.executeQuery<T>(
180 sql,
181 async () => {
182 const compiled = CompiledQuery.raw(formatted, last as unknown[]);
183
184 if (ctx) {
185 const res = await ctx.executeQuery(compiled);
186 return this.transformRawResult<T>(res, method);
187 }
188
189 const res = await this.getClient().executeQuery({
190 ...compiled,
191 autoCommit: true,
192 } as CompiledQuery);
193 return this.transformRawResult<T>(res, method);
194 },
195 { query, params, ...loggerContext },
196 );
197 }
198
199 /** @inheritDoc */

Callers

nothing calls this directly

Calls 11

executeQueryMethod · 0.95
transformRawResultMethod · 0.95
isRawFunction · 0.85
isObjectMethod · 0.80
sliceMethod · 0.80
formatQueryMethod · 0.80
getClientMethod · 0.80
getMethod · 0.65
toRawMethod · 0.45
executeQueryMethod · 0.45

Tested by

no test coverage detected