Indexeddb does not disappear data after giving refresh

Asked

Viewed 33 times

0

As I do not disappear the added data, even giving refresh on the screen, I say after I add if I give refresh do not disappear the add data in my table:

var indexedDB = window.indexedDB || window.mozIndexedDB ||
                    window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;

//declaration
var db;
(function () {
    var maquinaData = [
        { name: "Máquina de Lavar", status: "1"  },
        { name: "Máquina 2", status: "2" }
    ];

      let initDb = () => {
      let request = indexedDB.open("database", 1);

      request.onerror = (event) =>{ console.log("IndexedDB error: " + evt.target.errorCode);};

      request.onsuccess = (event) => { db = request.result; };

      request.onupgradeneeded = (event) => {

          let objectStore = event.currentTarget.result.createObjectStore(
                   "maquina", { keyPath: "id", autoIncrement: true });

          objectStore.createIndex("name", "name", { unique: false });
          objectStore.createIndex("status", "status", { unique: false });

          for (i in maquinaData) {
              objectStore.add(maquinaData[i]);
          }
      };
    }

    function contentLoaded() {
        initDb();
        adicionaNoBando(maquina);



    }
});
  • I don’t know if that’s it, but it seems to me that every refresh on the page that variable var db; is redeclared.

  • @dvd or I researched something about the window, but without much success

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.