[英]Check if data is included in SQLite3 database with node.js
所以我想用node.js檢查數據庫中是否有某種文本數據
if(db.run("message.author.username IN (participations|name)")) {
db.run("INSERT INTO participations(name, info) VALUES (?, ?)", [message.author.username, message.content]);
message.author.send("Teilnahme bestätigt!");
} else {
message.author.send("Du nimmst schon teil!");
};
if()..
部分不起作用,沒有if()
其他所有部分也都起作用。 有沒有辦法正確使用它?
通常會進行數據庫調用……這意味着您需要提供一個回調函數,然后在此處檢查結果:
db.run("message.author.username IN (participations|name)", (err, rows) => {
if(rows.length > 0) {
console.log("we have data!");
db.run("INSERT INTO participations(name, info) VALUES (?, ?)", [message.author.username, message.content]);
} else {
console.log("no data!");
}
});
而且,您的“選擇”似乎不是有效的SQL,除非我不知道SQLite3框架有什么不可思議的地方。 通常,用於確定行是否存在的SQL的格式為:
SELECT * FROM <table.name> WHERE username IN (<your values>)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.