idb-factory
Better window.indexedDB.
This module provides consistent, modern API to window.indexedDB
.
It's especially useful for test environment, when you need to open/delete database multiple times.
For implementation details check well documented 100 lines of the source.
Example
// open database with version 1 and create stores { etargetresult etargetresult }
API
open
and del
returns Promise
and handles blocked
event, by repeating operation after 100ms.
open(dbName, [version], [upgradeCallback])
// open "mydb1" v1, and create store and indexconst db1 = async // version and upgradeCallback are optional.const db2 = async
You can combine it with idb-schema and have a pretty good deal.
const schema = version1 version2 const db = async
del(db)
const db = async // do something with db// ... // delete existing IDBDatabase instanceasync
del(dbName)
async // delete database by name
cmp(val1, val2)
// Compare 2 values, using IndexedDB's comparison algorithmconsoleconsole
global.forceIndexedDB
It is a specially global variable, which you can define to prior global.indexedDB
.
{ return globalforceIndexedDB || globalindexedDB || globalwebkitIndexedDB || globalmozIndexedDB || globalmsIndexedDB || globalshimIndexedDB}
For example, due to WebKit bug you can't rewrite
window.indexedDB
, but Safari 8 implementation is really buggy,
so you'd like to use shim and fallback to WebSQL.
if isSafari8 globalforceIndexedDB = globalshimIndexedDB // use WebSQL implementation, only in Safari 8,// and use IndexedDB in remaining browsers.const db = async