]> hackdaworld.org Git - outofuni/jsutils.git/commitdiff
increase verbosity + only execute callback during update if defined
authorhackbard <hackbard@hackdaworld.org>
Wed, 4 May 2016 20:30:37 +0000 (22:30 +0200)
committerhackbard <hackbard@hackdaworld.org>
Wed, 4 May 2016 20:30:37 +0000 (22:30 +0200)
idb.js

diff --git a/idb.js b/idb.js
index 20d5ea4c424dc19a5426af5e5f75e703af47975b..2e4c9e9ed3a2a15d71ebdaea2b74724bba0b7161 100644 (file)
--- a/idb.js
+++ b/idb.js
@@ -25,7 +25,8 @@ var idb = {
                                var store=idb.stores[sn]
                                var key={};
                                key[store['keytype']]=store['keyname'];
-                               cl("idb: creating store '"+sn+"'");
+                               cl("idb: creating store '"+sn+"' ("+
+                                  store.keytype+": "+store.keyname+")");
                                store.os=idb.handle.createObjectStore(sn,key);
                                // indices
                                if(store.idx!==undefined) {
@@ -87,6 +88,7 @@ var idb = {
                        idb.successcb=successcb;
                if(upgradecb!==undefined)
                        idb.onupgradeneeded=upgradecb;
+               cl("idb: init database '"+idb.name+"'");
                var req=indexedDB.open(idb.name,idb.version);
                req.onsuccess=idb.onsuccess;
                req.onupgradeneeded=idb.onupgradeneeded;
@@ -165,7 +167,8 @@ var idb = {
                                var res=cursor.update(nitem);
                                res.onsuccess=function(event) {
                                        cl("idb: updated cursor");
-                                       callback(event);
+                                       if(callback!==undefined)
+                                               callback(event);
                                };
                                res.onerror=function(error) {
                                        cl("idb: cursor update error");
@@ -177,7 +180,8 @@ var idb = {
                                var addreq=store.add(nitem,num);
                                addreq.onsuccess=function(event) {
                                        cl("idb: added (update mode) key "+num);
-                                       callback(event);
+                                       if(callback!==undefined)
+                                               callback(event);
                                }
                                addreq.onerror=function(error) {
                                        cl("idb: error add (update mode)");