Skip to content

Create, read, update and delete your JSON data store in GitHub.

License

Notifications You must be signed in to change notification settings

aneesahammed/grud

Repository files navigation

Welcome to grud 👋

Version Documentation Maintenance License: MIT Twitter: aneesahammed downloads

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.

Install

npm install grud

Initialize

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.

Create

Create a single record

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);

Create multiple records

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);

Read

Get record by Id or unique identifier

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" });

Get all records

The following query returns all posts records.

const posts = await db.find();

Update

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);

Delete

Delete a single record

The following query deletes a single post record.

await db.deleteOne({ _id: "301b63faac384a31b3e785ebf40295e5" });

or

await db.deleteOne({ author: "Anand" });

Delete all records

TBA

Run tests

npm run test

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

Limits

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.

Author

👤 Anees Ahammed

📝 License

Copyright © 2021 Anees Ahammed.
This project is MIT licensed.

About

Create, read, update and delete your JSON data store in GitHub.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published