import { eq } from 'drizzle-orm' import { db } from './db-instance' import { units } from './schema/units' export type Unit = { id: number name: string } export type UnitsRepo = { listUnits: () => Promise createUnit: (input: { name: string }) => Promise } export function createUnitsRepo(): { repo: UnitsRepo } { const repo: UnitsRepo = { listUnits() { const rows = db.select().from(units).all() return Promise.resolve(rows.map((r) => ({ id: r.id, name: r.name }))) }, createUnit(input) { const created = db.insert(units).values(input).returning().get() return Promise.resolve({ id: created.id, name: created.name }) }, } return { repo } }