0.0.3 • Published 6 years ago

rethinkprovider v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

RethinkProvider

A Settings provider using RethinkDB. Made for Discord.js and related command frameworks.

Initialization

Note: RethinkProvider assumes the Primary Index of each table in the database is "id" when loading the settings to memory.

Note: RethinkProvider does not create the the database and tables in order to allow for more customizable structures.

const RethinkProvider = require("rethinkprovider");

//The values for these settings are the default values.
let provider = new RethinkProvider({
  db: "bot", //Name of the database to load.
  tables: ["guilds"], //Names of the databases to load.
  index: "settings", //Name of index to save the settings object to.
  host: "127.0.0.1", //IP Address of the RethinkDB server.
  port: 28015, // Port of the RethinkDB server.
  user: "admin", //Username of the user to login as.
  password: "" //Password of the user to login as.
});

provider.init();

Methods

init() => Promise<void>

Verifies that the database and tables provided exist, then proceeds to load the data into memory using a Map.

Params: None

Example:

const RethinkProvider = require("rethinkprovider");
let provider = new RethinkProvider();
provider.init();

get(table, <id, <key, [def]>>) => any

Gets a value from the settings object based on the table, id and key in the settings object. Returns whatever value is set to the key specified or the default value if the key value is not found..

Params:

  • table - The name of the table to get the value from.
  • id - The ID of the document to retreive settings from.
  • key - The key in the settings object to return the value from.
  • def - The value to default to if the value of the key is not found.

Example:

provider.get("guilds", "12345", "prefix", "?");

set(table, <id, <key, <value>>>) => Promise<void>

Sets a key in the settings object to the value specified.

Params:

  • table - The name of the table to get the value from.
  • id - The ID of the document to retreive settings from.
  • key - The key in the settings object to set the value to.
  • value - The value to set as the value of the key.

Example:

provider.set("guilds", "12345", "prefix", "%%");

remove(table, <id, <key>>) => Promise<void>

Removes a key in the settings object.

Params:

  • table - The name of the table to get the value from.
  • id - The ID of the document to retreive settings from.
  • key - The key in the settings object to remove.

Example:

provider.remove("guilds", "12345", "prefix");

clear(table, <id>) => Promise<void>

Clears the settings of a document, setting them back to {}.

Params:

  • table - The name of the table to get the value from.
  • id - The ID of the document to retreive settings from.

Example:

provider.clear("guilds", "12345");

destroy() => void

Destroys the connection to the database.

Params: None

Example:

provider.destroy();

License

This project is licensed under the MIT License - see the LICENSE.md file for details

0.0.3

6 years ago

0.0.2

6 years ago