MCPcopy
hub / github.com/sequelize/sequelize / handleSelectQuery

Method handleSelectQuery

src/dialects/abstract/query.js:268–333  ·  view source on GitHub ↗
(results)

Source from the content-addressed store, hash-verified

266 }
267
268 handleSelectQuery(results) {
269 let result = null;
270
271 // Map raw fields to names if a mapping is provided
272 if (this.options.fieldMap) {
273 const fieldMap = this.options.fieldMap;
274 results = results.map(result => _.reduce(fieldMap, (result, name, field) => {
275 if (result[field] !== undefined && name !== field) {
276 result[name] = result[field];
277 delete result[field];
278 }
279 return result;
280 }, result));
281 }
282
283 // Raw queries
284 if (this.options.raw) {
285 result = results.map(result => {
286 let o = {};
287
288 for (const key in result) {
289 if (Object.prototype.hasOwnProperty.call(result, key)) {
290 o[key] = result[key];
291 }
292 }
293
294 if (this.options.nest) {
295 o = Dot.transform(o);
296 }
297
298 return o;
299 });
300 // Queries with include
301 } else if (this.options.hasJoin === true) {
302 results = AbstractQuery._groupJoinData(results, {
303 model: this.model,
304 includeMap: this.options.includeMap,
305 includeNames: this.options.includeNames
306 }, {
307 checkExisting: this.options.hasMultiAssociation
308 });
309
310 result = this.model.bulkBuild(results, {
311 isNewRecord: false,
312 include: this.options.include,
313 includeNames: this.options.includeNames,
314 includeMap: this.options.includeMap,
315 includeValidated: true,
316 attributes: this.options.originalAttributes || this.options.attributes,
317 raw: true
318 });
319 // Regular queries
320 } else {
321 result = this.model.bulkBuild(results, {
322 isNewRecord: false,
323 raw: true,
324 attributes: this.options.originalAttributes || this.options.attributes
325 });

Callers 8

runMethod · 0.80
formatResultsMethod · 0.80
formatResultsMethod · 0.80
formatResultsMethod · 0.80
formatResultsMethod · 0.80
formatResultsMethod · 0.80
_handleQueryResponseMethod · 0.80
formatResultsMethod · 0.80

Calls 2

_groupJoinDataMethod · 0.80
bulkBuildMethod · 0.80

Tested by

no test coverage detected