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...
が期待どおりに動作します。
これは、ありがとう!私は1時間デバッグしようとしています。 –