xenkysdb

A simple JSON database in a npm package.

Usage no npm install needed!

<script type="module">
  import xenkysdb from 'https://cdn.skypack.dev/xenkysdb';
</script>

README

xenkysdb

A simple JSON database in a npm package.

Installation

npm i xenkysdb

Setup

const Database = require("xenkysdb")
const db = new Database()

All Methods

set(key, value)

Set a key and a value.

get(key)

Get a key with its values.

has(key)

Check if has the key.

all()

Get all the keys with them values.

delete(key)

Delete the key with its values.

clear()

Delete all keys with them values.

push(key, element)

Add an element to the key.

unpush(key, element)

Remove an element from the key.

add(key, number)

Add a number to the key.

remove(key, number)

Remove a number from the key.

Examples

const Database = require("xenkysdb")
const db = new Database(
    "storage" // The optional name of the json file, the default name is storage
    "." // The optional separator to switch between keys, the default separator is .
)

db.set("a.b.c", "value") // { "a": { "b": { "c": "value" }}}
db.get("a") // { "b": { "c": "value" }}
db.has("a.b.c") // true
db.all() // { "a": { "b": { "c": "value" }}}
db.delete("a.b.c") // { "a": { "b": {}}}
db.clear() // {}
db.push("a.b", "element") // { "a": { "b": ["element"] }}
db.unpush("a.b", "element") // { "a": { "b": [] }}
db.add("a.c", 4) // { "a": { "b": [] }, { "c": 4 }}
db.remove("a.c", 2) // { "a": { "b": [] }, { "c": 2 }}