Code Monkey home page Code Monkey logo

ng-idb's Introduction

iDB

ng-iDB is a wrapper around iDB, its helps angular developer to effeciently and fastly use IndexedDB to write modern HTML5 apps.

Install using bower

$ bower install ngidb --save

How to use it

step 1: Add dependency to your angular app

a) add 'ngIDb' module to your app
angular.module('your_module', ['ngIDb'])
b) inject '$iDB' service to your controller or service

step 2: Registring the object store.

Register all the object store that you want to use in your app

var objectStoresToRegister = [{
    name: 'test'
}, {
    name: 'customers'
}];
$iDB.registration.registerObjectStore(objectStoresToRegister);

Step 3: Initializing the database.

This will create the database and create the objectstore.

var databaseName = "test";
$iDB.registration.init({
    databaseName: databaseName,
    version: 1
})

Step 3: Perform operations on the database.

After step 2 database operations can be performed(add, delete, find, findByIndex, where, all)

Add
$iDB.add({
    objectStoreName: , //object store on which operation will be performed
    data:  //array of data to be added to the object store
});

add method will return a promise with added objects in the promise function.

Delete
$iDB.delete({
    objectStoreName: , //object store on which operation will be performed
    objectsToDelete:  //array of data to be added to the object store
});

delete method will return a promise with deleted objects in the promise function.

Find
 $iDB.find({
    objectStoreName: ,//object store on which operation will be performed
    indexName: //indexed property to be searched on 
    indexValue: //value of the index property to be searched
});

find function will return a promise which will resolve with the found objects

Find By Index
 $iDB.findByIndex({
    objectStoreName: ,//object store on which operation will be performed
    indexName: //indexed property to be searched on 
    indexValue: //value of the index property to be searched
});

findByIndex function will return a promise which will resolve to array of objects found.

where

Where operation can be slow as it has to iterates over all the object of the given object >store.

 $iDB.where({
    objectStoreName: ,//object store on which operation will be performed
    conditions: //array conditions to be applied

each condition is object and each where condition object looks like this

{
    property: ,//property of object to be checked
    operator: 'greaterThanEqualTo', 
    value: 25,
    and: //nested condition
}

Conditions in the array is applied as || . Nested conditions using the 'and' property is applied as &&

operator string value that can be any of the following:

'greaterThan': >
'equalTo':  ==
'lessThan': < 
'lessThanEqualTo' <=
'greaterThanEqualTo': >=
'notEqualTo': !=

where function will return a promise which will resolve to arrray of objects found.

all

Used to query all data in the objectstore

$iDB.all({
    objectStoreName: ,//name of the object store
});

all function will reutrn a promise which will resolve to array of all the object present in that object store.

ng-idb's People

Contributors

sushantt2099 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.