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

Method formatResults

lib/dialects/mssql/query.js:156–237  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

154 * ])
155 */
156 formatResults(data, rowCount) {
157 if (this.isInsertQuery(data)) {
158 this.handleInsertQuery(data);
159 return [this.instance || data, rowCount];
160 }
161 if (this.isShowTablesQuery()) {
162 return this.handleShowTablesQuery(data);
163 }
164 if (this.isDescribeQuery()) {
165 const result = {};
166 for (const _result of data) {
167 if (_result.Default) {
168 _result.Default = _result.Default.replace("('", '').replace("')", '').replace(/'/g, '');
169 }
170
171 result[_result.Name] = {
172 type: _result.Type.toUpperCase(),
173 allowNull: _result.IsNull === 'YES' ? true : false,
174 defaultValue: _result.Default,
175 primaryKey: _result.Constraint === 'PRIMARY KEY',
176 autoIncrement: _result.IsIdentity === 1,
177 comment: _result.Comment
178 };
179
180 if (
181 result[_result.Name].type.includes('CHAR')
182 && _result.Length
183 ) {
184 if (_result.Length === -1) {
185 result[_result.Name].type += '(MAX)';
186 } else {
187 result[_result.Name].type += `(${_result.Length})`;
188 }
189 }
190 }
191 return result;
192 }
193 if (this.isSelectQuery()) {
194 return this.handleSelectQuery(data);
195 }
196 if (this.isShowIndexesQuery()) {
197 return this.handleShowIndexesQuery(data);
198 }
199 if (this.isCallQuery()) {
200 return data[0];
201 }
202 if (this.isBulkUpdateQuery()) {
203 if (this.options.returning) {
204 return this.handleSelectQuery(data);
205 }
206
207 return rowCount;
208 }
209 if (this.isBulkDeleteQuery()) {
210 return data[0] ? data[0].AFFECTEDROWS : 0;
211 }
212 if (this.isVersionQuery()) {
213 return data[0].version;

Callers 1

_runMethod · 0.95

Calls 15

handleInsertQueryMethod · 0.95
handleShowTablesQueryMethod · 0.95
isShowIndexesQueryMethod · 0.95
isForeignKeysQueryMethod · 0.95
isInsertQueryMethod · 0.80
isShowTablesQueryMethod · 0.80
isDescribeQueryMethod · 0.80
isSelectQueryMethod · 0.80
handleSelectQueryMethod · 0.80
isCallQueryMethod · 0.80

Tested by

no test coverage detected