当您尝试使用.prepare(#).get()而查询不存在时,我该如何处理发生的错误?
let businessType = DB.prepare(`SELECT businessType from 'Profiles' WHERE userId = '${author.id}'`).get().businessType;所以基本上,当"businessType“不存在时,我如何停止崩溃,而不是脚本崩溃,我只需要发送像”用户不存在“之类的消息就可以了。
提前感谢!
发布于 2021-10-11 08:30:45
如果该行不存在,get()将返回undefined。
在尝试提取数据之前,您需要检查您的响应。
const row = DB.prepare(`SELECT businessType from 'Profiles' WHERE userId = ?`).get(author.id);
if(row) {
// profile recorded exist
...
} else {
// profile doesn't exist.
...
}https://stackoverflow.com/questions/69521151
复制相似问题