2
我有一个简单的类,它使插入数据更容易。我正在使用pg-promise
库与数据库交谈。TypeError:无法通过pg-promise插入读取未定义的属性'then'
class C_SQL
{
insert_text(text)
{
var time_now = new Date();
return
db.none(
`INSERT INTO notes(\
id,\
date,\
text,\
)
VALUES (\
(SELECT max(id) from notes)+1\,
'${time_now.setFullYear(time_now.getFullYear() + 1) ? time_now : ``}',\
${text}\
);`
);
}
}
我试图使用它,像这样:
var one = new C_SQL();
one.insert_text("inserted from a program")
.then(() => console.log("Inserted"))
.catch(err => console.log(err));
我必须做一些错误,导致insert_text
方法不返回任何承诺。我收到以下错误:
.then(() => console.log("Inserted"))
^
TypeError: Cannot read property 'then' of undefined
...
尝试通用db.query(...)
会产生相同的问题。然而,在我的代码的其他部分(在类似的方法内),db.query("SELECT...
按预期工作。
就是这样,谢谢!我一直在试图调试一小时左右。 –