[PWA] 14. Loop cursor
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的更多相关文章
- 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 ...
- oracle中REF Cursor用法
from:http://www.111cn.net/database/Oracle/42873.htm 1,什么是 REF游标 ? 动态关联结果集的临时对象.即在运行的时候动态决定执行查询. 2,RE ...
- 内核链表list.h
stddef.h #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) list.h #ifndef _LINUX ...
- Linux 内核 链表 的简单模拟(2)
接上一篇Linux 内核 链表 的简单模拟(1) 第五章:Linux内核链表的遍历 /** * list_for_each - iterate over a list * @pos: the & ...
- linux内核数据结构之链表
linux内核数据结构之链表 1.前言 最近写代码需用到链表结构,正好公共库有关于链表的.第一眼看时,觉得有点新鲜,和我之前见到的链表结构不一样,只有前驱和后继指针,而没有数据域.后来看代码注释发现该 ...
- linux内核数据结构之链表【转】
转自:http://www.cnblogs.com/Anker/p/3475643.html 1.前言 最近写代码需用到链表结构,正好公共库有关于链表的.第一眼看时,觉得有点新鲜,和我之前见到的链表结 ...
- 韩顺平Oracle笔记
韩顺平Oracle笔记 分类: DataBase2011-09-07 10:24 3009人阅读 评论(0) 收藏 举报 oracle数据库sqljdbcsystemstring 目录(?)[-] ...
- Oracle PLSQL游标、游标变量的使用
参考文章:https://www.cnblogs.com/huyong/archive/2011/05/04/2036377.html 在 PL/SQL 程序中,对于处理多行记录的事务经常使用游标来实 ...
- 《Linux设备驱动程序》编译LDD3的scull驱动问题总结***
由于Linux内核版本更新的原因,LDD3(v2.6.10)提供的源码无法直接使用,下面是本人编译scull源码时出现的一些问题及解决方法.编译环境:Ubuntu 10.04 LTS(kernel v ...
随机推荐
- 泛型? extents super
?可以接受任何泛型集合,但是不能编辑集合值.所以一般只在方法参数中用 例子: ? extends Number 则类型只能是Number类的子孙类 ? super String 则类型只能是Str ...
- Linux设置固定IP
此处需整理 问题:在CentOS 7上,我想要将我其中一个网络接口从DHCP改为静态IP地址配置,如何才能永久为CentOS或RHEL 7上的网络接口分配静态IP地址? 如果你想要为CentOS 7中 ...
- .animate动画
.animate(params, [duration], [easing], [callback]) params: 结果样式属性 duration: 动画时长 也可以用 slow normal fa ...
- js切换换class
1, js代码 function ntabs(thisObj,Num) {if(thisObj.className == "active")return; ...
- JDK环境变量配置贺Tomcat环境搭建
一.安装JDK JDK (Java Develpmet kit) Java开发环境(工具包和运行环境jre) 是Java开发的核心,包括:编译程序的命令 javac 运行程序java命令 he jav ...
- Android LinearLayout中weight属性的意义与使用方式
layout_weight 分割父级容器的比例
- 使用windows live writer 编辑博客日志
使用Windows Live Writer 编辑日志 一 意义 写博客日志是个需要坚持的好习惯.使用Windows Live Writer,能不受网页自带编辑器限制. Markdown支持.安装mar ...
- php实现base64编码
工作需要,想弄一个加密的串,就想仿照base64的编码方式,写一个加密的方法,所以就有了下面这个用php实现的base64的代码 <?php /** * Base64 编码/解码 * @auth ...
- zabbix 四张大表分区
trends_uint.ibd history history_unit trends CREATE TABLE `trends` ( `itemid` bigint(20) unsigned NOT ...
- C# Linq-Aggregate
The easiest to understand definition of Aggregate is that it performs an operation on each element o ...