1.0.2 • Published 2 years ago

oj-kvdb v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

KVDB (Key Value Database)

A simple nodejs database solution. Data stays in memory for fast access and stays synced with a JSON file for persistency.

constructor

constructor<T>(location?: string, syncThreshold: number = 200): KVDB<T>

The location points to a JSON file. It will create the file if it doesn't exist. The syncThreshold is the debounce threshold that the persistent JSON file gets written to. Pass a 0 to disable debouncing and write directly after each database edit.

const db = new KVDB<string>("D:/projectData/data.json", 0)

set

set(key: string, value: T): string

set("myKey", "my data") // "myKey"
set("otherKey", "some other data") // "otherKey"

get

get(key: string): T

get("myKey") // "my data"
get("otherKey") // "some other data"

has

has(key: string): boolean

has("myKey") // true
has("bar") // false

getAll

getAll(): [string, string][]

getAll() // [["myKey", "my data"], ["otherKey", "some other data"]]