Repository Layer Overview
The repository layer provides data access abstraction between services and the database.
Purpose
Repositories handle:
- Database queries and mutations
- Data mapping between database and domain entities
- SQL composition
- No business logic
Standard Pattern
export class FundRepository {
constructor(private db: ProductionDBClient) {}
async create(data: CreateFundRequest): Promise<FundEntity> {
const [fund] = await this.db.insert(fundsTable).values(data).returning();
return fund;
}
async findById(id: number): Promise<FundEntity | null> {
const [fund] = await this.db
.select()
.from(fundsTable)
.where(eq(fundsTable.id, id));
return fund || null;
}
}
See Repository Pattern for detailed documentation.