zoukankan      html  css  js  c++  java
  • indexed database IndexedDB

    Indexed Database API 目的是提供一个可供javascript存储和检索对象,并且还能进行查询,搜索等数据库操作

     
    设计为几乎完全异步,因此绝大部分操作都稍后执行,因此每次操作都应该提供onerror和onsuccess来处理结果
     
    目前还没有完全支持,因此:var indexedDB = window.indexedDB || window.msIndexedDB || window.mozIndexedDB || window.webkitIndexedDB;
     
    IndexedDB 和MySQL最大的区别在于用对象存储而不是表格来记录数据
    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 about 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 two customers have the same email, so use a unique index.
      objectStore.createIndex("email", "email", { unique: true });
    
      // Use transaction oncomplete to make sure the objectStore creation is 
      // 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]);
        }
      }};
  • 相关阅读:
    iOS-25个小技巧
    iOS-UITableView的使用
    iOS-UIPickerView
    iOS-UIStoryboard和UIResponder
    javascript弹出层-DEMO001
    jQuery源码分析-02正则表达式-RegExp-常用正则表达式
    JSON动态生成树
    回顾码农历程总结2013 期待2014
    大数据量分页存储过程效率测试附代码
    关于对象序列化json 说说
  • 原文地址:https://www.cnblogs.com/chuangweili/p/5166270.html
Copyright © 2011-2022 走看看