【发布时间】:2021-11-03 19:56:27
【问题描述】:
我正在使用 pg PoolClient 使用 typescript 从 postgres 数据库中获取一些数据,目前,我正在使用以下方式获取一些数据,如果有更好的方法可以实现,请告诉我
const SPECIAL_LIST = [
"ABC",
"XYZ",
"PQR",
"LMN",
"EFG",
"IJK",
];
var params = SPECIAL_LIST.reduce(function (a, b, idx) {
if (idx === 0) return '$' + (idx + 2);
else return a + ', $' + (idx + 2);
}, '');
const sql = "Select sg.code,sg.dep,sg.vo,sg.arr from table1 sg where sg.is_omitted is false and v_code = $1 and sg.r_code not in (" +params+ ") order by sg.est_datetime asc"
const values = [vesselCode].concat(SPECIAL_LIST);
const client = await pool.connect();
await client
.query(sql, values)
.then((res) => {
const data = res.rows;
console.log(res.rowCount)
data.forEach((row) => {
// function logic
});
})
.catch((e) => console.error(e))
.then(() => client.release());
【问题讨论】:
标签: sql typescript postgresql