@greencoast/djs-extended-data-provider-level
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

ci-build-status issues bundle-size node-version version djs-extended-version downloads-week downloads-total

Discord.js - Extended / Level Data Provider

djs-extended-data-provider-level is an implementation of a DataProvider for discord.js-extended made with a LevelDB backend.

Usage

You can visit the documentation site to see what this utility offers.

Installation

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

Adding the Data Provider to your Client

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.

Using Data Provider

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>

Testing

You can run the unit tests for this package by:

  1. Cloning the repo:
git clone https://github.com/greencoast-studios/djs-extended-data-provider-level
  1. Installing the dependencies.
npm install
  1. Running the tests.
npm test

Authors

This utility library was made by Greencoast Studios.

Package Sidebar

Install

npm i @greencoast/djs-extended-data-provider-level

Weekly Downloads

11

Version

1.0.1

License

MIT

Unpacked Size

28.8 kB

Total Files

12

Last publish

Collaborators

  • moonstar-x