@ryanforever/local-database
v1.2.1
Published
a simple JSON database tool.
Downloads
7
Readme
local-database
a simple database tool for storing data locally. based on data-store & redis
quickstart
by default, local-database will use json
for data storage.
const LocalDatabase = require("@surfingpikachu/local-database")
const db = new LocalDatabase("./database.json")
db.set("hello", "world")
db.get("hello")
// world
using redis
the redis
database uses redis as client, and will store data in memory. all commands are async
please make sure you have redis installed, you can find instructions here
const RedisDatabase = require("@surfingpikachu/local-database").redis
const db = new RedisDatabase()
// all commands are async
db.start().then(() => {
db.set("key1", "hello world")
db.get("key1").then(console.log)
// hello world
})
redis
commands
.set(key, value)
- set a key to given value.push(key, value)
- adds an element to an array.add(key, value)
- adds only unique elements to an array/set.get(key)
- get value at key.clear()
- clear the entire database
using json
the json
database will create a local database using a JSON file in a directory of your choosing.
const JsonDatabase = require("@surfingpikachu/local-database").json
const db = new JsonDatabase("./database.json")
db.set("key1", "hello world")
db.get("key1")
// hello world
json
commands
.set(key, value)
- set a key to given value.add(key, value)
- adds only unique elements to an array/set.get(key)
- get value at key.clear()
- clear the entire database