* High level function that handles the results of a query execution. * Example: * Oracle format : * { rows: //All rows [ [ 'Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production' ], [ 'PL/SQL Release 11.2.0.1.0 - Production' ], [ 'CORE\t11.2.0.1.0\t
(data)
| 395 | * @param {Array} data - The result of the query execution. |
| 396 | */ |
| 397 | formatResults(data) { |
| 398 | let result = this.instance; |
| 399 | if (this.isInsertQuery(data)) { |
| 400 | let insertData; |
| 401 | if (data.outBinds) { |
| 402 | const keys = Object.keys(this.options.outBindAttributes); |
| 403 | insertData = data.outBinds; |
| 404 | // For one row insert out bind array is 1D array |
| 405 | // we convert it to 2D array for uniformity |
| 406 | if (this.instance) { |
| 407 | insertData = [insertData]; |
| 408 | } |
| 409 | // Mapping the bind parameter to their values |
| 410 | const res = insertData.map(row =>{ |
| 411 | const obj = {}; |
| 412 | row.forEach((element, index) =>{ |
| 413 | obj[keys[index]] = element[0]; |
| 414 | }); |
| 415 | return obj; |
| 416 | }); |
| 417 | insertData = res; |
| 418 | // For bulk insert this.insert is undefined |
| 419 | // we map result to res, for one row insert |
| 420 | // result needs to be this.instance |
| 421 | if (!this.instance) { |
| 422 | result = res; |
| 423 | } |
| 424 | } |
| 425 | this.handleInsertQuery(insertData); |
| 426 | return [result, data.rowsAffected]; |
| 427 | } |
| 428 | if (this.isShowTablesQuery()) { |
| 429 | result = this.handleShowTablesQuery(data.rows); |
| 430 | } else if (this.isDescribeQuery()) { |
| 431 | result = {}; |
| 432 | // Getting the table name on which we are doing describe query |
| 433 | const table = Object.keys(this.sequelize.models); |
| 434 | const modelAttributes = {}; |
| 435 | // Get the model raw attributes |
| 436 | if (this.sequelize.models && table.length > 0) { |
| 437 | this._getAttributeMap(modelAttributes, this.sequelize.models[table[0]].rawAttributes); |
| 438 | } |
| 439 | data.rows.forEach(_result => { |
| 440 | if (_result.Default) { |
| 441 | _result.Default = _result.Default.replace("('", '') |
| 442 | .replace("')", '') |
| 443 | .replace(/'/g, ''); /* jshint ignore: line */ |
| 444 | } |
| 445 | |
| 446 | if (!(modelAttributes[_result.COLUMN_NAME] in result)) { |
| 447 | let key = modelAttributes[_result.COLUMN_NAME]; |
| 448 | if (!key) { |
| 449 | key = _result.COLUMN_NAME; |
| 450 | } |
| 451 | |
| 452 | result[key] = { |
| 453 | type: _result.DATA_TYPE.toUpperCase(), |
| 454 | allowNull: _result.NULLABLE === 'N' ? false : true, |
no test coverage detected