Database
This class provides methods to interact with the database. It supports both MongoDB and SQLite backends and
offers operations for creating, updating, deleting, and querying user and level-role documents. Methods set
createdAt and lastUpdated timestamps when creating or updating records.
Methodsβ
Database.getCollection()β
Returns a collection from the database.
This function can only be used with MongoDB databases.
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| collection | string | β | The name of the collection to get. |
Returns Collection - MongoDB Collectionβ
Database.createOne()β
ALL query properties are required here.
Creates a new document in the database. The method automatically adds createdAt and lastUpdated ISO
timestamps. Many fields in the data object are optional (for example name, user, level, xp, and
flags for simply-xps). The method supports both MongoDB and SQLite backends.
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| query | UserOptions LevelRoleOptions | β | The options for user or level role. |
Returns Promise<UserResult | LevelRoleResult> - User or Level Roleβ
Database.deleteMany()β
Deletes multiple documents from the database. Returns true when the underlying driver reports a result
object (for SQLite the run() result is treated as truthy when successful).
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| query | UserOptions LevelRoleOptions | β | The options for user or level role. |
Database.deleteOne()β
Deletes a single document from the database.
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| query | UserOptions LevelRoleOptions | β | The options for user or level role. |
Returns Promise<boolean> - true if a document was deleted, otherwise falseβ
Database.findOne()β
Finds a document from the database.
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| query | UserOptions LevelRoleOptions | β | The options for user or level role. |
Returns Promise<UserResult | LevelRoleResult> - User or Level Roleβ
Database.find()β
Finds documents from the database for a given guild. For SQLite simply-xps rows will have the flags
column parsed from JSON back into an array. The collection parameter must be either simply-xps or
simply-xp-levelroles.
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| collection | simply-xps simply-xp-levelroles | β | The name of the collection to get. |
| guild | string | β | The guild ID. |
Returns Promise< UserResult[] | LevelRoleResult[] > - User or Level Roleβ
Database.findAll()β
Finds all documents from the database.
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| collection | simply-xps simply-xp-levelroles | β | The name of the collection to get. |
Returns Promise< UserResult[] | LevelRoleResult[] > - User or Level Roleβ
Database.updateOne()β
Updates a document in the database.
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| filter | UserOptions LevelRoleOptions | β | The options for user or level role. |
| update | UserOptions LevelRoleOptions | β | The update to apply to the document. |
| options | UpdateOneOptions | β | The options for the update. (MONGODB) |