filer/examples/deferred-test.html

62 lines
1.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<div id="stdout"></div>
</body>
<script src='../lib/require.js'></script>
<script>
require.config({
baseUrl: "../lib",
paths: {
"src": "../src"
}
});
require(["src/indexeddb"], function(idb) {
var db;
idb.open('test').then(
function(event) {
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) {
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);
});
});
</script>
</html>