(sql, parameters)
| 31 | } |
| 32 | |
| 33 | async run(sql, parameters) { |
| 34 | this.sql = sql; |
| 35 | const { connection, options } = this; |
| 36 | |
| 37 | const showWarnings = this.sequelize.options.showWarnings || options.showWarnings; |
| 38 | |
| 39 | const complete = this._logQuery(sql, debug, parameters); |
| 40 | |
| 41 | if (parameters) { |
| 42 | debug('parameters(%j)', parameters); |
| 43 | } |
| 44 | |
| 45 | let results; |
| 46 | const errForStack = new Error(); |
| 47 | |
| 48 | try { |
| 49 | if (parameters && parameters.length) { |
| 50 | results = await new Promise((resolve, reject) => { |
| 51 | connection |
| 52 | .execute(sql, parameters, (error, result) => error ? reject(error) : resolve(result)) |
| 53 | .setMaxListeners(100); |
| 54 | }); |
| 55 | } else { |
| 56 | results = await new Promise((resolve, reject) => { |
| 57 | connection |
| 58 | .query({ sql }, (error, result) => error ? reject(error) : resolve(result)) |
| 59 | .setMaxListeners(100); |
| 60 | }); |
| 61 | } |
| 62 | } catch (error) { |
| 63 | if (options.transaction && error.errno === ER_DEADLOCK) { |
| 64 | // MySQL automatically rolls-back transactions in the event of a deadlock. |
| 65 | // However, we still initiate a manual rollback to ensure the connection gets released - see #13102. |
| 66 | try { |
| 67 | await options.transaction.rollback(); |
| 68 | } catch (error_) { |
| 69 | // Ignore errors - since MySQL automatically rolled back, we're |
| 70 | // not that worried about this redundant rollback failing. |
| 71 | } |
| 72 | |
| 73 | options.transaction.finished = 'rollback'; |
| 74 | } |
| 75 | |
| 76 | error.sql = sql; |
| 77 | error.parameters = parameters; |
| 78 | throw this.formatError(error, errForStack.stack); |
| 79 | } finally { |
| 80 | complete(); |
| 81 | } |
| 82 | |
| 83 | if (showWarnings && results && results.warningStatus > 0) { |
| 84 | await this.logWarnings(results); |
| 85 | } |
| 86 | return this.formatResults(results); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * High level function that handles the results of a query execution. |
no test coverage detected