Repository Pattern
The Repository pattern abstracts data access, providing a collection-like interface for domain objects. Implementations for TypeScript with Prisma and Python with SQLAlchemy.
- Difficulty
- intermediate
- Read time
- 1 min read
- Version
- v1.0.0
- Confidence
- established
- Last updated
Quick Reference
Repository abstracts data access with collection-like interface (find, findById, create, update, delete). Define interface, implement with ORM (Prisma/SQLAlchemy). Keep repositories focused on single entity. Business logic belongs in services, not repositories. Inject repositories into services for testability.
Use When
- Implementing data access layer
- Separating business logic from persistence
- Making code testable with mock data
- Supporting multiple data sources
Skip When
- Simple CRUD without business logic
- Direct database scripts
Repository Pattern
The Repository pattern abstracts data access, providing a collection-like interface for domain objects. Implementations for TypeScript with Prisma and Python with SQLAlchemy.