#Obtain all unique keys with quick.db?

2 messages · Page 1 of 1 (latest)

viscid ravine
#

Hi, depending on your current quick.db version it may be different.
version 9.1.x added startsWith;

const charactersData = await db.startsWith("characters_");

if you are on an older version

const charactersData = (await db.all()).filter(e => e.id == "characters_");

That get all the elements with a key that starts with characters_ into an array

After that you will be able to write your logic to check what to update.
Both startsWith and all return the same objects which are

{
  id: "<key>",
  value: Mixed
}

both return an array of those objects where id is the key you used to set the data and value is the data you set/have in the database for that key.

With those you will be able to write the logic to check wither you have to update the object when going trough the array and you will be able to use the object's id property to update it using the set method

#

You're welcome, For now the docs are a bit plain,
the guide doesn't document everything and the auto-generated one doesn't have description.
Thought it is useful to know everything quick.db offers.
Here is where the startsWith function can be found on the auto-generated docs https://docs.plexidev.org/classes/QuickDB.html#startsWith