Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

hosseinmd/react-notarealdb

Repository files navigation

NPM

install size dependencies

Not a Real DB

A "fake" database for reactjs react-native that stores data in local storage, for sample applications.

Usage

Create a DataStore instance specifying by name to store the data. then run load for get old data

const { DataStore } = require("react-notarealdb");

const apples = new DataStore("apples");
const oranges = new DataStore("oranges");
await apples.load();
await oranges.load();

You can then manipulate each collection using the following CRUD operations:

// create a new item; returns a generated id
const id = await apples.create({ variety: "Gala", weight: 133 }); // => 'BJ4E9mQOG'

// list all items in a collection
apples.list(); // => [{id: 'BJ4E9mQOG', variety: 'Gala', weight: 133}]

// get a single item
apples.get("BJ4E9mQOG"); // => {id: 'BJ4E9mQOG', variety: 'Gala', weight: 133}

// update an item
await apples.update({ id: "BJ4E9mQOG", variety: "Braeburn", weight: 133 });

// delete an item
await apples.delete("BJ4E9mQOG");

That's it. few operations are asynchronous.

About

Local Storage which simulated database CRUD functions

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published