MCPcopy
hub / github.com/sequelize/sequelize / formatResults

Method formatResults

src/dialects/oracle/query.js:397–511  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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,

Callers 1

runMethod · 0.95

Calls 15

handleInsertQueryMethod · 0.95
handleShowTablesQueryMethod · 0.95
_getAttributeMapMethod · 0.95
isShowIndexesQueryMethod · 0.95
_processRowsMethod · 0.95
isInsertQueryMethod · 0.80
isShowTablesQueryMethod · 0.80
isDescribeQueryMethod · 0.80
isSelectQueryMethod · 0.80
handleSelectQueryMethod · 0.80

Tested by

no test coverage detected