MCPcopy
hub / github.com/sequelize/sequelize / _handleQueryResponse

Method _handleQueryResponse

src/dialects/sqlite/query.js:78–226  ·  view source on GitHub ↗
(metaData, columnTypes, err, results, errStack)

Source from the content-addressed store, hash-verified

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

Callers 1

afterExecuteMethod · 0.80

Calls 15

formatErrorMethod · 0.95
handleInsertQueryMethod · 0.95
getInsertIdFieldMethod · 0.95
_collectModelsMethod · 0.95
applyParsersMethod · 0.95
isShowOrDescribeQueryMethod · 0.95
isInsertQueryMethod · 0.80
isUpsertQueryMethod · 0.80
isShowTablesQueryMethod · 0.80

Tested by

no test coverage detected