title: Get and set a value in Indexeddb
body: <p>This seems simple but for some reason not working </p>
  
  <p>Requirement is </p>
  
  <ul>
  <li>Look and see if there is a specific value in the Indexeddb   </li>
  <li>Return the value  </li>
  <li>If value is not there or the DB is not there return empty
  or null   </li>
  <li>If returned empty , create the DB and set the value</li>
  </ul>
  
  <p>Seems straightforward but running into issues with onupgradeneeded which never gets called even after manually deleting the DB</p>
  
  <p>Here is the code </p>
  
  <pre><code>  &lt;script type="text/javascript"&gt;
  
      var id = GetItem();     
  
      if(id == null || id=="")
      {
          //based on some other logic 
          var GID = "test";
  
          SetItem(GID);
      }
  
      function GetItem() {
  
          var result = "";
  
          try {
                 var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
  
                  // Open  the database
                  var open = indexedDB.open("DB", 1);
  
                  open.onupgradeneeded = function () {
                      var db = open.result;
                      var store = db.createObjectStore("Store", { keyPath: "id" });                      
                  };
  
                  open.onsuccess = function () {
                      // Start a new transaction
                      var db = open.result;
                      var transaction = db.transaction("Store", "readwrite");
                      var store = transaction.objectStore("Store");
  
                       var gid = store.get("GID");
                       result = kid.result.value;
  
                  };
  
                  transaction.oncomplete = function () {
                      db.close();
                  };                 
              }
              catch (err) {
                  console.error(err.message);
              }          
          return result;
      }
  
      function SetItem(GID) {
          var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
          // Open (or create) the database
          var open = indexedDB.open("DB", 1);
          var transaction = db.transaction(["Store"]);
          var objectStore = transaction.objectStore("Store");
          objectStore.put({ id: "GID", value: GID });
          objectStore.onerror = function (event) {
              console.error(err.message);
          };
          request.onsuccess = function (event) {
              // Do something with the request.result!
              alert(request.result.value);
          };
             transaction.oncomplete = function () {
                      db.close();
                  }; 
      }
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Local storage is not an option</p>