0.0.3 • Published 6 years ago
@marvinh/json-db v0.0.3
Simple JSON-Database
This is a simple implementation of a json-based collections, which can be queried
with predicates, similar to Array.filter
.
Installation
# npm
npm install @marvinh/json-db
# yarn
yarn add @marvinh/json-db
Usage
import { Collection, FileAdapter } from "@marvinh/json-db";
const posts = new Collection("posts", new FileAdapter("db.json"));
// Insert posts into the collection
await posts.update({ id: 1, title: "Hello World" });
await posts.update({ id: 2, title: "Second Post" });
// Contains the first post matching the predicate
const one = await posts.findOne(post => post.title = "Hello World");
// Contains all posts matching the predicate
const all = await posts.find(() => true);
// Delete a post
await posts.delete(one);
License
MIT
, see License.