Simple JSON data store in GitHub with CRUD interface for React, Node, Electron and the browser.
grud is a convenient method of storing & performing read, update & delete operations on data without setting up a database server.
🏠 Homepage
npm install grud
To get started with grud, initialize the db
object by passing the required config.
const Grud = require("grud");
let config = {
protocol: "https", //If not passed, defaults to 'https'
host: "api.github.com", //If not passed, defaults to 'api.github.com' | In case of Enterprise-GitHub e.g github.snapcircle.net.
pathPrefix: "", //Leave empty if you are using github.com | In case of Enterprise-GitHub e.g api/v3
owner: "username", //Your GitHub username
repo: "my-repo", //Your repository name where you'd like to have your JSON store hosted
path: "db.json", //Your data store file with .json extension
personalAccessToken: "xxxx", //Your personal-access-token with write access
};
let db = new Grud(config);
Create your GitHub personal token from here.
And please note that grud will create a new JSON data store file as mentioned in the config
(db.json in our case) if the file is not found.
If the file exists, data shall get appended to the collection array.
The following query creates a single post
record in your JSON dataStore (db.json
).
const data = {
author: "Anand",
title: "sunt aut facere repellat provident ",
body: "quia et suscipit\nsuscipit recusandae consequuntur ",
};
const posts = await db.save(data);
The following query creates multiple post
records in your defined JSON datastore.
const data = [
{
author: "Sarath",
title: "sunt aut facere repellat provident ",
body: "quia et suscipit\nsuscipit recusandae consequuntur ",
},
{
author: "Anand",
title: "qui est esse",
body: "est rerum tempore vitae\nsequi sint nihil",
},
];
const posts = await db.save(data);
The following query returns a single post
record by unique identifier or Id.
const post = await db.find({ _id: "301b63faac384a31b3e785ebf40295e5" });
or
const post = await db.find({ author: "Anand" });
The following query returns all posts
records.
const posts = await db.find();
Update record by Id or unique identifier.
The following query finds the post
record and updates it.
const posts = await db.update(
{ _id: "301b63faac384a31b3e785ebf40295e5" },
data
);
or
const posts = await db.update({ author: "Anand" }, data);
The following query deletes a single post
record.
await db.deleteOne({ _id: "301b63faac384a31b3e785ebf40295e5" });
or
await db.deleteOne({ author: "Anand" });
TBA
npm run test
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Give a ⭐️ if this project helped you!
grud came out from the frequent need of having a database for internal tooling purpose.
If your priority is to have secure/high-performance storage, you should stick to traditional databases like MongoDB.
👤 Anees Ahammed
- Twitter: @aneesahammed
Copyright © 2021 Anees Ahammed.
This project is MIT licensed.