@ryanforever/local-database

1.2.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @ryanforever/local-database

Weekly Downloads

12

Version

1.2.1

License

ISC

Unpacked Size

12 kB

Total Files

9

Last publish

Collaborators

  • ryanforever