35 lines
992 B
TypeScript
35 lines
992 B
TypeScript
import type { BlockedSite } from "./types"
|
|
import type { ExtensionDatabase } from "./database"
|
|
|
|
export interface BlockedSitesRepo {
|
|
getAll(): Promise<BlockedSite[]>
|
|
getOne(id: string): Promise<BlockedSite | undefined>
|
|
insert(input: BlockedSite): Promise<void>
|
|
update(input: BlockedSite): Promise<void>
|
|
delete(input: BlockedSite): Promise<void>
|
|
}
|
|
|
|
export function createBlockedSitesRepo(_db: Promise<ExtensionDatabase>): BlockedSitesRepo {
|
|
return {
|
|
async getAll() {
|
|
const db = await _db;
|
|
return await db.getAll("blocked_sites");
|
|
},
|
|
async getOne(id) {
|
|
const db = await _db;
|
|
return await db.get("blocked_sites", id);
|
|
},
|
|
async insert(input) {
|
|
const db = await _db;
|
|
await db.add("blocked_sites", input)
|
|
},
|
|
async update(input) {
|
|
const db = await _db;
|
|
await db.put("blocked_sites", input)
|
|
},
|
|
async delete(input) {
|
|
const db = await _db;
|
|
await db.delete("blocked_sites", input.id)
|
|
}
|
|
}
|
|
}
|