dbcopycat
Version:
A JSON Database that saves your Json data in a file and makes it easy for you to perform CRUD operations.
122 lines (88 loc) • 2.85 kB
Markdown
A JSON Database that saves your Json data in a file and makes it easy for you to perform CRUD operations.
<!-- TOC -->
- [Motivation](
- [Features](
- [Getting started](
- [Installation](
- [Commands](
- [getall()](
- [getById(arrayName, dataId)](
- [add(arrayName, data)](
- [deleteById(arrayName, dataId)](
- [update(arrayName, data)](
- [filter(arrayName, condition)](
- [find(arrayName, condition)](
- [License](
<!-- TOC -->
In small web projects, database connection is very troublesome and unnecessary in projects we usually do to improve ourselves. That's why we make use of `static json` files. Why don't we make our static json file `dynamic` with minimal code?
- Make your `static json` file `dynamic`.
- Get persistent json data.
- Get rid of database fees and hassle.
- It is so fast compared to other databases that it behaves as if it is a static data. 'NO WAITING TIME'.
Start converting your static json file to dynamic json file!
```sh
$ npm i -g dbcopycat
```
Then...
```sh
$ dbcopycat init
```
Generates a `db.json` file with some data
Fetch all data
```js
const dbcopycat = require('dbcopycat');
var data = dbcopycat.getAll();
```
Returns the data that matches the data id
```js
const dbcopycat = require('dbcopycat');
dbcopycat.getById(arrayName, dataId);
```
Adds data to data
```js
const dbcopycat = require('dbcopycat');
var data = {
"id": 2,
"categoryId": 1,
"productName": "Chang",
"quantityPerUnit": "24 - 12 oz bottles",
"unitPrice": "21",
"unitsInStock": 17
}
dbcopycat.add("arrayName", data);
```
Deletes data that matches the data ID
```js
const dbcopycat = require('dbcopycat');
dbcopycat.deleteById(arrayName, dataId);
```
Updates data that matches the data id
```js
const dbcopycat = require('dbcopycat');
dbcopycat.update(arrayName, data);
```
Filters data by condition
```js
const dbcopycat = require('dbcopycat');
dbcopycat.filter("arrayName", x => x.id == 1)
```
Returns a single data suitable for the condition
```js
const dbcopycat = require('dbcopycat');
dbcopycat.find("arrayName", x => x.categoryid == 1)
```
MIT