[READ-ONLY] Mirror of https://github.com/andrioid/chrome-worklogger. Allows you to log hours from the safety of your browser. Nags you if you dont. chrome.google.com/webstore/detail/work-logger/mpoffelgmlfgkmnpmfdiljpkbbdmokpb
0

Configure Feed

Select the types of activity you want to include in your feed.

chrome-worklogger / src / dbwrapper.js
2.4 kB 90 lines
1 2var dbw = {}; // namespace 3var db; // internal db handler 4var osname = "worklog" 5 6dbw.init = function(success, error) { 7 var openRequest = indexedDB.open("worklogger",1); 8 9 openRequest.onupgradeneeded = function(e) { 10 console.log("Creating Object Store with Indexes"); 11 12 var thisDb = e.target.result; 13 14 //uncomment for quick testing 15 //thisDb.deleteObjectStore("worklog"); 16 17 //Create objectStore 18 if(!thisDb.objectStoreNames.contains(osname)) { 19 var objectStore = thisDb.createObjectStore(osname, { keyPath: "id", autoIncrement:true }); 20 objectStore.createIndex("date","date", {unique:false}); 21 objectStore.createIndex("tags","tags", {unique:false,multiEntry:true}); 22 } 23 24 } 25 26 openRequest.onsuccess = function(e) { 27 28 db = e.target.result; 29 if (success) success(); 30 31 db.onerror = function(event) { 32 // Generic error handler for all errors targeted at this database's 33 // requests! 34 console.log("Database error: " + event.target.errorCode); 35 console.dir(event.target); 36 }; 37 } 38 39}; 40 41/** 42 * All dates are YYYY-MM-DD 43 */ 44dbw.getByDate = function(from, to) { 45 46} 47 48dbw.addData = function(dataobj, success) { 49 var transaction = db.transaction([osname], "readwrite"); 50 var objectStore = transaction.objectStore(osname); 51 var req = objectStore.add(dataobj); 52 req.onsuccess = function() { 53 if (success) success(); 54 //console.log("Data added"); 55 }; 56 req.onerror = function(e) { 57 console.err("Add DB error: " + e); 58 } 59} 60 61dbw.getAll = function(success) { 62 var transaction = db.transaction([osname], "readonly"); 63 var objectStore = transaction.objectStore(osname); 64 var request = objectStore.openCursor(); 65 var results = []; 66 67 request.onsuccess = function(event) { 68 var cursor = event.target.result; 69 if(cursor) { 70 results.push(cursor.value); 71 //console.log(cursor.key); 72 //console.log(cursor.value); 73 cursor.continue(); 74 } else { 75 if (success) success(results); 76 } 77 } 78} 79 80dbw.delItem = function (id, cb) { 81 var request = db.transaction([osname], "readwrite") 82 .objectStore(osname) 83 .delete(id); 84 request.onsuccess = function(event) { 85 if (cb) cb(); 86 }; 87} 88 89 90module.exports = dbw;