> For the complete documentation index, see [llms.txt](https://plexidev.gitbook.io/quickdb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://plexidev.gitbook.io/quickdb/overview/docs.md).

# Documentation

## Methods

## **.table(*****name*****)** <a href="#table" id="table"></a>

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

```javascript
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 <a href="#add-method" id="add-method"></a>

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

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

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

*Also allows for accessing properties using dot notation*

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

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

## **.all() -> array** <a href="#all-method" id="all-method"></a>

This function returns the entire active table as an array.

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

## **.delete(*****key*****) -> boolean** <a href="#delete" id="delete"></a>

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

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

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

*Also allows for accessing properties using dot notation*

```javascript
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

```javascript
await db.deleteAll() // Removes every thing
```

## **.get(*****key*****) -> row** <a href="#get" id="get"></a>

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

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

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

*Also allows for accessing properties using dot notation*

```javascript
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** <a href="#has" id="has"></a>

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

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

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

*Also allows for accessing properties using dot notation*

```javascript
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*****,&#x20;*****element*****) -> updatedRow** <a href="#push" id="push"></a>

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

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

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

*Also allows for accessing properties using dot notation*

```javascript
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

```javascript
// 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*****,&#x20;*****data*****) -> updatedRow** <a href="#set-method" id="set-method"></a>

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)

```javascript
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*

```javascript
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*****,&#x20;*****number*****) -> updatedRow** <a href="#subtract" id="subtract"></a>

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

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

*Also allows for accessing properties using dot notation*

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