(
query: string | NativeQueryBuilder | RawQueryFragment,
params: readonly unknown[] = [],
method: 'all' | 'get' | 'run' = 'all',
ctx?: Transaction,
loggerContext?: LoggingOptions,
)
| 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 */ |
nothing calls this directly
no test coverage detected