1 | [![NPM](https://nodei.co/npm/react-notarealdb.png)](https://nodei.co/npm/react-notarealdb/)
|
2 |
|
3 | [![install size](https://packagephobia.now.sh/badge?p=react-notarealdb)](https://packagephobia.now.sh/result?p=react-notarealdb) [![dependencies](https://david-dm.org/hosseinmd/react-notarealdb.svg)](https://david-dm.org/hosseinmd/react-notarealdb.svg)
|
4 |
|
5 | # Not a Real DB
|
6 |
|
7 | A "fake" database for reactjs react-native that stores data in local storage, for sample applications.
|
8 |
|
9 | ## Usage
|
10 |
|
11 | Create a `DataStore` instance specifying by name to store the data. then run load for get old data
|
12 |
|
13 | ```js
|
14 | const { DataStore } = require("react-notarealdb");
|
15 |
|
16 | const apples = new DataStore("apples");
|
17 | const oranges = new DataStore("oranges");
|
18 | await apples.load();
|
19 | await oranges.load();
|
20 | ```
|
21 |
|
22 | You can then manipulate each collection using the following CRUD operations:
|
23 |
|
24 | ```js
|
25 | // create a new item; returns a generated id
|
26 | const id = await apples.create({ variety: "Gala", weight: 133 }); // => 'BJ4E9mQOG'
|
27 |
|
28 | // list all items in a collection
|
29 | apples.list(); // => [{id: 'BJ4E9mQOG', variety: 'Gala', weight: 133}]
|
30 |
|
31 | // get a single item
|
32 | apples.get("BJ4E9mQOG"); // => {id: 'BJ4E9mQOG', variety: 'Gala', weight: 133}
|
33 |
|
34 | // update an item
|
35 | await apples.update({ id: "BJ4E9mQOG", variety: "Braeburn", weight: 133 });
|
36 |
|
37 | // delete an item
|
38 | await apples.delete("BJ4E9mQOG");
|
39 | ```
|
40 |
|
41 | That's it. few operations are asynchronous.
|