user.ts 452 B

123456789101112131415161718
  1. import { z } from "zod"
  2. import { eq } from "drizzle-orm"
  3. import { fn } from "./util/fn"
  4. import { Database } from "./drizzle"
  5. import { UserTable } from "./schema/user.sql"
  6. export namespace User {
  7. export const fromID = fn(z.string(), async (id) =>
  8. Database.transaction(async (tx) => {
  9. return tx
  10. .select()
  11. .from(UserTable)
  12. .where(eq(UserTable.id, id))
  13. .execute()
  14. .then((rows) => rows[0])
  15. }),
  16. )
  17. }