Line 53: |
Line 53: |
| } | | } |
| */ | | */ |
− |
| |
| | | |
| //|||||||||||||||||||||[ db objects ]||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | | //|||||||||||||||||||||[ db objects ]||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | | |
| | | |
− | var personalDB = {}; | + | var personal = {}; |
| var indexedDB = window.indexedDB ; | | var indexedDB = window.indexedDB ; |
| var indexedDBVersion = "2"; | | var indexedDBVersion = "2"; |
| var Pete = {id: '11345', name: {first: "Pete", last: "Rock"}, age: '52'}; | | var Pete = {id: '11345', name: {first: "Pete", last: "Rock"}, age: '52'}; |
| | | |
− | personalDB.indexedDB = {}; | + | personal.indexedDB = {}; |
− | personalDB.indexedDB.db = null; | + | personal.indexedDB.db = null; |
| | | |
| | | |
Line 70: |
Line 69: |
| | | |
| | | |
− | personalDB.indexedDB.onerror = function(arr){ | + | personal.indexedDB.onerror = function(arr){ |
| console.log(arr); | | console.log(arr); |
| } | | } |
Line 78: |
Line 77: |
| | | |
| | | |
− | personalDB.indexedDB.open = function(){ | + | personal.indexedDB.open = function(){ |
| // open database of | | // open database of |
| var request = indexedDB.open("personalDataIO"); | | var request = indexedDB.open("personalDataIO"); |
Line 84: |
Line 83: |
| request.onsuccess = function(e){ | | request.onsuccess = function(e){ |
| // | | // |
− | personalDB.indexedDB.db = e.target.result; | + | personal.indexedDB.db = e.target.result; |
− | var db = personalDB.indexedDB.db; | + | var db = personal.indexedDB.db; |
| | | |
| //object stores are created in setVersion transactions | | //object stores are created in setVersion transactions |
Line 92: |
Line 91: |
| | | |
| //object store is created onsuccess | | //object store is created onsuccess |
− | setDBVersion.onerror = personalDB.indexedDB.onerror; | + | setDBVersion.onerror = personal.indexedDB.onerror; |
| | | |
| setDBVersion.onsuccess = function(e){ | | setDBVersion.onsuccess = function(e){ |
Line 101: |
Line 100: |
| } | | } |
| store.createIndex("NameIndex", ["name.last", "name.first"]); | | store.createIndex("NameIndex", ["name.last", "name.first"]); |
− | personalDB.indexedDB.recordAll(); | + | personal.indexedDB.recordAll(); |
| }; | | }; |
| }else{ | | }else{ |
− | personalDB.indexedDB.recordAll(); | + | personal.indexedDB.recordAll(); |
| } | | } |
| }; | | }; |
− | request.onerror = personalDB.indexedDB.onerror; | + | request.onerror = personal.indexedDB.onerror; |
| };//end open | | };//end open |
| | | |
Line 115: |
Line 114: |
| | | |
| //add Items | | //add Items |
− | personalDB.indexedDB.recordAdd = function(recordObject){ | + | personal.indexedDB.recordAdd = function(recordObject){ |
− | console.log('Creating record: '+entryTxt);
| + | var db = personal.indexedDB.db; |
− | var db = personalDB.indexedDB.db; | |
| var trans = db.transaction(["personalDataIO"],IDBTransaction.READ_WRITE); | | var trans = db.transaction(["personalDataIO"],IDBTransaction.READ_WRITE); |
| var store = trans.objectStore("personalDataIO"); | | var store = trans.objectStore("personalDataIO"); |
Line 123: |
Line 121: |
| | | |
| request.onsuccess = function(e){ | | request.onsuccess = function(e){ |
− | personalDB.indexedDB.recordAll(); | + | personal.indexedDB.recordAll(); |
| }; | | }; |
| request.onerror = function(e){ | | request.onerror = function(e){ |
Line 134: |
Line 132: |
| | | |
| //get Items | | //get Items |
− | personalDB.indexedDB.recordAppend = function(Uname, field, value){ | + | personal.indexedDB.recordAppend = function(Uname, field, value){ |
| | | |
− | var db = personalDB.indexedDB.db; | + | var db = personal.indexedDB.db; |
| var trans = db.transaction("personalDataIO"); | | var trans = db.transaction("personalDataIO"); |
| var store = trans.objectStore("personalDataIO"); | | var store = trans.objectStore("personalDataIO"); |
Line 151: |
Line 149: |
| | | |
| function init() { | | function init() { |
− | personalDB.indexedDB.open(); | + | personal.indexedDB.open(); |
| } | | } |
| | | |
| //||||||||||||||||||||||||||||||[ Get Record by name]|||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | | //||||||||||||||||||||||||||||||[ Get Record by name]|||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| | | |
− | personalDB.indexedDB.recordGet = function(uname) { | + | personal.indexedDB.recordGet = function(uname) { |
− | var db = personalDB.indexedDB.db; | + | var db = personal.indexedDB.db; |
| var trans = db.transaction("personalDataIO"); | | var trans = db.transaction("personalDataIO"); |
| var store = trans.objectStore("personalDataIO"); | | var store = trans.objectStore("personalDataIO"); |
Line 179: |
Line 177: |
| init(); | | init(); |
| | | |
− | personalDB.indexedDB.recordAdd(Pete); | + | personal.indexedDB.recordAdd(Pete); |
− | personalDB.indexedDB.recordAppend(["Pete", "Rock"], 'telephone', '+123-XXX'); | + | personal.indexedDB.recordAppend(["Pete", "Rock"], 'telephone', '+123-XXX'); |
− | personalDB.indexedDB.recordGet(["Pete", "Rock"]); | + | personal.indexedDB.recordGet(["Pete", "Rock"]); |