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...
按預期工作。
就是這樣,謝謝!我一直在試圖調試一小時左右。 –