查询原始查询结果null

时间:2017-03-07 07:02:07

标签: node.js postgresql sequelize.js

以下是我用于获取结果的代码。当我在pgAdmin中执行此查询时它工作正常,但是当我通过Sequelize执行它时它不会给出结果。请在这里建议我做错了什么....

return new Promise(function (resolve, reject) {

var sql = "SELECT ' FROM '||string_agg (child_name || coalesce (' on '|| e_p_name ||'.'|| ec_p_name ||' = '|| e_c_name ||'.'||ec_c_name,'') || coalesce(' and '||conditionentityname||'.'||conditionalcolumn|| ' '||OperatorName||''''||condition_value||'''',''),' JOIN ') AS query \
        FROM\
            (SELECT \
              CASE WHEN child.name <> coalesce( e_p.name, child.name) THEN  e_c.name ELSE child.name  END child_name ,\
              e_p.name e_p_name , ec_p.name ec_p_name,\
              e_c.name e_c_name,  ec_c.name ec_c_name,\
              d_c.column_id,d_c.operator_id,d_c.condition_value condition_value,\
              ec_condition.name as conditionalcolumn,op.name as OperatorName,\
              e_condition_entity.name as conditionentityname\
            FROM \
              dataset_entity dse \
              JOIN entity child ON dse.entityid=child.id\
              LEFT JOIN table1 em ON ((em.baseentity = dse.parent AND em.childentity = dse.entityid) OR (em.baseentity = dse.entityid AND em.childentity = dse.parent))\
              LEFT JOIN table2 jc ON jc.relationshipid= em.id\
              LEFT JOIN table3 ec_p ON ec_p.id = jc.parentpk\
              LEFT JOIN table4 e_p ON e_p.id = ec_p.entity_id\
              LEFT JOIN table5 ec_c ON ec_c.id = jc.childfk\
              LEFT JOIN table6 e_c ON e_c.id = ec_c.entity_id\
                LEFT JOIN table7 d_c ON dse.id=d_c.dataset_entity_id\
                LEFT JOIN table8 ec_condition ON d_c.column_id=ec_condition.id\
                LEFT JOIN table9 e_condition_entity ON ec_condition.entity_id=e_condition_entity.id\
                LEFT JOIN table10 op ON op.id=d_c.operator_id\
            WHERE \
              dse.dataset_id =? ORDER BY dse.id) t";

 var query = sequelizeClient.query(sql, {
   replacements: [id],
   type: sequelizeClient.QueryTypes.SELECT     
 }).then(function (resultquery) {

   if (resultquery.length > 0) {
     resolve(resultquery[0].query);
   } else {
     resolve("");
   }
 }).catch(function (error) {

   reject(error);
 });

0 个答案:

没有答案