* High level function that handles the results of a query execution. * * * Example: * query.formatResults([ * { * id: 1, // this is from the main table * attr2: 'snafu', // this is from the main table * Tasks.id: 1, // this is from t
(data, rowCount, metadata, conn)
| 249 | * @private |
| 250 | */ |
| 251 | formatResults(data, rowCount, metadata, conn) { |
| 252 | let result = this.instance; |
| 253 | if (this.isInsertQuery(data, metadata)) { |
| 254 | this.handleInsertQuery(data, metadata); |
| 255 | |
| 256 | if (!this.instance) { |
| 257 | if (this.options.plain) { |
| 258 | const record = data[0]; |
| 259 | result = record[Object.keys(record)[0]]; |
| 260 | } else { |
| 261 | result = data; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if (this.isShowTablesQuery()) { |
| 267 | result = data; |
| 268 | } else if (this.isDescribeQuery()) { |
| 269 | result = {}; |
| 270 | for (const _result of data) { |
| 271 | if (_result.Default) { |
| 272 | _result.Default = _result.Default.replace("('", '').replace("')", '').replace(/'/g, ''); |
| 273 | } |
| 274 | |
| 275 | result[_result.Name] = { |
| 276 | type: _result.Type.toUpperCase(), |
| 277 | allowNull: _result.IsNull === 'Y' ? true : false, |
| 278 | defaultValue: _result.Default, |
| 279 | primaryKey: _result.KeySeq > 0, |
| 280 | autoIncrement: _result.IsIdentity === 'Y' ? true : false, |
| 281 | comment: _result.Comment |
| 282 | }; |
| 283 | } |
| 284 | } else if (this.isShowIndexesQuery()) { |
| 285 | result = this.handleShowIndexesQuery(data); |
| 286 | } else if (this.isSelectQuery()) { |
| 287 | result = this.handleSelectQuery(data); |
| 288 | } else if (this.isUpsertQuery()) { |
| 289 | result = data; |
| 290 | } else if (this.isDropSchemaQuery()) { |
| 291 | result = data[0]; |
| 292 | if (conn) { |
| 293 | const query = 'DROP TABLE ERRORSCHEMA.ERRORTABLE'; |
| 294 | conn.querySync(query); |
| 295 | } |
| 296 | } else if (this.isCallQuery()) { |
| 297 | result = data; |
| 298 | } else if (this.isBulkUpdateQuery()) { |
| 299 | result = data.length; |
| 300 | } else if (this.isBulkDeleteQuery()) { |
| 301 | result = rowCount; |
| 302 | } else if (this.isVersionQuery()) { |
| 303 | result = data[0].VERSION; |
| 304 | } else if (this.isForeignKeysQuery()) { |
| 305 | result = data; |
| 306 | } else if (this.isInsertQuery() || this.isUpdateQuery()) { |
| 307 | result = [result, rowCount]; |
| 308 | } else if (this.isShowConstraintsQuery()) { |
no test coverage detected