├── index.ts ├── .gitignore ├── index.metadata.json ├── .jshintrc ├── tsconfig.json ├── Gruntfile.js ├── LICENSE ├── angular2-indexeddb.d.ts ├── package.json ├── angular2-indexeddb.metadata.json ├── angular2-indexeddb.min.js ├── angular2-indexeddb.min.js.map ├── README.md ├── angular2-indexeddb.js.map ├── angular2-indexeddb.js └── angular2-indexeddb.ts /index.ts: -------------------------------------------------------------------------------- 1 | export {AngularIndexedDB, IndexDetails} from './angular2-indexeddb'; 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /node_modules 3 | npm-debug.log 4 | index.html 5 | index1.html 6 | main.* 7 | app.component.* -------------------------------------------------------------------------------- /index.metadata.json: -------------------------------------------------------------------------------- 1 | [{"__symbolic":"module","version":3,"metadata":{},"exports":[{"from":"./angular2-indexeddb","export":["AngularIndexedDB","IndexDetails"]}]},{"__symbolic":"module","version":1,"metadata":{},"exports":[{"from":"./angular2-indexeddb","export":["AngularIndexedDB","IndexDetails"]}]}] -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "browser": true, 4 | "esnext": true, 5 | "bitwise": true, 6 | "camelcase": true, 7 | "curly": true, 8 | "eqeqeq": true, 9 | "immed": true, 10 | "indent": 2, 11 | "latedef": true, 12 | "newcap": true, 13 | "noarg": true, 14 | "quotmark": "single", 15 | "regexp": true, 16 | "undef": true, 17 | "unused": true, 18 | "strict": true, 19 | "trailing": true, 20 | "smarttabs": true, 21 | "maxdepth": 2, 22 | "maxcomplexity": 10, 23 | "globals": { 24 | "angular": false 25 | } 26 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "emitDecoratorMetadata": true, 8 | "experimentalDecorators": true, 9 | "removeComments": false, 10 | "noImplicitAny": false, 11 | "declaration": true, 12 | "lib": ["dom","es6"] 13 | }, 14 | "exclude": [ 15 | "node_modules" 16 | ], 17 | "angularCompilerOptions": { 18 | "genDir": ".", 19 | "skipMetadataEmit" : false, 20 | "skipTemplateCodegen": true 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* License: MIT. 2 | * Copyright (C) 2016, Gil Fink. 3 | */ 4 | 5 | 'use strict'; 6 | 7 | module.exports = function (grunt) { 8 | // Load grunt tasks automatically 9 | require('load-grunt-tasks')(grunt); 10 | 11 | grunt.initConfig({ 12 | jshint: { 13 | options: { 14 | jshintrc: '.jshintrc' 15 | }, 16 | all: [ 17 | 'Gruntfile.js', 18 | 'angular2-indexeddb.js' 19 | ] 20 | }, 21 | uglify: { 22 | dist: { 23 | options: { 24 | sourceMap: true 25 | }, 26 | files: { 27 | 'angular2-indexeddb.min.js': 'angular2-indexeddb.js' 28 | } 29 | } 30 | } 31 | }); 32 | 33 | grunt.registerTask('build', [ 34 | 'uglify' 35 | ]); 36 | 37 | grunt.registerTask('default', ['build']); 38 | }; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Gil Fink and contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /angular2-indexeddb.d.ts: -------------------------------------------------------------------------------- 1 | export declare class AngularIndexedDB { 2 | utils: Utils; 3 | dbWrapper: DbWrapper; 4 | constructor(dbName: string, version: number); 5 | openDatabase(version: number, upgradeCallback?: Function): Promise; 6 | getByKey(storeName: string, key: any): Promise; 7 | getAll(storeName: string, keyRange?: IDBKeyRange, indexDetails?: IndexDetails): Promise; 8 | add(storeName: string, value: any, key?: any): Promise; 9 | update(storeName: string, value: any, key?: any): Promise; 10 | delete(storeName: string, key: any): Promise; 11 | openCursor(storeName: string, cursorCallback: (evt: Event) => void, keyRange?: IDBKeyRange): Promise; 12 | clear(storeName: string): Promise; 13 | getByIndex(storeName: string, indexName: string, key: any): Promise; 14 | } 15 | export declare class Utils { 16 | indexedDB: IDBFactory; 17 | constructor(); 18 | } 19 | export interface IndexDetails { 20 | indexName: string; 21 | order: string; 22 | } 23 | export declare class DbWrapper { 24 | dbName: string; 25 | dbVersion: number; 26 | db: IDBDatabase; 27 | constructor(dbName: string, version: number); 28 | validateStoreName(storeName: string): boolean; 29 | validateBeforeTransaction(storeName: string, reject: Function): void; 30 | createTransaction(options: { 31 | storeName: string; 32 | dbMode: IDBTransactionMode; 33 | error: (e: Event) => any; 34 | complete: (e: Event) => any; 35 | abort?: (e: Event) => any; 36 | }): IDBTransaction; 37 | } 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-indexeddb", 3 | "version": "1.2.3", 4 | "description": "angular2-indexeddb is a library that wraps indexeddb database in an Angular 2 service", 5 | "repository": { 6 | "type": "git", 7 | "url": "http://github.com/gilf/angular2-indexeddb.git" 8 | }, 9 | "files": [ 10 | "angular2-indexeddb.ts", 11 | "angular2-indexeddb.d.ts", 12 | "angular2-indexeddb.js", 13 | "angular2-indexeddb.js.map", 14 | "angular2-indexeddb.min.js", 15 | "angular2-indexeddb.min.js.map", 16 | "angular2-indexeddb.metadata.json", 17 | "index.ts", 18 | "index.d.ts", 19 | "index.js", 20 | "index.js.map", 21 | "LICENSE", 22 | "README.md" 23 | ], 24 | "scripts": { 25 | "tsc": "node_modules/.bin/ngc", 26 | "tsc:w": "tsc -w", 27 | "lite": "lite-server", 28 | "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ", 29 | "build": "node_modules/.bin/grunt build" 30 | }, 31 | "license": "MIT", 32 | "keywords": [ 33 | "Angular", 34 | "indexedDB", 35 | "ng", 36 | "service" 37 | ], 38 | "dependencies": { 39 | "@angular/core": ">=4.3.1" 40 | }, 41 | "engines": { 42 | "node": ">=0.10.0" 43 | }, 44 | "devDependencies": { 45 | "@angular/compiler": "^4.3.1", 46 | "@angular/compiler-cli": "^2.4.0", 47 | "concurrently": "^3.5.0", 48 | "lite-server": "^1.3.4", 49 | "typescript": "^2.4.2", 50 | "grunt": "0.4.5", 51 | "grunt-cli": "0.1.13", 52 | "grunt-contrib-cssmin": "0.14.0", 53 | "grunt-contrib-jshint": "0.11.3", 54 | "grunt-contrib-uglify": "0.9.2", 55 | "grunt-ngdocs": "0.2.9", 56 | "load-grunt-tasks": "3.3.0" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /angular2-indexeddb.metadata.json: -------------------------------------------------------------------------------- 1 | [{"__symbolic":"module","version":3,"metadata":{"AngularIndexedDB":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"number"}]}],"openDatabase":[{"__symbolic":"method"}],"getByKey":[{"__symbolic":"method"}],"getAll":[{"__symbolic":"method"}],"add":[{"__symbolic":"method"}],"update":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"openCursor":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"getByIndex":[{"__symbolic":"method"}]}},"Utils":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor"}]}},"DbWrapper":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"number"}]}],"validateStoreName":[{"__symbolic":"method"}],"validateBeforeTransaction":[{"__symbolic":"method"}],"createTransaction":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"AngularIndexedDB":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"number"}]}],"openDatabase":[{"__symbolic":"method"}],"getByKey":[{"__symbolic":"method"}],"getAll":[{"__symbolic":"method"}],"add":[{"__symbolic":"method"}],"update":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"openCursor":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"getByIndex":[{"__symbolic":"method"}]}},"Utils":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor"}]}},"DbWrapper":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"number"}]}],"validateStoreName":[{"__symbolic":"method"}],"validateBeforeTransaction":[{"__symbolic":"method"}],"createTransaction":[{"__symbolic":"method"}]}}}}] -------------------------------------------------------------------------------- /angular2-indexeddb.min.js: -------------------------------------------------------------------------------- 1 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var AngularIndexedDB=function(){function a(a,b){this.utils=new Utils,this.dbWrapper=new DbWrapper(a,b)}return a.prototype.openDatabase=function(a,b){var c=this,d=this;return new Promise(function(e,f){c.dbWrapper.dbVersion=a;var g=c.utils.indexedDB.open(c.dbWrapper.dbName,a);g.onsuccess=function(a){d.dbWrapper.db=g.result,e()},g.onerror=function(a){f((a.target.errorCode,a.target.errorCode+" ("+a.target.error+")"))},"function"==typeof b&&(g.onupgradeneeded=function(a){b(a,d.dbWrapper.db)})})},a.prototype.getByKey=function(a,b){var c=this;return new Promise(function(d,e){c.dbWrapper.validateBeforeTransaction(a,e);var f,g=c.dbWrapper.createTransaction({storeName:a,dbMode:"readonly",error:function(a){e(a)},complete:function(a){}}),h=g.objectStore(a);f=h.get(b),f.onsuccess=function(a){d(a.target.result)}})},a.prototype.getAll=function(a,b,c){var d=this;return new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f);var g,h=d.dbWrapper.createTransaction({storeName:a,dbMode:"readonly",error:function(a){f(a)},complete:function(a){}}),i=h.objectStore(a),j=[];if(c){var k=i.index(c.indexName),l="desc"===c.order?"prev":"next";g=k.openCursor(b,l)}else g=i.openCursor(b);g.onerror=function(a){f(a)},g.onsuccess=function(a){var b=a.target.result;b?(j.push(b.value),b.continue()):e(j)}})},a.prototype.add=function(a,b,c){var d=this;return new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f),d.dbWrapper.createTransaction({storeName:a,dbMode:"readwrite",error:function(a){f(a)},complete:function(a){e({key:c,value:b})}}).objectStore(a).add(b,c).onsuccess=function(a){c=a.target.result}})},a.prototype.update=function(a,b,c){var d=this;return new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f),d.dbWrapper.createTransaction({storeName:a,dbMode:"readwrite",error:function(a){f(a)},complete:function(a){e(b)},abort:function(a){f(a)}}).objectStore(a).put(b,c)})},a.prototype.delete=function(a,b){var c=this;return new Promise(function(d,e){c.dbWrapper.validateBeforeTransaction(a,e),c.dbWrapper.createTransaction({storeName:a,dbMode:"readwrite",error:function(a){e(a)},complete:function(a){d()},abort:function(a){e(a)}}).objectStore(a).delete(b)})},a.prototype.openCursor=function(a,b,c){var d=this;return new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f),d.dbWrapper.createTransaction({storeName:a,dbMode:"readonly",error:function(a){f(a)},complete:function(a){e()},abort:function(a){f(a)}}).objectStore(a).openCursor(c).onsuccess=function(a){b(a),e()}})},a.prototype.clear=function(a){var b=this;return new Promise(function(c,d){b.dbWrapper.validateBeforeTransaction(a,d),b.dbWrapper.createTransaction({storeName:a,dbMode:"readwrite",error:function(a){d(a)},complete:function(a){c()},abort:function(a){d(a)}}).objectStore(a).clear(),c()})},a.prototype.getByIndex=function(a,b,c){var d=this;return new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f),d.dbWrapper.createTransaction({storeName:a,dbMode:"readonly",error:function(a){f(a)},abort:function(a){f(a)},complete:function(a){}}).objectStore(a).index(b).get(c).onsuccess=function(a){e(a.target.result)}})},a}();exports.AngularIndexedDB=AngularIndexedDB;var Utils=function(){function a(){this.indexedDB=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB}return a}();exports.Utils=Utils;var DbWrapper=function(){function a(a,b){this.dbName=a,this.dbVersion=b||1,this.db=null}return a.prototype.validateStoreName=function(a){return this.db.objectStoreNames.contains(a)},a.prototype.validateBeforeTransaction=function(a,b){this.db||b("You need to use the openDatabase function to create a database before you query it!"),this.validateStoreName(a)||b("objectStore does not exists: "+a)},a.prototype.createTransaction=function(a){var b=this.db.transaction(a.storeName,a.dbMode);return b.onerror=a.error,b.oncomplete=a.complete,b.onabort=a.abort,b},a}();exports.DbWrapper=DbWrapper; 2 | //# sourceMappingURL=angular2-indexeddb.min.js.map -------------------------------------------------------------------------------- /angular2-indexeddb.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["angular2-indexeddb.js"],"names":["Object","defineProperty","exports","value","AngularIndexedDB","dbName","version","this","utils","Utils","dbWrapper","DbWrapper","prototype","openDatabase","upgradeCallback","_this","self","Promise","resolve","reject","dbVersion","request","indexedDB","open","onsuccess","e","db","result","onerror","target","errorCode","error","onupgradeneeded","getByKey","storeName","key","validateBeforeTransaction","transaction","createTransaction","dbMode","complete","objectStore","get","event","getAll","keyRange","indexDetails","index","indexName","order","openCursor","evt","cursor","push","add","update","abort","put","delete","cursorCallback","clear","getByIndex","window","mozIndexedDB","webkitIndexedDB","msIndexedDB","validateStoreName","objectStoreNames","contains","options","trans","oncomplete","onabort"],"mappings":"AAAA,YACAA,QAAOC,eAAeC,QAAS,cAAgBC,OAAO,GACtD,IAAIC,kBAAkC,WAClC,QAASA,GAAiBC,EAAQC,GAC9BC,KAAKC,MAAQ,GAAIC,OACjBF,KAAKG,UAAY,GAAIC,WAAUN,EAAQC,GAmM3C,MAjMAF,GAAiBQ,UAAUC,aAAe,SAAUP,EAASQ,GACzD,GAAIC,GAAQR,KACRS,EAAOT,IACX,OAAO,IAAIU,SAAQ,SAAUC,EAASC,GAClCJ,EAAML,UAAUU,UAAYd,CAC5B,IAAIe,GAAUN,EAAMP,MAAMc,UAAUC,KAAKR,EAAML,UAAUL,OAAQC,EACjEe,GAAQG,UAAY,SAAUC,GAC1BT,EAAKN,UAAUgB,GAAKL,EAAQM,OAC5BT,KAEJG,EAAQO,QAAU,SAAUH,GACxBN,GAA6BM,EAAEI,OAAOC,UAClCL,EAAEI,OAAOC,UAAY,KAAOL,EAAEI,OAAOE,MAAQ,OAGtB,kBAApBjB,KACPO,EAAQW,gBAAkB,SAAUP,GAChCX,EAAgBW,EAAGT,EAAKN,UAAUgB,SAKlDtB,EAAiBQ,UAAUqB,SAAW,SAAUC,EAAWC,GACvD,GAAInB,GAAOT,IACX,OAAO,IAAIU,SAAQ,SAAUC,EAASC,GAClCH,EAAKN,UAAU0B,0BAA0BF,EAAWf,EACpD,IAOsDE,GAPlDgB,EAAcrB,EAAKN,UAAU4B,mBAAoBJ,UAAWA,EAC5DK,OAAQ,WACRR,MAAO,SAAUN,GACbN,EAAOM,IAEXe,SAAU,SAAUf,OAEpBgB,EAAcJ,EAAYI,YAAYP,EAC1Cb,GAAUoB,EAAYC,IAAIP,GAC1Bd,EAAQG,UAAY,SAAUmB,GAC1BzB,EAAQyB,EAAMd,OAAOF,YAIjCvB,EAAiBQ,UAAUgC,OAAS,SAAUV,EA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UiD,WAAa,SAAU3B,EAAWc,EAAWb,GACpE,GAAInB,GAAOT,IACX,OAAO,IAAIU,SAAQ,SAAUC,EAASC,GAClCH,EAAKN,UAAU0B,0BAA0BF,EAAWf,GAClCH,EAAKN,UAAU4B,mBAAoBJ,UAAWA,EAC5DK,OAAQ,WACRR,MAAO,SAAUN,GACbN,EAAOM,IAEX+B,MAAO,SAAU/B,GACbN,EAAOM,IAEXe,SAAU,SAAUf,OAEMgB,YAAYP,GAAgCa,MAAMC,GAA4BN,IAAIP,GACxGX,UAAY,SAAUmB,GAC1BzB,EAAQyB,EAAMd,OAAOF,YAI1BvB,IAEXF,SAAQE,iBAAmBA,gBAC3B,IAAIK,OAAuB,WACvB,QAASA,KACLF,KAAKe,UAAYwC,OAAOxC,WAAawC,OAAOC,cAAgBD,OAAOE,iBAAmBF,OAAOG,YAEjG,MAAOxD,KAEXP,SAAQO,MAAQA,KAChB,IAAIE,WAA2B,WAC3B,QAASA,GAAUN,EAAQC,GACvBC,KAAKF,OAASA,EACdE,KAAKa,UAAYd,GAAW,EAC5BC,KAAKmB,GAAK,KAqBd,MAnBAf,GAAUC,UAAUsD,kBAAoB,SAAUhC,GAC9C,MAAO3B,MAAKmB,GAAGyC,iBAAiBC,SAASlC,IAG7CvB,EAAUC,UAAUwB,0BAA4B,SAAUF,EAAWf,GAC5DZ,KAAKmB,IACNP,EAAO,uFAENZ,KAAK2D,kBAAkBhC,IACxBf,EAAQ,gCAAkCe,IAGlDvB,EAAUC,UAAU0B,kBAAoB,SAAU+B,GAC9C,GAAIC,GAAQ/D,KAAKmB,GAAGW,YAAYgC,EAAQnC,UAAWmC,EAAQ9B,OAI3D,OAHA+B,GAAM1C,QAAUyC,EAAQtC,MACxBuC,EAAMC,WAAaF,EAAQ7B,SAC3B8B,EAAME,QAAUH,EAAQb,MACjBc,GAEJ3D,IAEXT,SAAQS,UAAYA","file":"angular2-indexeddb.min.js"} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | angular2-indexeddb 2 | ============== 3 | 4 | angular2-indexeddb is a service that wraps IndexedDB database in an Angular service. 5 | It exposes very simple promises API to enable the usage of IndexedDB without most of it plumbing. 6 | 7 | Copyright (C) 2017, Gil Fink 8 | 9 | Installation 10 | ------------ 11 | 12 | You can choose your preferred method of installation: 13 | * Download from npm: 14 | ``` 15 | npm install angular2-indexeddb 16 | ``` 17 | * Download from github: [angular2-indexeddb.min.js](https://github.com/gilf/angular2-indexeddb/blob/master/angular2-indexeddb.min.js) 18 | 19 | Usage 20 | ----- 21 | Include **angular2-indexeddb.js** in your application. 22 | 23 | ```html 24 | 25 | ``` 26 | 27 | Import the the `AngularIndexedDB` class as a dependency: 28 | 29 | ```js 30 | import {AngularIndexedDB} from 'angular2-indexeddb'; 31 | ``` 32 | 33 | ### AngularIndexedDB service 34 | First instantiate the service as follows: 35 | ```js 36 | let db = new AngularIndexedDB('myDb', 1); 37 | ``` 38 | The first argument is the name of your database and the second is the database version. 39 | If you forget the version you the service will default to version 1. 40 | 41 | Use the APIs that the AngularIndexedDB service exposes to use indexeddb. 42 | In the API the following functions: 43 | * openDatabase(version, createCallback): opens the database for usage and update it's objectStore/s. 44 | The first parameter is the version to upgrade the database and the second one is an optional callback that will handle the creation of objectStores for that version if needed. 45 | **openDatabase** returns a promise that is resolved when the database is open or updated or rejected if an error occurred. 46 | 47 | Usage example: 48 | 49 | ```js 50 | db.openDatabase(1, (evt) => { 51 | let objectStore = evt.currentTarget.result.createObjectStore( 52 | 'people', { keyPath: "id", autoIncrement: true }); 53 | 54 | objectStore.createIndex("name", "name", { unique: false }); 55 | objectStore.createIndex("email", "email", { unique: true }); 56 | }); 57 | ``` 58 | * getByKey(storeName, key): returns the object that is stored in the objectStore by its key. 59 | The first parameter is the store name to query and the second one is the object's key. 60 | **getByKey** returns a promise that is resolved when we have the object or rejected if an error occurred. 61 | 62 | Usage example: 63 | 64 | ```js 65 | db.getByKey('people', 1).then((person) => { 66 | console.log(person); 67 | }, (error) => { 68 | console.log(error); 69 | }); 70 | ``` 71 | 72 | * getAll(storeName, keyRange, indexDetails): returns an array of all the items in the given objectStore. 73 | The first parameter is the store name to query. 74 | The second parameter is an optional IDBKeyRange object. 75 | The third parameter is an index details which must include index name and an optional order parameter. 76 | **getAll** returns a promise that is resolved when we have the array of items or rejected if an error occurred. 77 | 78 | Usage example: 79 | 80 | ```js 81 | db.getAll('people').then((people) => { 82 | console.log(people); 83 | }, (error) => { 84 | console.log(error); 85 | }); 86 | ``` 87 | 88 | * getByIndex(storeName, indexName, key): returns an stored item using an objectStore's index. 89 | The first parameter is the store name to query, the second parameter is the index and third parameter is the item to query. 90 | **getByIndex** returns a promise that is resolved when the item successfully returned or rejected if an error occurred. 91 | 92 | Usage example: 93 | 94 | ```js 95 | db.getByIndex('people', 'name', 'Dave').then((person) => { 96 | console.log(person); 97 | }, (error) => { 98 | console.log(error); 99 | }); 100 | ``` 101 | 102 | * add(storeName, value, key): Adds to the given objectStore the key and value pair. 103 | The first parameter is the store name to modify, the second parameter is the value and the third parameter is the key (if not auto-generated). 104 | **add** returns a promise that is resolved when the value was added or rejected if an error occurred. 105 | 106 | Usage example (add without a key): 107 | 108 | ```js 109 | db.add('people', { name: 'name', email: 'email' }).then(() => { 110 | // Do something after the value was added 111 | }, (error) => { 112 | console.log(error); 113 | }); 114 | ``` 115 | In the previous example I'm using undefined as the key because the key is configured in the objectStore as auto-generated. 116 | 117 | * update(storeName, value, key?): Updates the given value in the objectStore. 118 | The first parameter is the store name to modify, the second parameter is the value to update and the third parameter is the key (if there is no key don't provide it). 119 | **update** returns a promise that is resolved when the value was updated or rejected if an error occurred. 120 | 121 | Usage example (update without a key): 122 | 123 | ```js 124 | db.update('people', { id: 3, name: 'name', email: 'email' }).then(() => { 125 | // Do something after update 126 | }, (error) => { 127 | console.log(error); 128 | }); 129 | ``` 130 | 131 | * delete(storeName, key): deletes the object that correspond with the key from the objectStore. 132 | The first parameter is the store name to modify and the second parameter is the key to delete. 133 | **delete** returns a promise that is resolved when the value was deleted or rejected if an error occurred. 134 | 135 | Usage example: 136 | 137 | ```js 138 | db.delete('people', 3).then(() => { 139 | // Do something after delete 140 | }, (error) => { 141 | console.log(error); 142 | }); 143 | ``` 144 | 145 | * openCursor(storeName, cursorCallback, keyRange): opens an objectStore cursor to enable iterating on the objectStore. 146 | The first parameter is the store name, the second parameter is a callback function to run when the cursor succeeds to be opened and the third parameter is optional IDBKeyRange object. 147 | **openCursor** returns a promise that is resolved when the cursor finishes running or rejected if an error occurred. 148 | 149 | Usage example: 150 | 151 | ```js 152 | db.openCursor('people', (evt) => { 153 | var cursor = (evt.target).result; 154 | if(cursor) { 155 | console.log(cursor.value); 156 | cursor.continue(); 157 | } else { 158 | console.log('Entries all displayed.'); 159 | } 160 | }, IDBKeyRange.bound("A", "F")); 161 | 162 | ``` 163 | 164 | * clear(storeName): clears all the data in an objectStore. 165 | The first parameter is the store name to clear. 166 | **clear** returns a promise that is resolved when the objectStore was cleared or rejected if an error occurred. 167 | 168 | Usage example: 169 | 170 | ```js 171 | db.clear('people').then(() => { 172 | // Do something after clear 173 | }, (error) => { 174 | console.log(error); 175 | }); 176 | 177 | ``` 178 | 179 | License 180 | ---- 181 | 182 | Released under the terms of the [MIT License](LICENSE). 183 | -------------------------------------------------------------------------------- /angular2-indexeddb.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"angular2-indexeddb.js","sourceRoot":"","sources":["angular2-indexeddb.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;IAII,0BAAY,MAAc,EAAE,OAAe;QACvC,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,uCAAY,GAAZ,UAAa,OAAe,EAAE,eAA0B;QAAxD,iBAsBC;QArBG,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,MAAM,CAAC,IAAI,OAA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AqF,CAAC,CAAC;QAClG,CAAC;QACD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACrC,MAAM,CAAC,CAAC,+BAA+B,GAAG,SAAS,CAAC,CAAC,CAAC;QAC1D,CAAC;IACL,CAAC;IAED,qCAAiB,GAAjB,UAAkB,OAA2I;QACzJ,IAAI,KAAK,GAAmB,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACnF,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9B,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;QACpC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IACL,gBAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,8BAAS"} -------------------------------------------------------------------------------- /angular2-indexeddb.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var AngularIndexedDB = /** @class */ (function () { 4 | function AngularIndexedDB(dbName, version) { 5 | this.utils = new Utils(); 6 | this.dbWrapper = new DbWrapper(dbName, version); 7 | } 8 | AngularIndexedDB.prototype.openDatabase = function (version, upgradeCallback) { 9 | var _this = this; 10 | var self = this; 11 | return new Promise(function (resolve, reject) { 12 | _this.dbWrapper.dbVersion = version; 13 | var request = _this.utils.indexedDB.open(_this.dbWrapper.dbName, version); 14 | request.onsuccess = function (e) { 15 | self.dbWrapper.db = request.result; 16 | resolve(); 17 | }; 18 | request.onerror = function (e) { 19 | reject('IndexedDB error: ' + e.target.errorCode ? 20 | e.target.errorCode + ' (' + e.target.error + ')' : 21 | e.target.errorCode); 22 | }; 23 | if (typeof upgradeCallback === "function") { 24 | request.onupgradeneeded = function (e) { 25 | upgradeCallback(e, self.dbWrapper.db); 26 | }; 27 | } 28 | }); 29 | }; 30 | AngularIndexedDB.prototype.getByKey = function (storeName, key) { 31 | var self = this; 32 | return new Promise(function (resolve, reject) { 33 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 34 | var transaction = self.dbWrapper.createTransaction({ storeName: storeName, 35 | dbMode: "readonly", 36 | error: function (e) { 37 | reject(e); 38 | }, 39 | complete: function (e) { 40 | } 41 | }), objectStore = transaction.objectStore(storeName), request; 42 | request = objectStore.get(key); 43 | request.onsuccess = function (event) { 44 | resolve(event.target.result); 45 | }; 46 | }); 47 | }; 48 | AngularIndexedDB.prototype.getAll = function (storeName, keyRange, indexDetails) { 49 | var self = this; 50 | return new Promise(function (resolve, reject) { 51 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 52 | var transaction = self.dbWrapper.createTransaction({ storeName: storeName, 53 | dbMode: "readonly", 54 | error: function (e) { 55 | reject(e); 56 | }, 57 | complete: function (e) { 58 | } 59 | }), objectStore = transaction.objectStore(storeName), result = [], request; 60 | if (indexDetails) { 61 | var index = objectStore.index(indexDetails.indexName), order = (indexDetails.order === 'desc') ? 'prev' : 'next'; 62 | request = index.openCursor(keyRange, order); 63 | } 64 | else { 65 | request = objectStore.openCursor(keyRange); 66 | } 67 | request.onerror = function (e) { 68 | reject(e); 69 | }; 70 | request.onsuccess = function (evt) { 71 | var cursor = evt.target.result; 72 | if (cursor) { 73 | result.push(cursor["value"]); 74 | cursor["continue"](); 75 | } 76 | else { 77 | resolve(result); 78 | } 79 | }; 80 | }); 81 | }; 82 | AngularIndexedDB.prototype.add = function (storeName, value, key) { 83 | var self = this; 84 | return new Promise(function (resolve, reject) { 85 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 86 | var transaction = self.dbWrapper.createTransaction({ storeName: storeName, 87 | dbMode: "readwrite", 88 | error: function (e) { 89 | reject(e); 90 | }, 91 | complete: function (e) { 92 | resolve({ key: key, value: value }); 93 | } 94 | }), objectStore = transaction.objectStore(storeName); 95 | var request = objectStore.add(value, key); 96 | request.onsuccess = function (evt) { 97 | key = evt.target.result; 98 | }; 99 | }); 100 | }; 101 | AngularIndexedDB.prototype.update = function (storeName, value, key) { 102 | var self = this; 103 | return new Promise(function (resolve, reject) { 104 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 105 | var transaction = self.dbWrapper.createTransaction({ storeName: storeName, 106 | dbMode: "readwrite", 107 | error: function (e) { 108 | reject(e); 109 | }, 110 | complete: function (e) { 111 | resolve(value); 112 | }, 113 | abort: function (e) { 114 | reject(e); 115 | } 116 | }), objectStore = transaction.objectStore(storeName); 117 | objectStore.put(value, key); 118 | }); 119 | }; 120 | AngularIndexedDB.prototype.delete = function (storeName, key) { 121 | var self = this; 122 | return new Promise(function (resolve, reject) { 123 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 124 | var transaction = self.dbWrapper.createTransaction({ storeName: storeName, 125 | dbMode: "readwrite", 126 | error: function (e) { 127 | reject(e); 128 | }, 129 | complete: function (e) { 130 | resolve(); 131 | }, 132 | abort: function (e) { 133 | reject(e); 134 | } 135 | }), objectStore = transaction.objectStore(storeName); 136 | objectStore["delete"](key); 137 | }); 138 | }; 139 | AngularIndexedDB.prototype.openCursor = function (storeName, cursorCallback, keyRange) { 140 | var self = this; 141 | return new Promise(function (resolve, reject) { 142 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 143 | var transaction = self.dbWrapper.createTransaction({ storeName: storeName, 144 | dbMode: "readonly", 145 | error: function (e) { 146 | reject(e); 147 | }, 148 | complete: function (e) { 149 | resolve(); 150 | }, 151 | abort: function (e) { 152 | reject(e); 153 | } 154 | }), objectStore = transaction.objectStore(storeName), request = objectStore.openCursor(keyRange); 155 | request.onsuccess = function (evt) { 156 | cursorCallback(evt); 157 | resolve(); 158 | }; 159 | }); 160 | }; 161 | AngularIndexedDB.prototype.clear = function (storeName) { 162 | var self = this; 163 | return new Promise(function (resolve, reject) { 164 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 165 | var transaction = self.dbWrapper.createTransaction({ storeName: storeName, 166 | dbMode: "readwrite", 167 | error: function (e) { 168 | reject(e); 169 | }, 170 | complete: function (e) { 171 | resolve(); 172 | }, 173 | abort: function (e) { 174 | reject(e); 175 | } 176 | }), objectStore = transaction.objectStore(storeName); 177 | objectStore.clear(); 178 | resolve(); 179 | }); 180 | }; 181 | AngularIndexedDB.prototype.getByIndex = function (storeName, indexName, key) { 182 | var self = this; 183 | return new Promise(function (resolve, reject) { 184 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 185 | var transaction = self.dbWrapper.createTransaction({ storeName: storeName, 186 | dbMode: "readonly", 187 | error: function (e) { 188 | reject(e); 189 | }, 190 | abort: function (e) { 191 | reject(e); 192 | }, 193 | complete: function (e) { 194 | } 195 | }), objectStore = transaction.objectStore(storeName), index = objectStore.index(indexName), request = index.get(key); 196 | request.onsuccess = function (event) { 197 | resolve(event.target.result); 198 | }; 199 | }); 200 | }; 201 | return AngularIndexedDB; 202 | }()); 203 | exports.AngularIndexedDB = AngularIndexedDB; 204 | var Utils = /** @class */ (function () { 205 | function Utils() { 206 | this.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; 207 | } 208 | return Utils; 209 | }()); 210 | exports.Utils = Utils; 211 | var DbWrapper = /** @class */ (function () { 212 | function DbWrapper(dbName, version) { 213 | this.dbName = dbName; 214 | this.dbVersion = version || 1; 215 | this.db = null; 216 | } 217 | DbWrapper.prototype.validateStoreName = function (storeName) { 218 | return this.db.objectStoreNames.contains(storeName); 219 | }; 220 | ; 221 | DbWrapper.prototype.validateBeforeTransaction = function (storeName, reject) { 222 | if (!this.db) { 223 | reject('You need to use the openDatabase function to create a database before you query it!'); 224 | } 225 | if (!this.validateStoreName(storeName)) { 226 | reject(('objectStore does not exists: ' + storeName)); 227 | } 228 | }; 229 | DbWrapper.prototype.createTransaction = function (options) { 230 | var trans = this.db.transaction(options.storeName, options.dbMode); 231 | trans.onerror = options.error; 232 | trans.oncomplete = options.complete; 233 | trans.onabort = options.abort; 234 | return trans; 235 | }; 236 | return DbWrapper; 237 | }()); 238 | exports.DbWrapper = DbWrapper; 239 | //# sourceMappingURL=angular2-indexeddb.js.map -------------------------------------------------------------------------------- /angular2-indexeddb.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export class AngularIndexedDB { 4 | utils: Utils; 5 | dbWrapper: DbWrapper; 6 | 7 | constructor(dbName: string, version: number) { 8 | this.utils = new Utils(); 9 | this.dbWrapper = new DbWrapper(dbName, version); 10 | } 11 | 12 | openDatabase(version: number, upgradeCallback?: Function) { 13 | let self = this; 14 | return new Promise((resolve, reject)=> { 15 | this.dbWrapper.dbVersion = version; 16 | let request = this.utils.indexedDB.open(this.dbWrapper.dbName, version); 17 | request.onsuccess = function (e) { 18 | self.dbWrapper.db = request.result; 19 | resolve(); 20 | }; 21 | 22 | request.onerror = function (e) { 23 | reject('IndexedDB error: ' + (e.target).errorCode ? 24 | (e.target).errorCode + ' (' + (e.target).error + ')' : 25 | (e.target).errorCode); 26 | }; 27 | 28 | if (typeof upgradeCallback === "function") { 29 | request.onupgradeneeded = function (e) { 30 | upgradeCallback(e, self.dbWrapper.db); 31 | }; 32 | } 33 | }); 34 | } 35 | 36 | getByKey(storeName: string, key: any) { 37 | let self = this; 38 | return new Promise((resolve, reject)=> { 39 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 40 | 41 | let transaction = self.dbWrapper.createTransaction({ storeName: storeName, 42 | dbMode: "readonly", 43 | error: (e: Event) => { 44 | reject(e); 45 | }, 46 | complete: (e: Event) => { 47 | } 48 | }), 49 | objectStore = transaction.objectStore(storeName), 50 | request: IDBRequest; 51 | 52 | request = objectStore.get(key); 53 | request.onsuccess = function (event: Event) { 54 | resolve((event.target).result); 55 | } 56 | }); 57 | } 58 | 59 | getAll(storeName: string, keyRange?: IDBKeyRange, indexDetails?: IndexDetails) { 60 | let self = this; 61 | return new Promise((resolve, reject)=> { 62 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 63 | 64 | let transaction = self.dbWrapper.createTransaction({ storeName: storeName, 65 | dbMode: "readonly", 66 | error: (e: Event) => { 67 | reject(e); 68 | }, 69 | complete: (e: Event) => { 70 | } 71 | }), 72 | objectStore = transaction.objectStore(storeName), 73 | result: Array = [], 74 | request: IDBRequest; 75 | if(indexDetails) { 76 | let index = objectStore.index(indexDetails.indexName), 77 | order = (indexDetails.order === 'desc') ? 'prev' : 'next'; 78 | request = index.openCursor(keyRange, order); 79 | } 80 | else { 81 | request = objectStore.openCursor(keyRange); 82 | } 83 | 84 | request.onerror = function (e) { 85 | reject(e); 86 | }; 87 | 88 | request.onsuccess = function (evt: Event) { 89 | let cursor = (evt.target).result; 90 | if (cursor) { 91 | result.push(cursor["value"]); 92 | cursor["continue"](); 93 | } else { 94 | resolve(result); 95 | } 96 | }; 97 | }); 98 | } 99 | 100 | add(storeName: string, value: any, key?: any) { 101 | let self = this; 102 | return new Promise((resolve, reject)=> { 103 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 104 | 105 | let transaction = self.dbWrapper.createTransaction({ storeName: storeName, 106 | dbMode: "readwrite", 107 | error: (e: Event) => { 108 | reject(e); 109 | }, 110 | complete: (e: Event) => { 111 | resolve({ key: key, value: value }); 112 | } 113 | }), 114 | objectStore = transaction.objectStore(storeName); 115 | 116 | let request = objectStore.add(value, key); 117 | request.onsuccess = (evt: any) => { 118 | key = evt.target.result; 119 | } 120 | }); 121 | } 122 | 123 | update(storeName: string, value: any, key?: any) { 124 | let self = this; 125 | return new Promise((resolve, reject)=> { 126 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 127 | 128 | let transaction = self.dbWrapper.createTransaction({ storeName: storeName, 129 | dbMode: "readwrite", 130 | error: (e: Event) => { 131 | reject(e); 132 | }, 133 | complete: (e: Event) => { 134 | resolve(value); 135 | }, 136 | abort: (e: Event) => { 137 | reject(e); 138 | } 139 | }), 140 | objectStore = transaction.objectStore(storeName); 141 | 142 | objectStore.put(value, key); 143 | }); 144 | } 145 | 146 | delete(storeName: string, key: any) { 147 | let self = this; 148 | return new Promise((resolve, reject)=> { 149 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 150 | 151 | let transaction = self.dbWrapper.createTransaction({ storeName: storeName, 152 | dbMode: "readwrite", 153 | error: (e: Event) => { 154 | reject(e); 155 | }, 156 | complete: (e: Event) => { 157 | resolve(); 158 | }, 159 | abort: (e: Event) => { 160 | reject(e); 161 | } 162 | }), 163 | objectStore = transaction.objectStore(storeName); 164 | 165 | objectStore["delete"](key); 166 | }); 167 | } 168 | 169 | openCursor(storeName: string, cursorCallback: (evt: Event) => void, keyRange?: IDBKeyRange) { 170 | let self = this; 171 | return new Promise((resolve, reject)=> { 172 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 173 | 174 | let transaction = self.dbWrapper.createTransaction({ storeName: storeName, 175 | dbMode: "readonly", 176 | error: (e: Event) => { 177 | reject(e); 178 | }, 179 | complete: (e: Event) => { 180 | resolve(); 181 | }, 182 | abort: (e: Event) => { 183 | reject(e); 184 | } 185 | }), 186 | objectStore = transaction.objectStore(storeName), 187 | request = objectStore.openCursor(keyRange); 188 | 189 | request.onsuccess = (evt: Event) => { 190 | cursorCallback(evt); 191 | resolve(); 192 | }; 193 | }); 194 | } 195 | 196 | clear(storeName: string) { 197 | let self = this; 198 | return new Promise((resolve, reject)=> { 199 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 200 | 201 | let transaction = self.dbWrapper.createTransaction({ storeName: storeName, 202 | dbMode: "readwrite", 203 | error: (e: Event) => { 204 | reject(e); 205 | }, 206 | complete: (e: Event) => { 207 | resolve(); 208 | }, 209 | abort: (e: Event) => { 210 | reject(e); 211 | } 212 | }), 213 | objectStore = transaction.objectStore(storeName); 214 | objectStore.clear(); 215 | resolve(); 216 | }); 217 | } 218 | 219 | getByIndex(storeName: string, indexName: string, key: any) { 220 | let self = this; 221 | return new Promise((resolve, reject)=> { 222 | self.dbWrapper.validateBeforeTransaction(storeName, reject); 223 | 224 | let transaction = self.dbWrapper.createTransaction({ storeName: storeName, 225 | dbMode: "readonly", 226 | error: (e: Event) => { 227 | reject(e); 228 | }, 229 | abort: (e: Event) => { 230 | reject(e); 231 | }, 232 | complete: (e: Event) => { 233 | } 234 | }), 235 | objectStore = transaction.objectStore(storeName), 236 | index = objectStore.index(indexName), 237 | request = index.get(key); 238 | 239 | request.onsuccess = (event) => { 240 | resolve((event.target).result); 241 | }; 242 | }); 243 | } 244 | } 245 | 246 | export class Utils { 247 | indexedDB: IDBFactory; 248 | 249 | constructor() { 250 | this.indexedDB = window.indexedDB || (window).mozIndexedDB || (window).webkitIndexedDB || (window).msIndexedDB; 251 | } 252 | } 253 | 254 | export interface IndexDetails { 255 | indexName: string; 256 | order: string; 257 | } 258 | 259 | export class DbWrapper { 260 | dbName: string; 261 | dbVersion: number; 262 | db: IDBDatabase; 263 | 264 | constructor(dbName: string, version: number) { 265 | this.dbName = dbName; 266 | this.dbVersion = version || 1; 267 | this.db = null; 268 | } 269 | 270 | validateStoreName(storeName: string) { 271 | return this.db.objectStoreNames.contains(storeName); 272 | }; 273 | 274 | validateBeforeTransaction(storeName: string, reject: Function) { 275 | if (!this.db) { 276 | reject('You need to use the openDatabase function to create a database before you query it!'); 277 | } 278 | if (!this.validateStoreName(storeName)) { 279 | reject(('objectStore does not exists: ' + storeName)); 280 | } 281 | } 282 | 283 | createTransaction(options: { storeName: string, dbMode: IDBTransactionMode, error: (e: Event) => any, complete: (e: Event) => any, abort?: (e:Event) => any }): IDBTransaction { 284 | let trans: IDBTransaction = this.db.transaction(options.storeName, options.dbMode); 285 | trans.onerror = options.error; 286 | trans.oncomplete = options.complete; 287 | trans.onabort = options.abort; 288 | return trans; 289 | } 290 | } 291 | --------------------------------------------------------------------------------