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
The active database provider instance.
Methods
initialize()
initialize()#
→Promise<void>Initializes the underlying database provider (e.g., opens the file connection or connects to the server).
Note: Called automatically by manager.init().
await manager.database.initialize();
get(key)
Retrieves a value from the database.
The key to retrieve.
const session = await manager.database.get("sessions.123");
set(key, value)
set(key, value)#
→Promise<void>Saves a value to the database.
The key to store.
The value to store.
await manager.database.set("config.volume", 50);
has(key)
Checks if a key exists in the database.
The key to check.
if (await manager.database.has("players.123")) {
console.log("Player data exists.");
}
remove(key)
remove(key)#
→Promise<boolean>Deletes a specific key from the database.
The key to remove.
await manager.database.remove("cache.temp");
keys(pattern)
keys(pattern)#
→Promise<string[]>Retrieves all keys, optionally matching a pattern.
Optional regex-like pattern.
const playerKeys = await manager.database.keys("players.*");
clear()
shutdown()
shutdown()#
→Promise<void>Gracefully closes the database connection.
await manager.database.shutdown();