繁体   English   中英

使用node.js检查数据是否包含在SQLite3数据库中

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM