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

Method handleSelectQuery

lib/dialects/abstract/query.js:244–309  ·  view source on GitHub ↗
(results)

Source from the content-addressed store, hash-verified

242 }
243
244 handleSelectQuery(results) {
245 let result = null;
246
247 // Map raw fields to names if a mapping is provided
248 if (this.options.fieldMap) {
249 const fieldMap = this.options.fieldMap;
250 results = results.map(result => _.reduce(fieldMap, (result, name, field) => {
251 if (result[field] !== undefined && name !== field) {
252 result[name] = result[field];
253 delete result[field];
254 }
255 return result;
256 }, result));
257 }
258
259 // Raw queries
260 if (this.options.raw) {
261 result = results.map(result => {
262 let o = {};
263
264 for (const key in result) {
265 if (Object.prototype.hasOwnProperty.call(result, key)) {
266 o[key] = result[key];
267 }
268 }
269
270 if (this.options.nest) {
271 o = Dot.transform(o);
272 }
273
274 return o;
275 });
276 // Queries with include
277 } else if (this.options.hasJoin === true) {
278 results = AbstractQuery._groupJoinData(results, {
279 model: this.model,
280 includeMap: this.options.includeMap,
281 includeNames: this.options.includeNames
282 }, {
283 checkExisting: this.options.hasMultiAssociation
284 });
285
286 result = this.model.bulkBuild(results, {
287 isNewRecord: false,
288 include: this.options.include,
289 includeNames: this.options.includeNames,
290 includeMap: this.options.includeMap,
291 includeValidated: true,
292 attributes: this.options.originalAttributes || this.options.attributes,
293 raw: true
294 });
295 // Regular queries
296 } else {
297 result = this.model.bulkBuild(results, {
298 isNewRecord: false,
299 raw: true,
300 attributes: this.options.originalAttributes || this.options.attributes
301 });

Callers 7

runMethod · 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