quick.db
  • 🎉Introduction
  • Overview
    • 📝Changelog
    • 💻Migration Guide
    • 📚Documentation
    • 📈More Information
    • Quick.db 9.0.0 pre-release upgrade to NPM
Powered by GitBook
On this page
  • Methods
  • .table(name)
  • .add(key, number) -> updatedRow
  • .all() -> array
  • .delete(key) -> boolean
  • .deleteAll() -> number
  • .get(key) -> row
  • .has(key) -> boolean
  • .push(key, element) -> updatedRow
  • .pull(key, [value|array|function]) -> updatedRow
  • .set(key, data) -> updatedRow
  • .sub(key, number) -> updatedRow
  1. Overview

Documentation

Methods

.table(name)

This function creates a new table, allowing you to separate your data while being used exactly the same.

const economy = db.table('economy')
await economy.set('myBalance', 500) // -> 500
await economy.get('myBalance') // -> 500
await db.get('myBalance') // -> null

.add(key, number) -> updatedRow

This function adds a number to a key in the database. (If no existing number, it will add to 0)

await db.get('myBalance')
// -> 500

await db.add('myBalance', 250)
// -> 750

Also allows for accessing properties using dot notation

await db.get('myUser')
// -> { guild: null, balance: 500 }

await db.add('myUser.balance', 250)
// -> { guild: null, balance: 750 }

.all() -> array

This function returns the entire active table as an array.

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

.delete(key) -> boolean

This function deletes the specified key. Returns if it was a success or not.

await db.get('myData')
// -> "Hello World!"

await db.delete('myData')
// true

Also allows for accessing properties using dot notation

await db.get('myUser')
// -> { guild: null, balance: 500 }

await db.delete('myUser.balance')
// -> true

await db.get('myUser')
// -> { guild: null }

.deleteAll() -> number

This function delete all there is in the database (or the table) It returns the numbers of rows deleted

await db.deleteAll() // Removes every thing

.get(key) -> row

This function returns data from a row based on the key. Alias: .fetch()

await db.set('myData', 'Hello World!')
// -> 'Hello World!'

await db.get('myData')
// -> 'Hello World!'

Also allows for accessing properties using dot notation

await db.set('myUser', { guild: 'Plexi', balance: 500 })
// -> { guild: 'Plexi', balance: 500 }

await db.get('myUser.guild') // -> "Plexi"
await db.get('myUser.balance') // -> 500
await db.get('myUser.notAProp') // -> undefined

.has(key) -> boolean

This function returns a boolean based on whether an element or property exists. Alias: .exists()

await db.set('myData', 'Hello World!')
// -> 'Hello World!'

await db.has('myData') // -> true

Also allows for accessing properties using dot notation

await db.set('myUser', { guild: 'Plexi', balance: 500 })
// -> { guild: 'Plexi', balance: 500 }

await db.has('myUser.guild') // -> true
await db.has('myUser.items') // false

.push(key, element) -> updatedRow

This function will push into an array in the database based on the key. (If no existing array, it will create one)

await db.set('myItems', ['Sword', 'Lock'])
// -> ['Sword', 'Lock']

await db.push('myItems', 'Dagger')
// -> ['Sword', 'Lock', 'Dagger']

Also allows for accessing properties using dot notation

await db.set('myUser', { balance: 500, items: ['Watch', 'Sword'] })
// -> { balance: 500, items: ['Watch', 'Sword'] }

await db.push('myUser.items', 'Dagger')
// -> { balance: 500, items: ['Watch', 'Sword', 'Dagger'] }

.pull(key, [value|array|function]) -> updatedRow

This function removes a value from an array (reverse operation from push). The second parameter can be a simple value, an array or a function. When used with a function, it will only remove the value when the function returns true

// Example data in the database
await db.set("myArray", ["test", "other test", "third test", "$special test"]);

// Single value example (removing test)
await db.pull("myArray", "test"); // -> ["other test", "third test", "$special test"]

// Array example (remove other test and third test)
await db.pull("myArray", ["other test", "third test"]); // -> ["$special test"]

// Function example (removing items that starts with $)
// First parameter is the item in the array
// The function is executed for each item
await db.pull("myArray", (item) => item.startsWith("$")); // -> []

.set(key, data) -> updatedRow

This function sets new data based on a key in the database. (When using dot notation, if the object doesn't exist it'll create one)

await db.set('myData', 'Hello World!') // -> 'Hello World!'
await db.set('myData', 50) // -> 50
await db.set('myData', { foo: 'bar' }) // -> { foo: 'bar' }

Also allows for accessing properties using dot notation

await db.get('myUser') // -> null

await db.set('myUser.guild.rank', 'Mage') 
// -> { guild: { rank: 'Mage' } }

await db.set('myUser.balance', 500) 
// -> { guild: { rank: 'Mage' }, balance: 500 }

await db.set('myUser.guild.rank', 'Warrior') 
// -> { guild: { rank: 'Warrior' }, balance: 500 }

.sub(key, number) -> updatedRow

This function subtracts a number to a key in the database. (If no existing number, it will subtract from 0)

await db.get('myBalance') // -> 500
await db.sub('myBalance', 200) // -> 300

Also allows for accessing properties using dot notation

await db.get('myUser', { league: 'Gold', XP: 500 }) // -> { league: 'Gold', XP: 500 }
await db.sub('myUser.XP', 200) // -> { league: 'Gold', XP: 300 }
PreviousMigration GuideNextMore Information

Last updated 3 years ago

📚