Guest User

Clearing namespaces with IDBWrapper

a guest
Feb 27th, 2014
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function clearBranch(branch) {
  2.     if (typeof branch === 'undefined' || branch === null)
  3.         branch = '';
  4.     branch = String(branch);
  5.     var options = {
  6.         onEnd: function() {
  7.             console.log('branch "' + branch + '" cleared');
  8.         },
  9.         writeAccess: true
  10.     };
  11.     if (branch !== '') {
  12.         options.keyRange = idbStore.makeKeyRange({
  13.             lower: branch + '.', // charCode 46
  14.             upper: branch + '/', // charCode 47
  15.             excludeUpper: true
  16.         });
  17.     }
  18.     idbStore.iterate(function(item, cursor) {
  19.         cursor.delete();
  20.     }, options);
  21. }
RAW Paste Data