Spaces:
Sleeping
Sleeping
Download src/libs/shared/infrastructure/postgres/repositories/PgUserRepository.ts from fouadkhalid123/asd: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/fouadkhalid123/asd/resolve/main/src/libs/shared/infrastructure/postgres/repositories/PgUserRepository.ts
- Command line
-
hf download hf://spaces/fouadkhalid123/asd/src/libs/shared/infrastructure/postgres/repositories/PgUserRepository.ts
-
curl -L -o PgUserRepository.ts https://huggingface.co/spaces/fouadkhalid123/asd/resolve/main/src/libs/shared/infrastructure/postgres/repositories/PgUserRepository.ts
1.21 kB
| import { eq } from "drizzle-orm"; | |
| import { users, User, NewUser } from "../schema/users"; | |
| import { IPgUserRepository } from "./IPgUserRepository"; | |
| export class PgUserRepository implements IPgUserRepository { | |
| constructor(private readonly db: any) { } | |
| async upsert(input: NewUser): Promise<void> { | |
| await this.db | |
| .insert(users) | |
| .values(input) | |
| .onConflictDoUpdate({ | |
| target: [users.email], | |
| set: { | |
| displayName: input.displayName, | |
| passwordHash: input.passwordHash, | |
| role: input.role, | |
| updatedAt: new Date(), | |
| }, | |
| }); | |
| } | |
| async findById(id: string): Promise<User | null> { | |
| const [result] = await this.db.select().from(users).where(eq(users.id, id)).limit(1); | |
| return result || null; | |
| } | |
| async findByEmail(email: string): Promise<User | null> { | |
| const [result] = await this.db.select().from(users).where(eq(users.email, email)).limit(1); | |
| return result || null; | |
| } | |
| async delete(id: string): Promise<void> { | |
| await this.db.delete(users).where(eq(users.id, id)); | |
| } | |
| } | |