【发布时间】:2018-04-21 05:02:56
【问题描述】:
我觉得我在这里遗漏了一些非常简单的东西。
我正在尝试使用 pg-promise 作为 outlined here. 的命名参数
我使用这个嵌套在db.task 函数中,editProductObj 是从我网站上的 HTML 表单中获得的。 MWE 如下:
db.task('edit-product', async t => {
console.log(editProductObj)
console.log(typeof(editProductObj))
console.log('display' in editProductObj)
// update product
await t.none(`UPDATE
product
SET
display = ${display},
product_date = ${product_date}
WHERE
product_id = ${product_id}`, editProductObj)
}).catch(err=>{console.log(err)})
将其输出到控制台:
{
display: 'true',
product_date: 2018-01-01T00:00:00.000Z,
product_id: '1'
} // object looks like what I expected
object // object is indeed an object
true // display is in the object passed
并且还输出错误:
ReferenceError: display is not defined
这让我相信t.none 函数没有正确访问editProductObj 对象,因为console.log 输出表明输入正常。
【问题讨论】:
标签: javascript node.js pg-promise