add closeDatabase
This commit is contained in:
parent
ea9310cb62
commit
bfa7c1af14
|
@ -1,4 +1,4 @@
|
|||
import { dbPromise, openDatabase } from './databaseLifecycle'
|
||||
import { closeDatabase, dbPromise, openDatabase } from './databaseLifecycle'
|
||||
import {
|
||||
DATA_VERSION_CURRENT,
|
||||
DB_NAME,
|
||||
|
@ -74,4 +74,8 @@ export class IndexedDBEngine {
|
|||
emojiStore.get(unicode).onsuccess = e => cb(e.target.result)
|
||||
})
|
||||
}
|
||||
|
||||
close () {
|
||||
return closeDatabase(DB_NAME)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,3 +48,8 @@ export async function getEmojiByUnicode (unicode) {
|
|||
await init()
|
||||
return idbEngine.getEmojiByUnicode(unicode)
|
||||
}
|
||||
|
||||
export async function closeDatabase () {
|
||||
await init()
|
||||
return idbEngine.close()
|
||||
}
|
||||
|
|
|
@ -57,12 +57,15 @@ export async function dbPromise (db, storeName, readOnlyOrReadWrite, cb) {
|
|||
})
|
||||
}
|
||||
|
||||
export function closeDatabase (instanceName) {
|
||||
export function closeDatabase (dbName) {
|
||||
if (!dbName) {
|
||||
throw new Error('dbName is required')
|
||||
}
|
||||
// close any open requests
|
||||
const openReq = openReqs[instanceName]
|
||||
const openReq = openReqs[dbName]
|
||||
if (openReq && openReq.result) {
|
||||
openReq.result.close()
|
||||
}
|
||||
delete openReqs[instanceName]
|
||||
delete databaseCache[instanceName]
|
||||
delete openReqs[dbName]
|
||||
delete databaseCache[dbName]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue