0
if (command == "tgive") {
      //Get their current balance
    const grab = sql.prepare(`SELECT bal FROM ${args[1]}`).get();
    //Grab the value from the first input after the second. Ex: eco tgive 5 Juliana
    const pointsToAdd = parseInt(args[0]);
    //Add the two values from the database and the args[0] input
    const result = +grab.bal + +pointsToAdd;
    //Replace the curret value from column bal in table ${args[1]}, with the const result
    sql.prepare(`REPLACE INTO ${args[1]} (bal) VALUES ('${result}');`).run();
    message.channel.send(`You have ${grab.bal}`);

}
});

在数据库“Juliana”中,列的值bal4205You have 420You have 425const result

4

1 回答 1

0
const grab = sql.prepare(`SELECT bal FROM ${args[1]}`).get();

当这行代码运行时,它从数据库中检索值并复制它。这意味着当数据库更新时, 的值grab不会。

如果您想获得新的余额,那么您需要再次查询数据库。

于 2020-01-17T16:34:37.157 回答