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