browser-database
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

browser-database

Simple client-side database based on localStorage. It creates in localStorage document-oriented database and provides basic data fetch/update methods.

travis ci npm version

Coverage Report

Documentation

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 record
  • update(table: string, id: number, row: object) - update record for specific id
  • remove(table: string, id: number) - remove record
  • getAll(table: string) - get all records
  • getById(table: string, id: number) - get record by id
  • subscribe(callback: Function) - subscribe to datbase updates. Callback will be called with 3 parameters:
  • table - name of table
  • action - performed action: insert, update, remove
  • result - result of action (new/updated/removed row data)

Development

  • npm run clear - clear /dist folder
  • npm run build - build production version
  • npm run watch - run watcher & build in development mode
  • npm run lint - run linter
  • npm run test - run karma unit tests
  • npm run coverage - run karma unit tests & generate coverage report to /coverage folder
  • npm run doc - gerenate documentation to /documentation folder

Readme

Keywords

Package Sidebar

Install

npm i browser-database

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

44.4 kB

Total Files

38

Last publish

Collaborators

  • s-kalaus