ghostchat-database
A simple, reliable, NoSQL database.
Documentation
Classes
Database
Methods
public get(key: string): Promise - Gets the value of the specified key from the database.
public write(key: string,value: any): Promise - Creates a new key.
public update(key: string,value: any): Promise - Updates the value of a key.
public delete(key: string): Promise - Deletes the key from the database.
public list(): Promise - Returns a list of keys in the database.
public empty(): Promise - Clears the database.
DBValue
Properties
public success: boolean - Whether the interaction was successful or not.
public value?: any - The value returned from the interaction.
DBError
extends Error
Properties
public message: string - The error message.
public errorCode: string - The error code returned from the database.
Guide
This is the guide to using the ghostchat-database module.
First import it using esm import statement
import Database from "ghostchat-database";
Then, create a new instance of the database.
const db = new Database();
Now, lets get a key from the database. We do this with the get function.
db.get("foo")
.then(({success,value}) => {
if(!success) console.error(value.message);
else console.log(value);
});
If the interaction is not successful, value will be an instance of DBError
, if the interaction is a success then value will either be undefined or the data returned from the database (get and list functions).
Now lets write a key
db.write("foo","bar")
.then(({succes,value}) => {
if(!success) console.error(value.message);
else console.log(success);
});
If we want to update a key its the same code, just a different function.
db.update("foo","bar")
.then(({succes,value}) => {
if(!success) console.error(value.message);
else console.log(success);
});
The write function will error if there is already a key named whats specified.
The update function will error if there is no key that matches with the one specified.