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

Method formatResults

src/dialects/db2/query.js:263–330  ·  view source on GitHub ↗

* High level function that handles the results of a query execution. * * * Example: * query.formatResults([ * { * id: 1, // this is from the main table * attr2: 'snafu', // this is from the main table * Tasks.id: 1, // this is from t

(data, rowCount, metadata, conn)

Source from the content-addressed store, hash-verified

261 * @private
262 */
263 formatResults(data, rowCount, metadata, conn) {
264 let result = this.instance;
265 if (this.isInsertQuery(data, metadata)) {
266 this.handleInsertQuery(data, metadata);
267
268 if (!this.instance) {
269 if (this.options.plain) {
270 const record = data[0];
271 result = record[Object.keys(record)[0]];
272 } else {
273 result = data;
274 }
275 }
276 }
277
278 if (this.isShowTablesQuery()) {
279 result = data;
280 } else if (this.isDescribeQuery()) {
281 result = {};
282 for (const _result of data) {
283 if (_result.Default) {
284 _result.Default = _result.Default.replace("('", '').replace("')", '').replace(/'/g, '');
285 }
286
287 result[_result.Name] = {
288 type: _result.Type.toUpperCase(),
289 allowNull: _result.IsNull === 'Y' ? true : false,
290 defaultValue: _result.Default,
291 primaryKey: _result.KeySeq > 0,
292 autoIncrement: _result.IsIdentity === 'Y' ? true : false,
293 comment: _result.Comment
294 };
295 }
296 } else if (this.isShowIndexesQuery()) {
297 result = this.handleShowIndexesQuery(data);
298 } else if (this.isSelectQuery()) {
299 result = this.handleSelectQuery(data);
300 } else if (this.isUpsertQuery()) {
301 result = data;
302 } else if (this.isDropSchemaQuery()) {
303 result = data[0];
304 if (conn) {
305 const query = 'DROP TABLE ERRORSCHEMA.ERRORTABLE';
306 conn.querySync(query);
307 }
308 } else if (this.isCallQuery()) {
309 result = data;
310 } else if (this.isBulkUpdateQuery()) {
311 result = data.length;
312 } else if (this.isBulkDeleteQuery()) {
313 result = rowCount;
314 } else if (this.isVersionQuery()) {
315 result = data[0].VERSION;
316 } else if (this.isForeignKeysQuery()) {
317 result = data;
318 } else if (this.isInsertQuery() || this.isUpdateQuery()) {
319 result = [result, rowCount];
320 } else if (this.isShowConstraintsQuery()) {

Callers 1

_runMethod · 0.95

Calls 15

handleInsertQueryMethod · 0.95
isShowIndexesQueryMethod · 0.95
isDropSchemaQueryMethod · 0.95
isForeignKeysQueryMethod · 0.95
isInsertQueryMethod · 0.80
isShowTablesQueryMethod · 0.80
isDescribeQueryMethod · 0.80
isSelectQueryMethod · 0.80
handleSelectQueryMethod · 0.80
isUpsertQueryMethod · 0.80

Tested by

no test coverage detected