1.2.1 • Published 8 months ago

@ryanforever/local-database v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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
1.2.1

8 months ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.11

2 years ago