html Repro Safari IndexedDB autoIncrement bug
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Repro Safari IndexedDB autoIncrement bug相关的知识,希望对你有一定的参考价值。
<body>
<h1>Repro Safari IndexedDB autoIncrement bug</h1>
<div id="logger"></div>
<script>
var dbname = 'time_' + Date.now() + '_';
function log(msg) {
document.getElementById("logger").innerHTML += msg + "<br>";
}
var req = indexedDB.open(dbname + "1");
req.onupgradeneeded = function (e) {
var db = e.target.result;
if (e.oldVersion === 1) {
return;
}
db.createObjectStore('store', {keyPath: 'id', autoIncrement: true}).createIndex('key', 'key', {unique: true});
};
req.onsuccess = function (e) {
var db = e.target.result;
var mergeOnKey = function(data, objectStore){
return new Promise( function (resolve, reject) {
var openIndex = objectStore.index('key');
var request = openIndex.get(data.key);
request.onsuccess = function (e) {
if(e.target.result){
data.id = e.target.result.id;
}
var request = objectStore.put(data);
request.onsuccess = function (e) {
resolve( e.target.result );
};
request.onerror = reject;
};
request.onerror = reject;
});
};
var batchMergeOnKey = function( dataArray ){
var txn = db.transaction('store', 'readwrite');
var objectStore = txn.objectStore('store');
var keys = [];
return new Promise( function(resolve, reject) {
dataArray.forEach(function(data){
mergeOnKey(data, objectStore).then( function(key) {
keys.push(key);
});
});
txn.oncomplete = function (e) {
resolve(keys);
};
});
};
batchMergeOnKey([{ key: 'a' }, { key: 'b' }])
.then( function (keys) {
log('created keys ' + keys);
return batchMergeOnKey([{ key: 'a', state: 'updated' }, { key: 'c', state: 'new' }]);
})
.then( function (keys) {
log('merged/created keys ' + keys);
if(keys.includes(3)){
log('This is expected behaviour');
} else {
log('There is a bug');
}
});
};
</script>
</body>
</html>
以上是关于html Repro Safari IndexedDB autoIncrement bug的主要内容,如果未能解决你的问题,请参考以下文章
resiprocate使用入门:内网搭建基于repro的sipproxy测试环境
indexed database IndexedDB
树状树组(Binary Indexed Tree (BIT))的C++部分实现
使用 Google Picker API 会阻止发出 RAMP LOAD?
Spring Data Mongo @Indexed 多次创建索引
ElasticSearch & Tire:使用映射和 to_indexed_json