(sql, parameters)
| 27 | } |
| 28 | |
| 29 | async run(sql, parameters) { |
| 30 | this.sql = sql; |
| 31 | const { connection, options } = this; |
| 32 | |
| 33 | const showWarnings = this.sequelize.options.showWarnings || options.showWarnings; |
| 34 | |
| 35 | const complete = this._logQuery(sql, debug, parameters); |
| 36 | |
| 37 | if (parameters) { |
| 38 | debug('parameters(%j)', parameters); |
| 39 | } |
| 40 | |
| 41 | let results; |
| 42 | |
| 43 | try { |
| 44 | results = await new Promise((resolve, reject) => { |
| 45 | connection.execute({ |
| 46 | sqlText: sql, |
| 47 | binds: parameters, |
| 48 | complete(err, _stmt, rows) { |
| 49 | if (err) { |
| 50 | reject(err); |
| 51 | } else { |
| 52 | resolve(rows); |
| 53 | } |
| 54 | } |
| 55 | }); |
| 56 | }); |
| 57 | } catch (error) { |
| 58 | if (options.transaction && error.errno === ER_DEADLOCK) { |
| 59 | try { |
| 60 | await options.transaction.rollback(); |
| 61 | } catch (error_) { |
| 62 | // ignore errors |
| 63 | } |
| 64 | |
| 65 | options.transaction.finished = 'rollback'; |
| 66 | } |
| 67 | |
| 68 | error.sql = sql; |
| 69 | error.parameters = parameters; |
| 70 | throw this.formatError(error); |
| 71 | } finally { |
| 72 | complete(); |
| 73 | } |
| 74 | |
| 75 | if (showWarnings && results && results.warningStatus > 0) { |
| 76 | await this.logWarnings(results); |
| 77 | } |
| 78 | return this.formatResults(results); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * High level function that handles the results of a query execution. |
no test coverage detected