Sequelize查询回复为:,[object Object]
Sequelize query reply is: ,[object Object]
下面的函数可以正常工作,但没有更改就失效了
exports.updateFormState = async() => {
let queryReply;
try {
queryReply = await db.sequelize.query(
"SELECT * FROM Whosebug"
);
console.log("Im passed the reply")
console.log("This is the query: " + queryReply)
if (queryReply[1] === 1) {
console.log("Inside if statement")
return "SUCCESS";
}
}catch(err) {
return err.message;
}
}
它应该做什么
它需要触发对数据库的查询和 return 结果。
它的作用
它 returns ,[object 对象]
奇怪的是,它总是 return 编辑正确的东西,但现在不
有用的东西
查询有效(代码中未显示)
数据库连接在那里
它之前有效...
Sequelize 文档中的片段:
By default the function will return two arguments - a results array,
and an object containing metadata (such as amount of affected rows,
etc). Note that since this is a raw query, the metadata are dialect
specific. Some dialects return the metadata "within" the results
object (as properties on an array). However, two arguments will always
be returned, but for MSSQL and MySQL it will be two references to the
same object.
因此,这将稍微取决于您选择的基础数据库,但您很可能想要 return queryReply[0]
而不是 queryReply
.
此外,我注意到您正在这样做:
console.log("This is the query: " + queryReply)
这将尝试将 queryReply 呈现为字符串,但它不是,因为它是一个对象。相反,您可能会发现使用以下命令更容易调试:
console.log("This is the query: ", queryReply)
下面的函数可以正常工作,但没有更改就失效了
exports.updateFormState = async() => {
let queryReply;
try {
queryReply = await db.sequelize.query(
"SELECT * FROM Whosebug"
);
console.log("Im passed the reply")
console.log("This is the query: " + queryReply)
if (queryReply[1] === 1) {
console.log("Inside if statement")
return "SUCCESS";
}
}catch(err) {
return err.message;
}
}
它应该做什么
它需要触发对数据库的查询和 return 结果。
它的作用
它 returns ,[object 对象] 奇怪的是,它总是 return 编辑正确的东西,但现在不
有用的东西
查询有效(代码中未显示) 数据库连接在那里 它之前有效...
Sequelize 文档中的片段:
By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc). Note that since this is a raw query, the metadata are dialect specific. Some dialects return the metadata "within" the results object (as properties on an array). However, two arguments will always be returned, but for MSSQL and MySQL it will be two references to the same object.
因此,这将稍微取决于您选择的基础数据库,但您很可能想要 return queryReply[0]
而不是 queryReply
.
此外,我注意到您正在这样做:
console.log("This is the query: " + queryReply)
这将尝试将 queryReply 呈现为字符串,但它不是,因为它是一个对象。相反,您可能会发现使用以下命令更容易调试:
console.log("This is the query: ", queryReply)