Indexed Database IndexedDB

Source: Internet
Author: User
Tags createindex

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.