我正在嘗試將數(shù)據(jù)發(fā)布到我的本地 sqlite 數(shù)據(jù)庫。數(shù)據(jù)在 POST 后出現(xiàn)在我的數(shù)據(jù)庫表中,但Promise.resolve()返回 as undefined,這又不會將結(jié)果返回給客戶端。我錯過了什么嗎?任何幫助,將不勝感激。這是我得到的。module.exports.addAccount = function (data) {const db_conn = new sqlite3.Database( path.join(__dirname, "../user_database.sql") )return new Promise( function (resolve, reject) { db_conn.serialize( function () { // insert row db_conn.run("INSERT INTO some_table (username) VALUES (?);", [data.username], function (err,rows) { if (!err) { console.log(rows) // always returns undefined resolve([rows, this.lastID]) } else { reject(err) } }) }) db_conn.close() })}然后:app.post("/add-row", function (req, res) {user_info.addAccount(req.body).then( function(response) { res.json({ rows: response[0], // this is undefined row_id: response[1] // this is not })}).catch(function () {})})
承諾解析未定義,但數(shù)據(jù)仍已發(fā)布
富國滬深
2022-12-18 16:17:23