0

I want to get a list of a key inside my database I use db.set(`fuel_${car}`, amount of fuel) and then I want to get a list of all cars fuel, here is my code :

/*set the fuel of lol9*/
client.on('message', async message => {

if(message.content === 'db') {

  const m = await db.get('fuel');
  message.channel.send(`${m}`);
}
})

1 Answers1

0

The quick.db documentation states:

.all() -> array

This function returns the entire active table as an array.

await db.all()
// -> [Array]

This being said, you could do this:

let carFuelArray = [];
await db.all().then(array => {
   array.forEach(element, => {
      if(element.startWith("fuel_")) {
         // if you want to log "fuel_{car}"
         carFuelArray.push(element)
         // if you want to log the "fuel_{car}" key value
         carFuelArray.push(db.get(element))
      }
   })
})
loom
  • 50
  • 6