homeman-deno/db.ts
2024-01-21 15:52:46 -06:00

25 lines
546 B
TypeScript

import {
createPentagon,
TableDefinition,
} from 'https://deno.land/x/pentagon@v0.1.5/mod.ts'
import { TodoModel, UserModel } from '@homeman/models.ts'
export const kv = await Deno.openKv('homeman.db')
export const schema: Record<string, TableDefinition> = {
users: {
schema: UserModel,
relations: {
assignedTodos: ['todos', [TodoModel], 'id', 'assigneeUserId'],
},
},
todos: {
schema: TodoModel,
relations: {
assignee: ['users', UserModel, 'assigneeUserId', 'id'],
},
},
}
export const db = createPentagon(kv, schema)