JavaScript Sqlite-在var中存储单个结果的简单方法

时间:2018-11-17 00:09:49

标签: javascript sqlite

我一直试图将单行结果(在本例中为ID)存储在变量中,以便可以在其他地方使用。我有以下内容,但没有通过。

    var muteid =
con.each("SELECT max(id) as id from full_track", function(err, row) {
  console.log(row.id);
});

const logembed = new discord.RichEmbed()
//.setTitle("User Muted")
  .setAuthor(message.author.username, message.author.avatarURL)
  .setDescription(`${tomute.user.tag} has been muted for ${ms(ms(mutedtime))}`)
  .addField(`**Reason:** ${mutedreason}`, `aa`)
  .setFooter(`ID: ${muteid}`)
  .setTimestamp()
  .setColor(3447003)

1 个答案:

答案 0 :(得分:0)

只需将代码放入您放置控制台的con.each处理程序中即可。

var muteid, logembed = [];

con.each("SELECT max(id) as id from full_track", function(err, row) {
  console.log(row.id);
  muteid = row.id;

  logembed[muteid] = new discord.RichEmbed()
  //.setTitle("User Muted")
    .setAuthor(message.author.username, message.author.avatarURL)
    .setDescription(`${tomute.user.tag} has been muted for ${ms(ms(mutedtime))}`)
    .addField(`**Reason:** ${mutedreason}`, `aa`)
    .setFooter(`ID: ${muteid}`)
    .setTimestamp()
    .setColor(3447003);
});