-
Notifications
You must be signed in to change notification settings - Fork 2
/
SDB-min.js
1 lines (1 loc) · 2.74 KB
/
SDB-min.js
1
window.sdb=window.sdb||function(){function e(e,t){this.req,this.db,this.transaction;this.req=indexedDB.open(e.db||e,e.v||!"");this.req.onsuccess=function(e){this.db=e.target.result;t(this.db)};this.req.onerror=function(e){console.log("IndexedDB error: "+e.target.errorCode)};if(e.constructor===Object){this.req.onupgradeneeded=function(t){function s(e){for(var t in e){r.createIndex(e[t].index,e[t].index,e[t].opts)}}var n=e.upgrade.stores,r;for(var i in n){r=t.currentTarget.result.createObjectStore(n[i].name,n[i].opts);s(n[i].indices)}}}return{req:this.req,tr:this.trans,store:this.store,add:this.add,put:this.put,del:this.del,get:this.get,cursor:this.cursor,count:this.count,clear:this.clear,index:this.index,deleteIndex:this.deleteIndex}}e.prototype=function(){function n(t,n,r){e=t.transaction(n,r);return this}function r(n){e&&(t=e.objectStore(n));return this}function i(e,n){var r,i=((e&&t.add(e)).onsuccess=function(e){r=e.target.result;n&&n(r);return i}).onerror=function(e){console.log("PUT ERROR!",e);return i};return this}function s(e,n){var r,i;i=e&&t.put(e);i.onsuccess=function(e){console.log("PUT.onsuccess",e);r=e.target.result;n&&n(r);return i};i.onerror=function(e){console.log("PUT ERROR!",e);return i};return this}function o(e,n){var r,i=((e&&t.get(e)).onsuccess=function(e){r=e.target.source;n&&n(r);return i}).onerror=function(e){console.log("GET ERROR!",e);return i};return this}function u(e){console.log("hit DELETE function, keyPath",e&&e||"NO keyPath");e&&t.delete(e);return this}function a(e,n){var r,i,s,o=[],u;!n&&function(){u=t.openCursor()}()||n&&function(){n.constructor===Object&&function(){i=n.bound&&IDBKeyRange.bound(n.bound[0],n.bound[1],n.bound[2]&&n.bound[2],n.bound[3]&&n.bound[3]);s=n.direction&&n.direction;s&&(u=t.openCursor(i,s))||(u=t.openCursor(i))}()||n.constructor===Number&&function(){i=n&&n;u=t.openCursor(i)}()}();u.onsuccess=function(t){r=t.target.result;if(r){o.push(r.value);e(r.value,r)}};return this}function f(){console.log("hit count function");return this}function l(){console.log("hit CLEAR function");return this}function c(e){function i(e,t){n.get(e).onsuccess=function(e){var n=e.target.result;t(n)};return this}function s(e){var t,r=[],i=n.openCursor();i.onsuccess=function(n){t=n.target.result;t&&function(){r.push(t.value);e(t.value);t.continue()}()};return this}function o(e){var t,r=[],i=n.openCursor();i.onsuccess=function(n){t=n.target.result;t&&function(){r.push(t.value);e(t.value);t.continue()}()};return this}console.log("hit index function");var n,r;t&&e&&(n=t.index(e));return{get:i,openCursor:s,openKeyCursor:o}}function h(){console.log("hit deleteIndex function");return this}var e,t;return{trans:n,store:r,add:i,put:s,del:u,get:o,cursor:a,count:f,clear:l,index:c,deleteIndex:h}}();return{req:function(t,n){return new e(t,n)}}}()