import idb from 'idb';

var dbPromise = idb.open('test-db', 4, function (upgradeDb) {
switch (upgradeDb.oldVersion) {
case 0:
// keyval store is already created at version 1
var keyValStore = upgradeDb.createObjectStore('keyval');
keyValStore.put("world", "hello");
case 1:
// new version
upgradeDb.createObjectStore('people', {keyPath: 'name'});
case 2:
var peopleStore = upgradeDb.transaction.objectStore('people');
peopleStore.createIndex('animal', 'favoriteAnimal');
case 3:
var peopleStore = upgradeDb.transaction.objectStore('people');
peopleStore.createIndex('age', 'age');
}
}); // 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);
}); dbPromise.then(function (db) {
var tx = db.transaction('people', 'readwrite');
var peopleStore = tx.objectStore('people'); peopleStore.put({
name: "John", // name is the key
age: 23,
favoriteAnimal: 'cat'
});
peopleStore.put({
name: "Joe", // name is the key
age: 21,
favoriteAnimal: 'cat'
});
peopleStore.put({
name: "Jie", // name is the key
age: 22,
favoriteAnimal: 'dog'
});
peopleStore.put({
name: "Jay", // name is the key
age: 24,
favoriteAnimal: 'dog'
});
return tx.complete;
}).then(function () {
console.log("People are added");
}); dbPromise.then(function (db) {
var tx = db.transaction('people', 'readwrite');
var peopleStore = tx.objectStore('people');
var ageIndex = peopleStore.index('age');
return ageIndex.openCursor();
}).then(function (cursor) {
if (!cursor) return;
return cursor.advance(1); // skip the first person
}).then(function logPerson(cursor) {
if(cursor.value.name == "Jie"){
cursor.delete(); // delete
}
if(cursor.value.name == "Jay"){
console.log("Cursor at:", cursor.value.name);
var joe = cursor.value;
joe.favoriteAnimal = "Bird";
cursor.update(joe); // update
}
return cursor.continue().then(logPerson);
}).then(function () {
console.log("DONE");
});

[PWA] 14. Loop cursor的更多相关文章

  1. Oracle PLSQL Demo - 10.For Loop遍历游标[FOR LOOP CURSOR]

    declare cursor cur_emp is select t.* from scott.emp t; begin for r_emp in cur_emp loop dbms_output.p ...

  2. oracle中REF Cursor用法

    from:http://www.111cn.net/database/Oracle/42873.htm 1,什么是 REF游标 ? 动态关联结果集的临时对象.即在运行的时候动态决定执行查询. 2,RE ...

  3. 内核链表list.h

    stddef.h #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) list.h #ifndef _LINUX ...

  4. Linux 内核 链表 的简单模拟(2)

    接上一篇Linux 内核 链表 的简单模拟(1) 第五章:Linux内核链表的遍历 /** * list_for_each - iterate over a list * @pos: the & ...

  5. linux内核数据结构之链表

    linux内核数据结构之链表 1.前言 最近写代码需用到链表结构,正好公共库有关于链表的.第一眼看时,觉得有点新鲜,和我之前见到的链表结构不一样,只有前驱和后继指针,而没有数据域.后来看代码注释发现该 ...

  6. linux内核数据结构之链表【转】

    转自:http://www.cnblogs.com/Anker/p/3475643.html 1.前言 最近写代码需用到链表结构,正好公共库有关于链表的.第一眼看时,觉得有点新鲜,和我之前见到的链表结 ...

  7. 韩顺平Oracle笔记

    韩顺平Oracle笔记 分类: DataBase2011-09-07 10:24 3009人阅读 评论(0) 收藏 举报 oracle数据库sqljdbcsystemstring   目录(?)[-] ...

  8. Oracle PLSQL游标、游标变量的使用

    参考文章:https://www.cnblogs.com/huyong/archive/2011/05/04/2036377.html 在 PL/SQL 程序中,对于处理多行记录的事务经常使用游标来实 ...

  9. 《Linux设备驱动程序》编译LDD3的scull驱动问题总结***

    由于Linux内核版本更新的原因,LDD3(v2.6.10)提供的源码无法直接使用,下面是本人编译scull源码时出现的一些问题及解决方法.编译环境:Ubuntu 10.04 LTS(kernel v ...

随机推荐

  1. Ajax基础--JavaScript实现

    ajax原理 1.ajax 即“Asynchronous JavaScript and XML”(异步 JavaScript 和 XML),也就是无刷新数据读取. 通俗地讲就是:AJAX 通过在后台与 ...

  2. python之json

    import json import requests re = requests.get('http://wthrcdn.etouch.cn/weather_mini?city=成都') re.en ...

  3. import uno 错误

    安装aeroolib 模块后,提示没有 uno 相关段一些模块, 原因是这些模块是 openoffice 中段,需要先安装 openoffice. 1:清除所有 libreoffice 软件,  su ...

  4. uboot main_loop函数分析

    一.概述    main_loop()函数做的都是与具体平台无关的工作.主要包括的工作如下: (1)初始化启动次数限制机制 (2)Modem功能 (3)设置软件版本号 (4)启动延迟 (5)读取命令, ...

  5. ps使用方法续

    1.找一张皱折的背景,将需要制作的照片拖入背景层,调整尺寸并裁剪,使之 与背景边框相配, 2.调整-色相饱和度,全图:饱和度-35,明度+10, 3.调整图层改成柔光模式,出来旧照片的效果了, 4.色 ...

  6. 1. android

    http://blog.csdn.net/mirkerson/article/details/7238815

  7. GNU MAKE指南

    GNU make 指南 翻译: 哈少 译者按: 本文是一篇介绍 GNU Make 的文章,读完后读者应该基本掌握了 make 的用法.而 make 是所有想在 Unix (当然也包括 Linux )系 ...

  8. BZOJ 1043 下落的圆盘

    Description 有n个圆盘从天而降,后面落下的可以盖住前面的.求最后形成的封闭区域的周长.看下面这副图, 所有的红色线条的总长度即为所求.  Input n ri xi y1 ... rn x ...

  9. Atlantis

    poj1151:http://poj.org/problem?id=1151 题意:求矩形面积的并题解:扫描线加线段树 #include<iostream> #include<cst ...

  10. Election Time

    Election Time Time Limit: 1000MS Memory limit: 65536K 题目描述 The cows are having their first election ...