indexed database IndexedDB
2016-01-28 14:55
113 查看
Indexed Database API 目的是提供一个可供javascript存储和检索对象,并且还能进行查询,搜索等数据库操作
设计为几乎完全异步,因此绝大部分操作都稍后执行,因此每次操作都应该提供onerror和onsuccess来处理结果
目前还没有完全支持,因此:var indexedDB = window.indexedDB || window.msIndexedDB || window.mozIndexedDB || window.webkitIndexedDB;
IndexedDB 和MySQL最大的区别在于用对象存储而不是表格来记录数据
设计为几乎完全异步,因此绝大部分操作都稍后执行,因此每次操作都应该提供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]); } }};
相关文章推荐
- 密谍伙伴(X Company)
- cocos2d-js获得其它Layer层对象
- Access与SQL中的IsNull(),IS NULL的区别
- python字符串连接效率比较(使用+连接)
- web storage 离线存储
- iOS---免费获取邓白氏编码
- flex 修改访问url
- Linux FTP服务器 vsftp
- Android SDK镜像服务器
- 用C语言实现二分查找算法
- java微信二次开发01
- iOS UITableView 里的Cell用Xib实现
- if脚本linux
- ubuntu下导入导出.sql
- Eclipse中jsp、js文件编辑时,卡死现象解决汇总
- [转载] 最全Android 编程下 Touch 事件的分发和消费机制
- python数字图像处理(18):高级形态学处理
- 【原创】Java实现手机号码归属地查询
- Let’s encrypt 计划为网站提供免费的基本 SSL 证书,以加速互联网从 HTTP 向 HTTPS 过渡。
- 离线缓存 manifest