* Internal method to execute a query * Not protected by the transaction mutex, so it can be used inside a transaction * @param query The query to execute * @param params Optional parameters for the query * @returns The result of the query
(
query: string,
params: any[] = [],
options?: QueryOptions,
)
| 208 | * @returns The result of the query |
| 209 | */ |
| 210 | async #runQuery<T>( |
| 211 | query: string, |
| 212 | params: any[] = [], |
| 213 | options?: QueryOptions, |
| 214 | ): Promise<Results<T>> { |
| 215 | return await this._runExclusiveQuery(async () => { |
| 216 | // We need to parse, bind and execute a query with parameters |
| 217 | this.#log('runQuery', query, params, options) |
| 218 | await this._handleBlob(options?.blob) |
| 219 | |
| 220 | let results |
| 221 | |
| 222 | try { |
| 223 | const { messages: parseResults } = await this.#execProtocolNoSync( |
| 224 | serializeProtocol.parse({ text: query, types: options?.paramTypes }), |
| 225 | options, |
| 226 | ) |
| 227 | |
| 228 | const dataTypeIDs = parseDescribeStatementResults( |
| 229 | ( |
| 230 | await this.#execProtocolNoSync( |
| 231 | serializeProtocol.describe({ type: 'S' }), |
| 232 | options, |
| 233 | ) |
| 234 | ).messages, |
| 235 | ) |
| 236 | |
| 237 | const values = params.map((param, i) => { |
| 238 | const oid = dataTypeIDs[i] |
| 239 | if (param === null || param === undefined) { |
| 240 | return null |
| 241 | } |
| 242 | const serialize = options?.serializers?.[oid] ?? this.serializers[oid] |
| 243 | if (serialize) { |
| 244 | return serialize(param) |
| 245 | } else { |
| 246 | return param.toString() |
| 247 | } |
| 248 | }) |
| 249 | |
| 250 | results = [ |
| 251 | ...parseResults, |
| 252 | ...( |
| 253 | await this.#execProtocolNoSync( |
| 254 | serializeProtocol.bind({ |
| 255 | values, |
| 256 | }), |
| 257 | options, |
| 258 | ) |
| 259 | ).messages, |
| 260 | ...( |
| 261 | await this.#execProtocolNoSync( |
| 262 | serializeProtocol.describe({ type: 'P' }), |
| 263 | options, |
| 264 | ) |
| 265 | ).messages, |
| 266 | ...( |
| 267 | await this.#execProtocolNoSync( |
nothing calls this directly
no test coverage detected