(sql, parameters)
| 47 | } |
| 48 | |
| 49 | async run(sql, parameters) { |
| 50 | const { connection } = this; |
| 51 | |
| 52 | if (!_.isEmpty(this.options.searchPath)) { |
| 53 | sql = this.sequelize.getQueryInterface().queryGenerator.setSearchPath(this.options.searchPath) + sql; |
| 54 | } |
| 55 | |
| 56 | if (this.sequelize.options.minifyAliases && this.options.includeAliases) { |
| 57 | _.toPairs(this.options.includeAliases) |
| 58 | // Sorting to replace the longest aliases first to prevent alias collision |
| 59 | .sort((a, b) => b[1].length - a[1].length) |
| 60 | .forEach(([alias, original]) => { |
| 61 | const reg = new RegExp(_.escapeRegExp(original), 'g'); |
| 62 | |
| 63 | sql = sql.replace(reg, alias); |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | this.sql = sql; |
| 68 | |
| 69 | const query = parameters && parameters.length |
| 70 | ? new Promise((resolve, reject) => connection.query(sql, parameters, (error, result) => error ? reject(error) : resolve(result))) |
| 71 | : new Promise((resolve, reject) => connection.query(sql, (error, result) => error ? reject(error) : resolve(result))); |
| 72 | |
| 73 | const complete = this._logQuery(sql, debug, parameters); |
| 74 | |
| 75 | let queryResult; |
| 76 | const errForStack = new Error(); |
| 77 | |
| 78 | try { |
| 79 | queryResult = await query; |
| 80 | } catch (error) { |
| 81 | // set the client so that it will be reaped if the connection resets while executing |
| 82 | if (error.code === 'ECONNRESET' |
| 83 | // https://github.com/sequelize/sequelize/pull/14090 |
| 84 | // pg-native throws custom exception or libpq formatted errors |
| 85 | || /Unable to set non-blocking to true/i.test(error) |
| 86 | || /SSL SYSCALL error: EOF detected/i.test(error) |
| 87 | || /Local: Authentication failure/i.test(error) |
| 88 | // https://github.com/sequelize/sequelize/pull/15144 |
| 89 | || error.message === 'Query read timeout' |
| 90 | ) { |
| 91 | connection._invalid = true; |
| 92 | } |
| 93 | |
| 94 | error.sql = sql; |
| 95 | error.parameters = parameters; |
| 96 | throw this.formatError(error, errForStack.stack); |
| 97 | } |
| 98 | |
| 99 | complete(); |
| 100 | |
| 101 | let rows = Array.isArray(queryResult) |
| 102 | ? queryResult.reduce((allRows, r) => allRows.concat(r.rows || []), []) |
| 103 | : queryResult.rows; |
| 104 | const rowCount = Array.isArray(queryResult) |
| 105 | ? queryResult.reduce( |
| 106 | (count, r) => Number.isFinite(r.rowCount) ? count + r.rowCount : count, |
nothing calls this directly
no test coverage detected