* High level function that handles the results of a query execution. * * @param {Array} data - The result of the query execution. * @param {number} rowCount * @private * @example * Example: * query.formatResults([ * { * id: 1, // this is from the main
(data, rowCount)
| 163 | * ]) |
| 164 | */ |
| 165 | formatResults(data, rowCount) { |
| 166 | if (this.isInsertQuery(data)) { |
| 167 | this.handleInsertQuery(data); |
| 168 | return [this.instance || data, rowCount]; |
| 169 | } |
| 170 | if (this.isShowTablesQuery()) { |
| 171 | return this.handleShowTablesQuery(data); |
| 172 | } |
| 173 | if (this.isDescribeQuery()) { |
| 174 | const result = {}; |
| 175 | for (const _result of data) { |
| 176 | if (_result.Default) { |
| 177 | _result.Default = _result.Default.replace("('", '').replace("')", '').replace(/'/g, ''); |
| 178 | } |
| 179 | |
| 180 | result[_result.Name] = { |
| 181 | type: _result.Type.toUpperCase(), |
| 182 | allowNull: _result.IsNull === 'YES' ? true : false, |
| 183 | defaultValue: _result.Default, |
| 184 | primaryKey: _result.Constraint === 'PRIMARY KEY', |
| 185 | autoIncrement: _result.IsIdentity === 1, |
| 186 | comment: _result.Comment |
| 187 | }; |
| 188 | |
| 189 | if ( |
| 190 | result[_result.Name].type.includes('CHAR') |
| 191 | && _result.Length |
| 192 | ) { |
| 193 | if (_result.Length === -1) { |
| 194 | result[_result.Name].type += '(MAX)'; |
| 195 | } else { |
| 196 | result[_result.Name].type += `(${_result.Length})`; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | return result; |
| 201 | } |
| 202 | if (this.isSelectQuery()) { |
| 203 | return this.handleSelectQuery(data); |
| 204 | } |
| 205 | if (this.isShowIndexesQuery()) { |
| 206 | return this.handleShowIndexesQuery(data); |
| 207 | } |
| 208 | if (this.isCallQuery()) { |
| 209 | return data[0]; |
| 210 | } |
| 211 | if (this.isBulkUpdateQuery()) { |
| 212 | if (this.options.returning) { |
| 213 | return this.handleSelectQuery(data); |
| 214 | } |
| 215 | |
| 216 | return rowCount; |
| 217 | } |
| 218 | if (this.isBulkDeleteQuery()) { |
| 219 | return data[0] ? data[0].AFFECTEDROWS : 0; |
| 220 | } |
| 221 | if (this.isVersionQuery()) { |
| 222 | return data[0].version; |
no test coverage detected