electron-jsondb
v0.1.1
Published
JSON based database for electron
Maintainers
Readme
ELECTRON-JSONDB
electron-jsondb is a database module for using in electron and persist data in JSON format in .db file extension.
Installing
npm install electron-jsondb
Using
const Database = require("electron-jsondb");
const mode = "DEVELOPMENT" || "PRODUCTION";
const db = new Database("mydb", mode);
// Additing some data, key must be string, and the value a valid json value, key can't be 'save', 'delete' or 'deleteAll'
db.set("key", "value")
.then(data => console.log("it's Done"))
.catch(err => console.log("something went wrong"));
// Getting a data
db.get("key")
.then(async returned => {
// the data is inside data key
console.log(returned.data);
// modify and update, save function will save alteration in db, but is async function
returned.data = 955;
await returned.save();
// Deleting data
await returned.delete();
})
.catch(err => console.log("something went wrong"));
// Getting all data
db.getAll()
.then(async d => {
// returned data is all key and values, you can access like an normal object
console.log(d, d.key);
// like in get, you can change directily db and save
d.key = 123;
d.newData = {
name: "Hello World"
};
await d.save();
// you can delete all data inside db
await d.deleteAll();
})
.catch(err => console.log("something went wrong"));