1.0.0 • Published 2 years ago
light-json-database v1.0.0
Installation
npm install light-json-database
Introduction
This is very simple and extremely light database for server side NodeJS applications. It stores the data in json file generated in the current working directory.
Example
- Creating a database
const { JsonDatabase } = require("simple-json-database");
const db = new JsonDatabase("example"); // example is database name
console.log(db.getAll()); // output: {}
- Inserting data in database
const { JsonDatabase } = require("simple-json-database");
const db = new JsonDatabase("example"); // example is database name
db.set("name", "Jon Doe"); // db.set(key, value)
console.log(db.get("name")); // output: "Jon Doe"
console.log(db.getAll()); // output: { name: "Jon Doe" }
- Updating data in database
const { JsonDatabase } = require("simple-json-database");
const db = new JsonDatabase("example"); // example is database name
db.set("name", "Jon Doe"); // db.set(key, value)
console.log(db.get("name")); // output: "Jon Doe"
db.set("name", "Another name"); // updating value of key "name"
console.log(db.get("name")); // output: "Another name"
- Deleting data from database
const { JsonDatabase } = require("simple-json-database");
const db = new JsonDatabase("example"); // example is database name
db.set("name", "Jon Doe"); // db.set(key, value)
console.log(db.getAll()); // output: { name: "Jon Doe" }
db.remove("name"); // removing data of key "name"
console.log(db.get("name")); // output: {}
- All methods
db.get(key); // return value assigned for given key
db.getAll(); // return all the data in the database
db.set(key, value); // set the value for given key
// also can be used for updating value any key that already exists in database then it will overwrite/update it.
db.setAll(data); // set/overwrite all data of database
db.remove(key); // delete the data with given key
db.removeAll(); // delete all the data in the database
1.0.0
2 years ago