Skip to content

This is a simple IndexedDB angularjs service that I have created for one of my projects. Hope than may be a shortcut to someone in developing Angularjs-IndexedDB apps.

License

Notifications You must be signed in to change notification settings

VelinGeorgiev/IndexedDB-Angularjs-Service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

IndexedDB-Angularjs-Service

build status

This is a simple IndexedDB angularjs service that I have created for one of my projects for use in offline apps development. Hope that may be a shortcut to someone developing Angularjs IndexedDB apps.

I simply did not find any suitable factory for indexedDB and decided to create a simple service to do the job.

Usage

First in the Service init method define your object stores

  var gameStore = db.createObjectStore("games", { keyPath: "id" });
  gameStore.createIndex("id_idx", "id", { unique: true });
  gameStore.createIndex("data_idx", "data", { unique: false });
  gameStore.createIndex("createdBy_idx", "createdBy", { unique: false });

and then access them with the dbService methods like on the example bellow.

dbService.getByIndex('games', 'owner_idx', $rootScope.user.id).then(
    function (games) {
                //array of game objects returned
    },
    function (error) {
               console.log(error);
    }
);

Load

To insert multiple records in the database, call addall method.

var gamelist = [
  {id:1, data:"", createdBy:"", extra:"",rate:2.5 },
  {id:1, data:"", createdBy:"", extra:"",rate:3.5 },
  {id:1, data:"", createdBy:"", extra:"",rate:1.5 },
  ...
];
dbService.addall('games', gamelist).then(function (total) {
    console.log("total records inserted: ", total);
    //
},function (error) {
    // $q Rejection
    console.log(error);
});

About

This is a simple IndexedDB angularjs service that I have created for one of my projects. Hope than may be a shortcut to someone in developing Angularjs-IndexedDB apps.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •