UNPKG

1.38 kBMarkdownView Raw
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
7A "fake" database for reactjs react-native that stores data in local storage, for sample applications.
8
9## Usage
10
11Create a `DataStore` instance specifying by name to store the data. then run load for get old data
12
13```js
14const { DataStore } = require("react-notarealdb");
15
16const apples = new DataStore("apples");
17const oranges = new DataStore("oranges");
18await apples.load();
19await oranges.load();
20```
21
22You can then manipulate each collection using the following CRUD operations:
23
24```js
25// create a new item; returns a generated id
26const id = await apples.create({ variety: "Gala", weight: 133 }); // => 'BJ4E9mQOG'
27
28// list all items in a collection
29apples.list(); // => [{id: 'BJ4E9mQOG', variety: 'Gala', weight: 133}]
30
31// get a single item
32apples.get("BJ4E9mQOG"); // => {id: 'BJ4E9mQOG', variety: 'Gala', weight: 133}
33
34// update an item
35await apples.update({ id: "BJ4E9mQOG", variety: "Braeburn", weight: 133 });
36
37// delete an item
38await apples.delete("BJ4E9mQOG");
39```
40
41That's it. few operations are asynchronous.