21 lines
565 B
TypeScript
21 lines
565 B
TypeScript
import { eq } from "drizzle-orm";
|
|
import type { Database } from "../client.js";
|
|
import { users } from "../schema/users.js";
|
|
|
|
export function makeUsersRepo(db: Database) {
|
|
return {
|
|
findById: async (id: number) => {
|
|
const rows = await db.select().from(users).where(eq(users.id, id)).limit(1);
|
|
return rows[0] ?? null;
|
|
},
|
|
findByUsername: async (username: string) => {
|
|
const rows = await db
|
|
.select()
|
|
.from(users)
|
|
.where(eq(users.username, username))
|
|
.limit(1);
|
|
return rows[0] ?? null;
|
|
},
|
|
};
|
|
}
|