filer/examples/deferred-test.html

62 lines
1.3 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<div id="stdout"></div>
</body>
2013-05-26 00:37:13 +00:00
<script src='../lib/require.js'></script>
<script>
2013-05-26 00:37:13 +00:00
require.config({
baseUrl: "../lib",
paths: {
"src": "../src"
}
});
2013-05-26 00:37:13 +00:00
require(["src/indexeddb"], function(idb) {
var db;
2013-05-26 00:37:13 +00:00
idb.open('test').then(
function(event) {
2013-05-26 01:26:18 +00:00
db = event.target.result;
var transaction = db.transaction(['FILES'], 'readwrite');
var files = transaction.objectStore('FILES');
return files.clear();
},
function(event) {
console.error('error:', event);
},
function(event) {
2013-05-26 01:26:18 +00:00
db = event.target.result;
if(db.objectStoreNames().contains('FILES')) {
db.deleteObjectStore('FILES');
}
var files = db.createObjectStore('FILES');
}
).then(
function(event) {
var transaction = db.transaction(['FILES'], 'readwrite');
var files = transaction.objectStore('FILES');
return files.put('value', 'key');
}
).then(
function(event) {
var transaction = db.transaction(['FILES'], 'readwrite');
var files = transaction.objectStore('FILES');
return files.get('key');
}
).then(
function(event) {
console.info('result', event.target.result);
}
).otherwise(function(event) {
console.error('error: ', event);
});
2013-05-26 00:37:13 +00:00
});
</script>
</html>