* @param {string} sql * @param {Function} debugContext * @param {Array|object} parameters * @protected * @returns {Function} A function to call after the query was completed.
(sql, debugContext, parameters)
| 353 | * @returns {Function} A function to call after the query was completed. |
| 354 | */ |
| 355 | _logQuery(sql, debugContext, parameters) { |
| 356 | const { connection, options } = this; |
| 357 | const benchmark = this.sequelize.options.benchmark || options.benchmark; |
| 358 | const logQueryParameters = this.sequelize.options.logQueryParameters || options.logQueryParameters; |
| 359 | const startTime = Date.now(); |
| 360 | let logParameter = ''; |
| 361 | |
| 362 | if (logQueryParameters && parameters) { |
| 363 | const delimiter = sql.endsWith(';') ? '' : ';'; |
| 364 | let paramStr; |
| 365 | if (Array.isArray(parameters)) { |
| 366 | paramStr = parameters.map(p=>safeStringifyJson(p)).join(', '); |
| 367 | } else { |
| 368 | paramStr = safeStringifyJson(parameters); |
| 369 | } |
| 370 | logParameter = `${delimiter} ${paramStr}`; |
| 371 | } |
| 372 | const fmt = `(${connection.uuid || 'default'}): ${sql}${logParameter}`; |
| 373 | const msg = `Executing ${fmt}`; |
| 374 | debugContext(msg); |
| 375 | if (!benchmark) { |
| 376 | this.sequelize.log(`Executing ${fmt}`, options); |
| 377 | } |
| 378 | return () => { |
| 379 | const afterMsg = `Executed ${fmt}`; |
| 380 | debugContext(afterMsg); |
| 381 | if (benchmark) { |
| 382 | this.sequelize.log(afterMsg, Date.now() - startTime, options); |
| 383 | } |
| 384 | }; |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * The function takes the result of the query execution and groups |