Sagdb
Sagdb is JSON database system.
Installation
$ npm install sagdb
Usage
const Sagdb = require("sagdb").default;
import Sagdb from "sagdb";
-
Default database name is "db".
-
Db name and folder name is must be String.
-
Database folder name is optional.
-
If you want readable database, set "minify" to false.
const db = new Sagdb({ name: "database", folder: "foldername", minify: true });
const db = new Sagdb({ name: "database", folder: "folder/database" });
const db = new Sagdb({ name: "database" });
Method's
set
db.set("key", "apple");
Can't set Function.
function test() {}
db.set("key", test);
get
db.set("key", "apple");
db.get("key");
update
- Update get a callback function, give old data and return must be a same type old data.
db.update("key", (old_data) => {
const new_data = old_data.toUpperCase();
return new_data;
});
delete
- Delete any key from database.
db.set("key", "apple");
db.delete("key");
db.get("key");
add
db.set("number", 1);
db.get("number");
db.add("number", 3);
db.get("number");
db.add("number");
db.get("number");
db.add("number", "asd");
U can set object in object.
db.set("key.value", "apple");
db.get("key");
Table
import Sagdb, { Table } from "sagdb";
const db = new Sagdb({ name: "database" });
const table = new Table(db, "table_name");
add
table.add(1);
find
table.find(callback | data_object);
findById
table.findById("uuid");
update
table.update(callback | data_object, new_data, force?: boolean);
filter
table.filter(callback | data_object, new_data);
remove
table.update(callback, all?: boolean);
Listeneer's
On
table.on("event_name", callback());
Example
table.on("add", callback(new_data));
table.on("update", callback(old_data, new_data));
table.on("remove", callback(old_data));
License MIT