Cmen
3 years ago
5 changed files with 62 additions and 12 deletions
@ -0,0 +1,33 @@
|
||||
import { openDB, IDBPDatabase, wrap, unwrap } from "idb"; |
||||
|
||||
const DB = "FineGeoJSON"; |
||||
const STORE = "cache"; |
||||
const VERSION = 1.0; |
||||
|
||||
let db: IDBPDatabase; |
||||
|
||||
init(); |
||||
|
||||
async function init() { |
||||
if (db == null) { |
||||
db = await openDB(DB, VERSION, { |
||||
upgrade(db) { |
||||
db.createObjectStore(STORE); |
||||
}, |
||||
}); |
||||
} |
||||
} |
||||
|
||||
export async function getItem(key: string) { |
||||
await init(); |
||||
return await db.get(STORE, key); |
||||
} |
||||
|
||||
export async function setItem(key: string, value: string) { |
||||
await init(); |
||||
await db.put(STORE, value, key); |
||||
} |
||||
|
||||
export async function deleteItem(key: string) { |
||||
//
|
||||
} |
Loading…
Reference in new issue