zip-db
Lightweight JSON based Database implementation for NodeJS, which is designed for a small volume of stored data. No additional Database drivers are required.
The Database will be:
- persisted into the local file system
- encrypted with
aes-256-ctr
- compressed
Example
const ZipDb = require("zip-db"); // Initialize a database that will be persisted in the file "mydb.db".// The database will be encrypted by using the password "my-password".const db = new ZipDb(__dirname + "/mydb.db", "my-password"); // add a new collectionconst peopleCollection = db.createCollection("people"); // add a new document to the collectionconst johnCenasId = peopleCollection.add({ firstName: "John", lastName: "Cena", symbol: "💪🏻",}); // get an array of all entities in the collectionconst allPeople = peopleCollection.getAll(); // get a specific document from the collectionconst johnCena = peopleCollection.getById(johnCenasId); // update john cenaconst updatedJohnCena = peopleCollection.update(johnCenasId, { firstName: "John", lastName: "Cena", symbol: "🥊",}); // delete a document from the collectionpeopleCollection.removeById(johnCenasId); // remove all entites from collectionpeopleCollection.truncate(); // remove people collectiondb.removeCollection("people"); // add a collection of fruits, if it does not exist yetconst fruitCol = db.hasCollection("fruits") ? db.getCollection("fruits") : db.createCollection("fruits"); // add tasty fruitsfruitCol.add({ name: "Apple", symbol: "🍎" });fruitCol.add({ name: "Banana", symbol: "🍌" });fruitCol.add({ name: "Melon", symbol: "🍉" }); // print all documents of all collectionsdb.getAllCollections().forEach(col => { console.log(col.name, col.getAll());}); // persist changes to databasedb.persist(); // add a collection of junkfoodconst junkCol = db.createCollection("junkfood");junkCol.add({ name: "Burger", symbol: "🍔" });junkCol.add({ name: "Fries", symbol: "🍟" });junkCol.add({ name: "Pizza", symbol: "🍕" }); // we roll back the database to the last .persist() call// this erases the bad junkfood collection againdb.rollBack();