Skip to main content

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.

caution

This function can only be used with MongoDB databases.

Parameters​

ParameterTypeRequiredDescription
collectionstringβœ…The name of the collection to get.

Returns Collection - MongoDB Collection​


Database.createOne()​

caution

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​

ParameterTypeRequiredDescription
queryUserOptions 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​

ParameterTypeRequiredDescription
queryUserOptions LevelRoleOptionsβœ…The options for user or level role.

Database.deleteOne()​

Deletes a single document from the database.

Parameters​

ParameterTypeRequiredDescription
queryUserOptions 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​

ParameterTypeRequiredDescription
queryUserOptions 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​

ParameterTypeRequiredDescription
collectionsimply-xps
simply-xp-levelroles
βœ…The name of the collection to get.
guildstringβœ…The guild ID.

Returns Promise< UserResult[] | LevelRoleResult[] > - User or Level Role​


Database.findAll()​

Finds all documents from the database.

Parameters​

ParameterTypeRequiredDescription
collectionsimply-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​

ParameterTypeRequiredDescription
filterUserOptions LevelRoleOptionsβœ…The options for user or level role.
updateUserOptions LevelRoleOptionsβœ…The update to apply to the document.
optionsUpdateOneOptions❌The options for the update. (MONGODB)

Returns Promise<UserResult | LevelRoleResult> - User or Level Role​