【发布时间】:2020-11-19 19:52:20
【问题描述】:
我正在创建一个以 postgresql 作为后端的 nodejs 项目,我使用 pg_promise 作为查询驱动程序
目前我必须对可能不同但都具有相同相等条件检查的列执行选择语句,如下所示
pg.any('select * from table where col1 = ${col1} and col2 = ${col2}',{
col1:value1,
col2:value2
});
// which generates the query shown below
// select * from table where col2 = value1 and col2 = value2;
我想要的是希望找到一种更简单的方法来生成选择查询,其中变量 no 的列具有相等的 where 条件,类似于 pg_promise 允许我们使用 helpers.update 来生成更新查询。
// something like shown below
pg.helpers.select('select * from table ',{col1:value1, col2:value2})
// it shoud generate the same as the query with static columns
//select * from table where col2 = value1 and col2 = value2;
【问题讨论】:
-
您应该在问题中包含
$(dynamic columns list)的预期输出。否则,不清楚你想要什么。此外,适当地格式化您的问题会很好,也许是一个更好的标题。看起来一团糟。
标签: pg-promise