[PWA] 12. Intro to IndexedDB
Use the library indexedDB-promised.
Create a database and stroe:
import idb from 'idb'; // Open(db_name, version, cb)
var dbPromise = idb.open('test-db', 1, function (upgradeDb) {
var keyValStore = upgradeDb.createObjectStore('keyval'); // create table
//put(value, key)
keyValStore.put('world', 'Hello');
});
Notice put() function take value frist then key.
Read the key in stroe:
// read "hello" in "keyval"
dbPromise.then(function (db) {
var tx = db.transaction('keyval'); // Open a transaction
var keyValStore = tx.objectStore('keyval'); // read the store
return keyValStore.get('hello'); // get value by key
}).then(function (val) {
console.log('The value of "hello" is:', val);
});
Write value to store:
// set "foo" to be "bar" in "keyval"
dbPromise.then(function (db) {
var tx = db.transaction('keyval', 'readwrite'); // ready for add key value
var keyValStore = tx.objectStore('keyval'); // get the store
keyValStore.put('bar', 'foo'); // set the value, notice it may not be success if any step in transaction fail.
return tx.complete; // tx.complete is a promise
}).then(function () {
console.log('Added foo:bar to keyval');
});
[PWA] 12. Intro to IndexedDB的更多相关文章
- [PWA] 1. Intro to Service worker
Service worker stays between our browser and noetwork requests. It can help to fetch data from cache ...
- Angularjs学习---ubuntu12.04中karma安装配置中常见的问题总结
karma启动时出现了很多问题: 1.安装karma前提条件 安装karma首先要安装nodejs,npm然后才可以安装karma.nodejs,npm的安装过程可以参考文章:Angularjs学习- ...
- Angularjs学习---ubuntu12.04中karma安装配置
Angularjs学习---ubuntu12.04中karma安装配置中常见的问题总结 karma启动时出现了很多问题: 1.安装karma前提条件 安装karma首先要安装nodejs,npm然 ...
- golang结构体
声明结构体 定义结构体使用struct关键字.在结构体内部定义它们的成员变量和类型.如果成员变量的类型相同还可以把它们写到同一行. struct里面可以包含多个字段(属性) struct类型可以定义方 ...
- 手把手教你如何安装和使用Karma-Jasmine
注意:本文中出现的资料链接.karma的插件安装等,均可能需要翻$墙后才能正确执行. Jasmine是一个Javascript的测试工具,在Karma上运行Jasmine可完成Javascript的自 ...
- HTTP cache in depth
HTTP cache in depth HTTP 缓存 https://developers.google.com/web/fundamentals/performance/optimizing-co ...
- python 各模块
01 关于本书 02 代码约定 03 关于例子 04 如何联系我们 1 核心模块 11 介绍 111 内建函数和异常 112 操作系统接口模块 113 类型支持模块 114 正则表达式 115 语言支 ...
- Python Standard Library
Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...
- 在mybatis中写sql语句的一些体会
本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...
随机推荐
- jquery动画效果中,避免持续反应用户的连续点击
一.某些动画效果中,避免持续连续反应用户的连续点击(这标题真不好描述) 意思就是指用户点击速度很快,完成一次效果的时间不能很快结束的话,就会出现用户不点击了,效果还在持续.看下面例子就明白了,手风琴效 ...
- PHPCMS收集标签使用
调用子栏目(在栏目首页模板需要用到) {pc:content action="category" catid="$catid" num="25&quo ...
- centos jdk切换
#这里找下载路径 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html ...
- 阻止文件不被上传到iCloud-b
有空用下 http://www.cocoachina.com/bbs/read.php?tid=86244 http://www.ooso.net/archives/617 http://blog.c ...
- 阿里云的esc
云服务器ecs作用如下:1.完全管理权限:对云服务器的操作系统有完全控制权,用户可以通过连接管理终端自助解决系统问题,进行各项操作:2.快照备份与恢复:对云服务器的磁盘数据生成快照,用户可使用快照回滚 ...
- 概率质量函数:怀孕周期的PMF
__author__ = 'dell' import surveyimport Pmfimport matplotlib.pyplot as pyplot table = survey.Pregnan ...
- android:TextAppearance.Material.Widget.Button.Inverse找不到或者报错问题
前两天将android sdk升到android6.0后出现Error retrieving parent for Item - AppCompact-v7 23 或者无法解析 android:Tex ...
- Spring boot Mybatis
最近刚接触Spring boot,正是因为他的及简配置方便开发,促使我下定决心要用它把之前写的项目重构,那么问题来了,spring boot怎么整合mybatis呢,下面几个配置类来搞定. 在我的代码 ...
- yii分页
关于分页有一个重要的类CPagination. CPagination represents information relevant to pagination. http://www.yiifra ...
- Hibernate 配置详解(3)
7) hibernate.max_fetch_depth: 该属性用于设置left out join单对象查询关系(one-to-one/many-to-one)中最大的关联深度.默认值为0,即默认情 ...