【发布时间】:2019-10-30 22:50:50
【问题描述】:
我正在编写一个使用 node.js 查询 Postgresql 数据库的程序。我有正确的查询来自数据库。我只是对输出格式有疑问。我需要将结果发送到另一个函数。
我正在使用 Postgresql 和 nodejs 查询数据库,结果显示为 { model: 'Antonov An-148 (241 nmi)' }。我希望Antonov An-148 (241 nmi) 成为结果并发送到setValue 函数。
我是否应该以不同的方式查询数据库,因为我有其他查询要发送到其他函数进行计算?
client.connect()
.then(() => console.log("Connected successfuly"))
.then(() => client.query("select model from \"aircraftModels\" where model = $1", ["Antonov An-148 (241 nmi)"]))
.then (results => setValue(results.rows))
.catch(e => console.log(e))
.finally(() => client.end())
function setValue(value){
console.log(value);
}
实际结果:{ model: 'Antonov An-148 (241 nmi)' }
预期结果:Antonov An-148 (241 nmi)
【问题讨论】:
-
然后记录
value.model而不是value。 -
value.model以未定义的形式返回 -
然后需要将JSON解析成一个对象,然后访问
value.model。
标签: javascript node.js postgresql