djs-extended-data-provider-level is an implementation of a DataProvider for discord.js-extended made with a LevelDB backend.
You can visit the documentation site to see what this utility offers.
This package is designed to work for discord.js and @greencoast/discord.js-extended, this does not install any of these packages, you are expected to have these in your project.
You can install this package with:
npm install discord.js @greencoast/discord.js-extended @greencoast/djs-extended-data-provider-level
Assuming you have created your own ExtendedClient, you can attach this data provider into your client as such:
const { LevelDataProvider } = require('@greencoast/djs-extended-data-provider-level');
const client = new ExtendedClient();
client.once('ready', async () => {
await client.setDataProvider(new LevelDataProvider(client, 'database_location'));
});
And that's it! You can then access the data provider across your code through client.dataProvider
.
You can use the following methods anywhere:
await client.dataProvider.get(guild, 'key'); // Get a value for 'key' in guild.
await client.dataProvider.set(guild, 'key', 'value'); // Set 'value' for 'key' in guild.
await client.dataProvider.delete(guild, 'key'); // Delete a key-value pair for 'key' in guild.
await client.dataProvider.clear(guild); // Clear all data in a guild.
await client.dataProvider.getGlobal('key'); // Get a value for 'key' in the global scope.
await client.dataProvider.setGlobal('key', 'value'); // Set 'value' for 'key' in the global scope.
await client.dataProvider.deleteGlobal('key'); // Delete a key-value pair for 'key' in the global scope.
await client.dataProvider.clearGlobal(); // Clear all data in the global scope.
If you're using TypeScript, you should pass a generic type to the get
and delete
methods as such:
await client.dataProvider.get<string>(guild, 'key'); // Promise<string | undefined>
await client.dataProvider.get<string>(guild, 'key', 'default'); // Promise<string>
await client.dataProvider.delete<string>(guild, 'key'); // Promise<string | undefined>
You can run the unit tests for this package by:
git clone https://github.com/greencoast-studios/djs-extended-data-provider-level
npm install
npm test
This utility library was made by Greencoast Studios.
Generated using TypeDoc