idb-keyval
Advanced tools
Comparing version 3.0.4 to 3.0.5
export class Store { | ||
private _dbp: Promise<IDBDatabase>; | ||
readonly _dbp: Promise<IDBDatabase>; | ||
constructor(dbName = 'keyval-store', readonly storeName = 'keyval') { | ||
const connection = (version?: number): Promise<IDBDatabase> => new Promise((resolve, reject) => { | ||
const openreq = indexedDB.open(dbName, version); | ||
this._dbp = new Promise((resolve, reject) => { | ||
const openreq = indexedDB.open(dbName, 1); | ||
openreq.onerror = () => reject(openreq.error); | ||
openreq.onsuccess = () => { | ||
// If a later version of this database wants to open, | ||
// close and create a new connection for the new version. | ||
openreq.result.onversionchange = () => { | ||
openreq.result.close(); | ||
this._dbp = connection(); | ||
} | ||
// If this database has been opened before, but never with this | ||
// storeName, the objectStore won't exist yet. In which case, | ||
// force an upgrade by opening a connection with version n+1. | ||
if (!openreq.result.objectStoreNames.contains(storeName)) { | ||
resolve(connection(openreq.result.version + 1)); | ||
} | ||
else { | ||
resolve(openreq.result); | ||
} | ||
} | ||
openreq.onsuccess = () => resolve(openreq.result); | ||
@@ -31,4 +15,2 @@ // First time setup: create an empty object store | ||
}); | ||
this._dbp = connection(); | ||
} | ||
@@ -84,3 +66,3 @@ | ||
// And openKeyCursor isn't supported by Safari. | ||
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function () { | ||
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function() { | ||
if (!this.result) return; | ||
@@ -87,0 +69,0 @@ keys.push(this.result.key); |
{ | ||
"name": "idb-keyval", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"description": "A super-simple-small keyval store built on top of IndexedDB", | ||
@@ -5,0 +5,0 @@ "main": "./dist/idb-keyval-cjs.js", |
@@ -105,2 +105,12 @@ # IDB-Keyval | ||
These built versions are also available on jsDelivr, e.g.: | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/idb-keyval@3/dist/idb-keyval-iife.min.js"></script> | ||
<!-- Or in modern browsers: --> | ||
<script type="module"> | ||
import { get, set } from 'https://cdn.jsdelivr.net/npm/idb-keyval@3/dist/idb-keyval.mjs'; | ||
</script> | ||
``` | ||
## Updating from 2.x | ||
@@ -107,0 +117,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135
19527
14
312