Created
March 13, 2019 15:24
-
-
Save quasicomputational/73d408f8f9034976901de8a4836a7e88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import indexedDB from "fake-indexeddb"; | |
import IDBKeyRange from 'fake-indexeddb/lib/FDBKeyRange'; | |
import IDBIndex from 'fake-indexeddb/lib/FDBIndex'; | |
import IDBCursor from 'fake-indexeddb/lib/FDBCursor'; | |
import IDBDatabase from 'fake-indexeddb/lib/FDBDatabase'; | |
import IDBTransaction from 'fake-indexeddb/lib/FDBTransaction'; | |
import IDBObjectStore from 'fake-indexeddb/lib/FDBObjectStore'; | |
import IDBRequest from 'fake-indexeddb/lib/FDBRequest'; | |
global.indexedDB = indexedDB; | |
global.IDBKeyRange = IDBKeyRange; | |
global.IDBIndex = IDBIndex; | |
global.IDBTransaction = IDBTransaction; | |
global.IDBDatabase = IDBDatabase; | |
global.IDBCursor = IDBCursor; | |
global.IDBObjectStore = IDBObjectStore; | |
global.IDBRequest = IDBRequest; | |
import { openDB } from "./node_modules/idb/build/esm/index.js"; | |
export const STORE = "store"; | |
export const dbPromise = () => openDB("db", 1, { | |
upgrade: (db, oldVersion) => { | |
switch (oldVersion) { | |
case 0: | |
db.createObjectStore(STORE, { autoIncrement: true }); | |
break; | |
} | |
}, | |
}); | |
export const checkForGarbage = async () => { | |
const db = await dbPromise(); | |
try { | |
const tx = db.transaction([STORE], "readwrite"); | |
const store = tx.objectStore(STORE); | |
const id = await store.get(0); | |
console.log("Done!"); | |
} finally { | |
db.close(); | |
} | |
}; | |
for (let i = 0; i < 3; i++) { | |
setTimeout(checkForGarbage, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment