从数据库中删除所有以相同键开头的数据"quick.db"

delete all the data that start with the same key from the database "quick.db"

大家好,我正在尝试删除所有以 modapp_${message.guild.id}

开头的数据

我尝试使用:

let money = db.all().filter(a => a.ID.startsWith(`modapp_${message.guild.id}`))
db.delete(money)

但它给我这个错误 SQLite3 can only bind numbers, strings, bigints, buffers, and null

谁能帮帮我

如果您查看 Quick.db Documentation You will see that .delete() accepts a key but .all() gives you an array of values, they do not mention the return type, after looking at the source code 结果发现您获得了具有 ID 和数据作为属性的对象,您可以映射 ID 并为它们中的每一个调用 delete

let money = db.all()
  .map(entry => entry.ID)
  .filter(id => id.startsWith(`modapp_${message.guild.id}`))

money.forEach(db.delete)

或者你可以使用 Array#reduce 只循环一次,提到这个作为替代方案,否则你会循环 3 次

let money = db.all().reduce((acc, val) => {
  if (val.ID.startsWith(`modapp_${message.guild.id}`)) {
    acc.push(val.ID)
  }

  return acc
}, [])