UNPKG

83db

Version:

Entirely encrypted and GZip compressed JSON Database

84 lines (62 loc) 1.97 kB
# Getting Started 83db is a CURD, GZip compressed, JSON database with optional AES-256-CBC encryption ### Simple DB: <br> First, create a new JS file for your database, For this example I will make a file named `users.js` and a database file named `users.db` ```js const Database = require("83db"); module.exports.UserDB = new Database('./users.db', { dir: __dirname // This is needed for local paths }) ``` ### Encrypted DB: <br> Same steps as before, but add the `decryptionKey` option. ```js const Database = require("83db"); module.exports.UserDB = new Database('./users.db', { dir: __dirname, // This is needed for local paths decryptionKey: "256 bit ( 16 hex characters ) decryption key, store in env" }) ``` ### Functions <br> `get(key: string)` - Gets the value in a DB with the key, `key` - Returns the key's value `set(key: string, value: any)` - Sets a key's value, or creates it if it doesnt exist. - Returns `Database` `delete(key: string)` - Deletes the value with the key, `key` - Returns `Database` `list(prefix: string?)` - List all keys with an optional prefix - Returns `string[]` `empty()` - Empties the entire database - Returns `Database` `exists(key: string)` - Checks if a key, `key` exists - Returns `Boolean` `write(encryptionKey : string?)` - Writes all data to the file, you can override the encryption key with the optional `encryptionKey` parameter - Returns `Database` `getAll()` - Returns an object with all the keys and values like `{ key: value ... }` - Returns `object` `setAll(obj : object?)` - Sets the database's JSON to a specified object `obj` - Returns `Database` ### Examples <br> Creates a key named "John" and has a value of `{ lastName: "Doe" }` ```js const Database = require("83db"); const users = new Database('./users.db', { dir: __dirname }); users.set("John", { lastName: "Doe" }).write(); ```