pinafore/routes/_utils/database/knownDbs.js

27 lines
791 B
JavaScript
Raw Normal View History

2018-01-22 02:18:56 +01:00
import keyval from "idb-keyval"
export async function addKnownDb(instanceName, type, dbName) {
2018-01-22 03:36:40 +01:00
let knownDbs = (await getKnownDbs())
2018-01-22 02:18:56 +01:00
if (!knownDbs[instanceName]) {
knownDbs[instanceName] = []
}
if (!knownDbs[instanceName].some(db => db.type === type && db.dbName === dbName)) {
knownDbs[instanceName].push({type, dbName})
}
await keyval.set('known_dbs', knownDbs)
}
export async function getKnownDbs() {
return (await keyval.get('known_dbs')) || {}
}
export async function getKnownDbsForInstance(instanceName) {
let knownDbs = await getKnownDbs()
return knownDbs[instanceName] || []
2018-01-22 03:36:40 +01:00
}
export async function deleteInstanceFromKnownDbs(instanceName) {
let knownDbs = await getKnownDbs()
delete knownDbs[instanceName]
await keyval.set('known_dbs', knownDbs)
2018-01-22 02:18:56 +01:00
}