(metaData, columnTypes, err, results, errStack)
| 67 | } |
| 68 | |
| 69 | _handleQueryResponse(metaData, columnTypes, err, results, errStack) { |
| 70 | if (err) { |
| 71 | err.sql = this.sql; |
| 72 | throw this.formatError(err, errStack); |
| 73 | } |
| 74 | let result = this.instance; |
| 75 | |
| 76 | // add the inserted row id to the instance |
| 77 | if (this.isInsertQuery(results, metaData) || this.isUpsertQuery()) { |
| 78 | this.handleInsertQuery(results, metaData); |
| 79 | if (!this.instance) { |
| 80 | // handle bulkCreate AI primary key |
| 81 | if ( |
| 82 | metaData.constructor.name === 'Statement' |
| 83 | && this.model |
| 84 | && this.model.autoIncrementAttribute |
| 85 | && this.model.autoIncrementAttribute === this.model.primaryKeyAttribute |
| 86 | && this.model.rawAttributes[this.model.primaryKeyAttribute] |
| 87 | ) { |
| 88 | const startId = metaData[this.getInsertIdField()] - metaData.changes + 1; |
| 89 | result = []; |
| 90 | for (let i = startId; i < startId + metaData.changes; i++) { |
| 91 | result.push({ [this.model.rawAttributes[this.model.primaryKeyAttribute].field]: i }); |
| 92 | } |
| 93 | } else { |
| 94 | result = metaData[this.getInsertIdField()]; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if (this.isShowTablesQuery()) { |
| 100 | return results.map(row => row.name); |
| 101 | } |
| 102 | if (this.isShowConstraintsQuery()) { |
| 103 | result = results; |
| 104 | if (results && results[0] && results[0].sql) { |
| 105 | result = this.parseConstraintsFromSql(results[0].sql); |
| 106 | } |
| 107 | return result; |
| 108 | } |
| 109 | if (this.isSelectQuery()) { |
| 110 | if (this.options.raw) { |
| 111 | return this.handleSelectQuery(results); |
| 112 | } |
| 113 | // This is a map of prefix strings to models, e.g. user.projects -> Project model |
| 114 | const prefixes = this._collectModels(this.options.include); |
| 115 | |
| 116 | results = results.map(result => { |
| 117 | return _.mapValues(result, (value, name) => { |
| 118 | let model; |
| 119 | if (name.includes('.')) { |
| 120 | const lastind = name.lastIndexOf('.'); |
| 121 | |
| 122 | model = prefixes[name.substr(0, lastind)]; |
| 123 | |
| 124 | name = name.substr(lastind + 1); |
| 125 | } else { |
| 126 | model = this.options.model; |
no test coverage detected