Star ✨ on GitHub

DatabaseManager

Handles the internal data persistence for queues, sessions, and player states. Supports both 'memory' and 'local' (file-based) storage.

The DatabaseManager is responsible for abstracting the storage layer. Moonlink.js uses this to persist player queues and session data, allowing for features like auto-resume even after a bot restart (if using the local provider).

Properties

Database Properties

Internal state of the database manager.

Configuration

providerMemory | Local

The active database provider instance.

Methods

initialize()

initialize()#

Initializes the underlying database provider (e.g., opens the file connection or connects to the server). Note: Called automatically by manager.init().

Example
await manager.database.initialize();

get(key)

get(key)#

Retrieves a value from the database.

keystring required

The key to retrieve.

Example
const session = await manager.database.get("sessions.123");

set(key, value)

set(key, value)#

Saves a value to the database.

keystring required

The key to store.

valueany required

The value to store.

Example
await manager.database.set("config.volume", 50);

has(key)

has(key)#

Checks if a key exists in the database.

keystring required

The key to check.

Example
if (await manager.database.has("players.123")) {
    console.log("Player data exists.");
}

remove(key)

remove(key)#

Deletes a specific key from the database.

keystring required

The key to remove.

Example
await manager.database.remove("cache.temp");

keys(pattern)

keys(pattern)#

Retrieves all keys, optionally matching a pattern.

patternstring

Optional regex-like pattern.

Example
const playerKeys = await manager.database.keys("players.*");

clear()

clear()#

Wipes all data from the database.

Example
await manager.database.clear();

shutdown()

shutdown()#

Gracefully closes the database connection.

Example
await manager.database.shutdown();