initial commit
This commit is contained in:
commit
7e466e29d2
28 changed files with 17360 additions and 0 deletions
35
utils/todo-repo.ts
Normal file
35
utils/todo-repo.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue