browser-database
v1.0.5
Published
Simple client-side database based on localStorage
Downloads
3
Readme
browser-database
Simple client-side database based on localStorage. It creates in localStorage document-oriented database and provides basic data fetch/update methods.
Demo (Add only)
Installation
npm install browser-database
- install package
Usage
- Include with (plain JavaScript for browser):
<script src="node_modules/browser-database/dist/browser-database.js"></script>
<script>
browserDatabase.insert('modelName', {field: 'value'});
</script>
- Include with (ES6):
import {BrowserDatabase} from 'browser-database';
const browserDatabase = new BrowserDatabase({
storageType: 'localStorage',
storageKey: 'databaseName'
});
browserDatabase.insert('modelName', {field: 'value'})
.then(row => console.log(row))
.catch(err => console.error(err));
BrowserDatabase options
storageType: string
- type of storage to use:localStorage
storageKey: string
- database name
Methods
insert(table: string, row: object)
- add new recordupdate(table: string, id: number, row: object)
- update record for specific idremove(table: string, id: number)
- remove recordgetAll(table: string)
- get all recordsgetById(table: string, id: number)
- get record by idsubscribe(callback: Function)
- subscribe to datbase updates. Callback will be called with 3 parameters:table
- name of tableaction
- performed action:insert
,update
,remove
result
- result of action (new/updated/removed row data)
Development
npm run clear
- clear/dist
foldernpm run build
- build production versionnpm run watch
- run watcher & build in development modenpm run lint
- run linternpm run test
- run karma unit testsnpm run coverage
- run karma unit tests & generate coverage report to/coverage
foldernpm run doc
- gerenate documentation to/documentation
folder