Skip to content

mprzodala/browser-storage-db

Repository files navigation

browser-storage-db

Build Status Coverage Status npm npm

BrowserStorageDB give you posibility to save and find data in localStorage or sessionStorage with basic mongoDB interface.

Examples

set(documents: [Object]): void

import BrowserStorageDB from 'browser-storage-db';
const db = new BrowserStorageDB('testDB', localStorage);
const initialState = [{ id:'1', name:'foo', desc: 'bar' }, { id:'2', name:'foo2', desc: 'bar2' }];
db.set(initialState);

insert(document: Object): String

import BrowserStorageDB from 'browser-storage-db';
const db = new BrowserStorageDB('testDB', localStorage);
const document = { name:'foo', desc: 'bar' };
const documentId = db.insert(document);

update(id: String, data: Object): void

import BrowserStorageDB from 'browser-storage-db';
const db = new BrowserStorageDB('testDB', localStorage);
const documentId = '3d3d4sda3sd';
const document = { name:'foo2', desc: 'bar2' };
db.update(documentId, document);

find(query: Object): [Object]

import BrowserStorageDB from 'browser-storage-db';
const db = new BrowserStorageDB('testDB', localStorage);
const query = { name: 'foo2' };
const documents = db.find(query);

findOne(query: Object): Object

import BrowserStorageDB from 'browser-storage-db';
const db = new BrowserStorageDB('testDB', localStorage);
const query = { name: 'foo2' };
const document = db.findOne(query);

To see more complex examples, check out this project's test suite.

About

Simple db based on browser localStorage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published