The purpose of the Indexed database API is to provide an object that can be stored and retrieved by JavaScript, as well as to query, search, etc.
is designed to be almost completely asynchronous, so most operations are executed later, soEach operation should provide onerror and onsuccess to process the resultsCurrently not fully supported, therefore: var IndexedDB = Window.indexeddb | | WINDOW.MSINDEXEDDB | | WINDOW.MOZINDEXEDDB | | WINDOW.WEBKITINDEXEDDB; The biggest difference between IndexedDB and MySQL is that they use object storage instead of tables to record data
Const DBNAME = "The_name"; var request = Indexeddb.open (DbName, 2); request.onerror = function (event) {//Handle errors.} ; request.onupgradeneeded = function (event) {var db = Event.target.result; Create an ObjectStore-to-hold information on our customers. We ' Re//going to use "ssn" as our key path because it's guaranteed to be//unique. var objectstore = Db.createobjectstore ("Customers", {keypath: "ssn"}); Create an index to search customers by name. We may have duplicates//So we can ' t use a unique index. Objectstore.createindex ("name", "name", {unique:false}); Create an index to search customers by email. We want to ensure that//No. Customers has the same email, so use a unique index. Objectstore.createindex ("email", "email", {unique:true}); Use transaction OnComplete to make sure the ObjectStore creation are//finished before adding data into it. ObjectStore.transaction.oncomplete = function (event) {//Store values in the newly creaTed ObjectStore. var customerobjectstore = db.transaction ("Customers", "ReadWrite"). ObjectStore ("Customers"); for (var i in CustomerData) {Customerobjectstore.add (customerdata[i]); } }};
Indexed Database IndexedDB