Add idb-keyval backed archival storage (#9754)
* Add idb-keyval backed archival storage * Cleanup * Remove test
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import {MMKV} from '@bsky.app/react-native-mmkv'
|
||||
|
||||
import {type DB} from '#/storage/archive/db/types'
|
||||
|
||||
export function create({id}: {id: string}): DB {
|
||||
const store = new MMKV({id})
|
||||
|
||||
return {
|
||||
async get(key: string): Promise<string | undefined> {
|
||||
return store.getString(key) ?? undefined
|
||||
},
|
||||
async set(key: string, value: string): Promise<void> {
|
||||
store.set(key, value)
|
||||
},
|
||||
async delete(key: string): Promise<void> {
|
||||
store.delete(key)
|
||||
},
|
||||
async clear(): Promise<void> {
|
||||
store.clearAll()
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import {clear, createStore, del, get, set} from 'idb-keyval'
|
||||
|
||||
import {type DB} from '#/storage/archive/db/types'
|
||||
|
||||
export function create({id}: {id: string}): DB {
|
||||
const store = createStore(id, id)
|
||||
|
||||
return {
|
||||
async get(key: string): Promise<string | undefined> {
|
||||
return get(key, store) ?? undefined
|
||||
},
|
||||
async set(key: string, value: string): Promise<void> {
|
||||
await set(key, value, store)
|
||||
},
|
||||
async delete(key: string): Promise<void> {
|
||||
await del(key, store)
|
||||
},
|
||||
async clear(): Promise<void> {
|
||||
await clear(store)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export type DB = {
|
||||
get(key: string): Promise<string | undefined>
|
||||
set(key: string, value: string): Promise<void>
|
||||
delete(key: string): Promise<void>
|
||||
clear(): Promise<void>
|
||||
}
|
||||
Reference in New Issue
Block a user