Documentation

Methods

new .table(name)

This function creates a new table, allowing you to separate your data while being used exactly the same.
1
var economy = new db.table('economy')
2
economy.set('myBalance', 500) // -> 500
3
economy.get('myBalance') // -> 500
4
db.get('myBalance') // -> null
Copied!

.add(key, number, [options]) -> updatedRow

This function adds a number to a key in the database. (If no existing number, it will add to 0)
1
db.get('myBalance')
2
// -> 500
3
4
db.add('myBalance', 250)
5
// -> 750
Copied!
Also allows for accessing properties using dot notation
1
db.get('myUser')
2
// -> { guild: null, balance: 500 }
3
4
db.add('myUser.balance', 250)
5
// -> { guild: null, balance: 750 }
Copied!

.all() -> array

This function returns the entire active table as an array.
1
db.all()
2
// -> [Array]
Copied!

.delete(key, [options]) -> boolean

This function deletes the specified key. Returns if it was a success or not.
1
db.get('myData')
2
// -> "Hello World!"
3
4
db.delete('myData')
5
// true
Copied!
Also allows for accessing properties using dot notation
1
db.get('myUser')
2
// -> { guild: null, balance: 500 }
3
4
db.delete('myUser.balance')
5
// -> true
6
7
db.get('myUser')
8
// -> { guild: null }
Copied!

.get(key, [options]) -> row

This function returns data from a row based on the key. Alias: .fetch()
1
db.set('myData', 'Hello World!')
2
// -> 'Hello World!'
3
4
db.get('myData')
5
// -> 'Hello World!'
Copied!
Also allows for accessing properties using dot notation
1
db.set('myUser', { guild: 'Plexi', balance: 500 })
2
// -> { guild: 'Plexi', balance: 500 }
3
4
db.get('myUser.guild') // -> "Plexi"
5
db.get('myUser.balance') // -> 500
6
db.get('myUser.notAProp') // -> undefined
Copied!

.has(key, [options]) -> boolean

This function returns a boolean based on whether an element or property exists. Alias: .exists()
1
db.set('myData', 'Hello World!')
2
// -> 'Hello World!'
3
4
db.has('myData') // -> true
Copied!
Also allows for accessing properties using dot notation
1
db.set('myUser', { guild: 'Plexi', balance: 500 })
2
// -> { guild: 'Plexi', balance: 500 }
3
4
db.has('myUser.guild') // -> true
5
db.has('myUser.items') // false
Copied!

.push(key, element, [options]) -> updatedRow

This function will push into an array in the database based on the key. (If no existing array, it will create one)
1
db.set('myItems', ['Sword', 'Lock'])
2
// -> ['Sword', 'Lock']
3
4
db.push('myItems', 'Dagger')
5
// -> ['Sword', 'Lock', 'Dagger']
Copied!
Also allows for accessing properties using dot notation
1
db.set('myUser', { balance: 500, items: ['Watch', 'Sword'] })
2
// -> { balance: 500, items: ['Watch', 'Sword'] }
3
4
db.push('myUser.items', 'Dagger')
5
// -> { balance: 500, items: ['Watch', 'Sword', 'Dagger'] }
Copied!

.set(key, data, [options]) -> 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)
1
db.set('myData', 'Hello World!') // -> 'Hello World!'
2
db.set('myData', 50) // -> 50
3
db.set('myData', { foo: 'bar' }) // -> { foo: 'bar' }
Copied!
Also allows for accessing properties using dot notation
1
db.get('myUser') // -> null
2
3
db.set('myUser.guild.rank', 'Mage')
4
// -> { guild: { rank: 'Mage' } }
5
6
db.set('myUser.balance', 500)
7
// -> { guild: { rank: 'Mage' }, balance: 500 }
8
9
db.set('myUser.guild.rank', 'Warrior')
10
// -> { guild: { rank: 'Warrior' }, balance: 500 }
Copied!

.subtract(key, number, [option]) -> updatedRow

This function subtracts a number to a key in the database. (If no existing number, it will subtract from 0)
1
db.get('myBalance') // -> 500
2
db.subtract('myBalance', 200) // -> 300
Copied!
Also allows for accessing properties using dot notation
1
db.get('myUser', { league: 'Gold', XP: 500 }) // -> { league: 'Gold', XP: 500 }
2
db.subtract('myUser.XP', 200) // -> { league: 'Gold', XP: 300 }
Copied!
Last modified 1yr ago