Skip to content

Latest commit

 

History

History
82 lines (62 loc) · 1.42 KB

README.md

File metadata and controls

82 lines (62 loc) · 1.42 KB

angular-db

An AngularJS IndexedDB provider base on db.js.

Requirement

Installation

Add a <script> to your index.html:

<script src="db.js"></script>
<script src="angular-db.js"></script>

And add dbService as a dependency for your app:

angular.module('myApp', ['dbService']);

Usage

Config IndexedDB with dbProvider:

app.config(['dbProvider', function(dbProvider) {
  dbProvider.config({
    server: 'PREFIX_',
    version: 1,
    schema: {
      phones: {
        key: { keyPath: 'phoneId' }
      }
      // etc...
    }
  });
}]);

Use db service to CRUD:

app.controller('PhoneListCtrl', ['$scope', 'db', function($scope, db) {
  db('phones').getBatch(function(phones) {
  	$scope.phones = phones;
  });
}]);

app.controller('PhoneDetailCtrl', ['$scope', '$routeParams', 'db', 
function($scope, $routeParams, db) {
  db('phones').get('phoneId', parseInt($routeParams.phoneId), function(phones) {
    $scope.mainImageUrl = phones[0].images[0];
  });
}]);

Documentation

Adding items

db('objectStore').putBatch(array, onSuccess);

Querying all objects

db('objectStore').getBatch(onSuccess);

Getting a single object by ID

db('objectStore').get('keyPath', value, onSuccess);