Methods
.table( name )
This function creates a new table, allowing you to separate your data while being used exactly the same.
Copy 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)
Copy await db .get ( 'myBalance' )
// -> 500
await db .add ( 'myBalance' , 250 )
// -> 750
Also allows for accessing properties using dot notation
Copy 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.
Copy await db .all ()
// -> [Array]
.delete( key ) -> boolean
This function deletes the specified key. Returns if it was a success or not.
Copy await db .get ( 'myData' )
// -> "Hello World!"
await db .delete ( 'myData' )
// true
Also allows for accessing properties using dot notation
Copy 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
Copy await db .deleteAll () // Removes every thing
.get( key ) -> row
This function returns data from a row based on the key. Alias: .fetch()
Copy await db .set ( 'myData' , 'Hello World!' )
// -> 'Hello World!'
await db .get ( 'myData' )
// -> 'Hello World!'
Also allows for accessing properties using dot notation
Copy 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()
Copy await db .set ( 'myData' , 'Hello World!' )
// -> 'Hello World!'
await db .has ( 'myData' ) // -> true
Also allows for accessing properties using dot notation
Copy 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)
Copy await db .set ( 'myItems' , [ 'Sword' , 'Lock' ])
// -> ['Sword', 'Lock']
await db .push ( 'myItems' , 'Dagger' )
// -> ['Sword', 'Lock', 'Dagger']
Also allows for accessing properties using dot notation
Copy 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
Copy // 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)
Copy 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
Copy 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)
Copy await db .get ( 'myBalance' ) // -> 500
await db .sub ( 'myBalance' , 200 ) // -> 300
Also allows for accessing properties using dot notation
Copy await db .get ( 'myUser' , { league : 'Gold' , XP : 500 }) // -> { league: 'Gold', XP: 500 }
await db .sub ( 'myUser.XP' , 200 ) // -> { league: 'Gold', XP: 300 }