1.0.1 • Published 2 years ago
ez-json-database v1.0.1
ez-json-database
An easy to use database for Node.js and the browser!
Usage:
Database With Collections And Documents
import AsyncDatabase from "ez-json-database/AsyncDatabase";
// Create Instance
const db = new AsyncDatabase("path/to/db", "utf-8");
// Create Collection
const collection = await db.createCollection("name");
// Set A Document
await db.setDocument("collection", "name", {
value: 23,
});
// Get A Document
const document = await db.getDocument("collection", "name");
// Delete A Document
await db.deleteDocument("collection", "name");
// Delete A Collection
await db.deleteCollection("collection");
// List Documents In A Collection
const documents = await db.listDocuments("collection");
// List All Collections With Their Documents
const collections = await db.listCollections();
There Is Also A SyncDatabase
Class That Is Synchronous.
Single File Database
import FileDatabaseAsync from "ez-json-database/FileDatabaseAsync";
// Create Instance
const db = new FileDatabaseAsync("filename", "utf-8");
// Get An Entry
const entry = await db.get("key");
// Set An Entry
await db.set("key", "value");
// Delete An Entry
await db.delete("key");
// Get All Entries
const entries = await db.all();
There Is Also A FileDatabaseSync
Class That Is Synchronous.
LocalStorage Database
import LocalStorageDatabase from "ez-json-database/LocalStorageDatabase";
// Create Instance
const db = new LocalStorageDatabase();
// Get An Entry
const entry = await db.get("key");
// Set An Entry
await db.set("key", "value");
// Delete An Entry
await db.delete("key");
// Clear All Entries
await db.clear();
There Is Also A SessionStorageDatabase
Class That Works For Session Storage.