1.0.12 ā€¢ Published 3 years ago

grud v1.0.12

Weekly downloads
79
License
MIT
Repository
github
Last release
3 years ago

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

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.

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago