javascript - 如何使用 JS、Node.JS 和 Discord.JS 在 SQLITE 数据库中获取多行?

标签 javascript node.js sqlite sequelize.js discord.js

我遇到了关于使用 Sequelize 和 Sqlite 为我的 Discord 机器人创建数据库的问题。

我的表由带有列的行组成:“用户名”、“描述”、“键”、“名称”和“显示名称”。
我想获得多行,例如我的表中有一些用户。

我没有找到任何用于获取特定表的行数的特定函数,因此我决定使用数组,在其中推送每个“显示名称”属性。
这并没有带我去任何地方,而不是使用 array.length() 时数组元素的数量,代码输出“对象未定义”值。

这是代码:

else if (cmd === `${prefix}alist`) {
  // equivalent to: SELECT name FROM tags;
  const notdone = [];
  const done = [];
  var s;
  const tagList = await Tags.findAll({
    attributes: ['displayname']
  });
  const tagListDone = await TagsDone.findAll({
    attributes: ['displaynamedone']
  });
  notdone.push(tagList.map(t => t.displayname));
  done.push(tagListDone.map(t => t.displaynamedone));
  const notdonestring = notdone.join(' ');
  const donestring = done.join(' ');
  s = Math.round(done.length / (notdone.length + done.length));
  message.reply(toString(done.length) + ' ' + toString(notdone.length));
  return message.channel.send(`Список заданий: \n` + notdonestring + `\n \nСписок выполненных: \n` + donestring + '\n \nНаш прогресс: ' + toString(s) + '%');
}


这是代码输出:
Code output

最佳答案

如果您希望获得多行,只需使用 count 而不是 findAll :

 const tagCount = await Tags.count();

关于javascript - 如何使用 JS、Node.JS 和 Discord.JS 在 SQLITE 数据库中获取多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62202313/

相关文章:

javascript - 如何在 HTML 中使我的列动态化

node.js - 为什么我本应失败的超测却通过了?

android - SQLite 数据库副本在由设备而不是模拟器生成时出现损坏

sql - sqlite:使用复合选择查询其他列

linux - 从单 Node 过渡到多 Node hadoop same

database - 将照片与应用程序 : files or in sqlite database? bundle 在一起的最佳方式

javascript - 为什么 JavaScript getTime() 不是一个函数?

javascript - <p :calendar> highlight specific dates (values from bean)

javascript - meteor :如何按关注最多的用户排序?

node.js - NPM:没有那个文件或目录