npm

Need private packages and team management tools?Check out npm Orgs. »

j-indexdb

1.0.4 • Public • Published

J-indexDB.js

A simple lib for creating an indexedDB storage

Install

npm i j-indexdb
import J_IDB from 'j-indexdb';
const J_IDB = require('j-indexdb');

Usage

As a native plugin:

// Create a new Instance
var myDB = new J_IDB('myDB');
 
// Create DB & tables with index
var tables = {
  'person': [
    ['name', false],
    ['email', true]
  ],
  'animal': [
    ['name', false],
    ['age', false],
    ['type', false]
  ]
};
 
myDB.initDB(tables);
 
// Add data into table
var data = [
  { 'id': 1, 'name': 'Johnny', 'email': 'example@star.com' },
  { 'id': 2, 'name': 'Yan', 'email': 'example2@star.com' }
];
 
myDB.addData('person', data);
 
// Read data with key
myDB.readData('person', 1);
 
// Read data within the whole table
myDB.readAll('person');
 
// Delete data with key
myDB.delData('person', 1);
 
// Update data with a new data(must add key in the new data)
var newData = [
  { 'id': 1, 'name': 'Chris', 'email': 'example@cartoon.com' }
];
myDB.updateData('person', newData);

Methods

  • initDB(tables)

    tables => Type: Object

    Create DB & tables with index.

  • addData(tableName, data)

    dbName => Type: String

    data => Type: Array

    Add data into table.

  • readData(tableName, keyNum)

    dbName => Type: String

    keyNum => Type: Same with keyPath

    Read data with key.

  • readAll(tableName)

    dbName => Type: String

    Read data within the whole table.

  • delData(tableName, keyNum)

    dbName => Type: String

    keyNum => Type: Same with keyPath

    Delete data with key.

  • updateData(tableName, data)

    dbName => Type: String

    data => Type: Array

    Update data with a new data.

License

Under the MIT license.

Keywords

install

npm i j-indexdb

Downloadsweekly downloads

7

version

1.0.4

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability