Browse Source

refactor : turning group fields as params

pull/13/head
oof1lab 7 years ago
parent
commit
2d218b33bd
  1. 12
      lib/xapi.js

12
lib/xapi.js

@ -482,21 +482,27 @@ class Xapi {
if (req.query && req.query._fields) { if (req.query && req.query._fields) {
let queryParamsObj = {} let queryParamsObj = {}
queryParamsObj.query = ''; queryParamsObj.query = 'select ';
queryParamsObj.params = []; queryParamsObj.params = [];
queryParamsObj.query = 'select ' + req.query._fields + ',count(*) as _count from ?? group by ' + req.query._fields; /**************** add columns and group by columns ****************/
this.mysql.getColumnsForSelectStmt(req.app.locals._tableName,req.query,queryParamsObj)
queryParamsObj.query += ',count(*) as _count from ?? group by ';
let tableName = req.app.locals._tableName; let tableName = req.app.locals._tableName;
queryParamsObj.params.push(tableName); queryParamsObj.params.push(tableName);
this.mysql.getColumnsForSelectStmt(req.app.locals._tableName,req.query,queryParamsObj)
if (!req.query._sort) { if (!req.query._sort) {
req.query._sort = {} req.query._sort = {}
req.query._sort = '-_count' req.query._sort = '-_count'
} }
/**************** where clause ****************/ /**************** add having clause ****************/
this.mysql.getHavingClause(req.query._having, req.app.locals._tableName, queryParamsObj, ' having '); this.mysql.getHavingClause(req.query._having, req.app.locals._tableName, queryParamsObj, ' having ');
/**************** add orderby clause ****************/
this.mysql.getOrderByClause(req.query, tableName, queryParamsObj); this.mysql.getOrderByClause(req.query, tableName, queryParamsObj);
//console.log(queryParamsObj.query, queryParamsObj.params); //console.log(queryParamsObj.query, queryParamsObj.params);

Loading…
Cancel
Save