https://github.com/timoniq/coolrepo
Viable repository utility for SQLAlchemy-based projects offering builder interface
https://github.com/timoniq/coolrepo
repository-pattern sqlalchemy
Last synced: about 1 year ago
JSON representation
Viable repository utility for SQLAlchemy-based projects offering builder interface
- Host: GitHub
- URL: https://github.com/timoniq/coolrepo
- Owner: timoniq
- Created: 2025-04-19T08:39:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-17T13:18:02.000Z (about 1 year ago)
- Last Synced: 2025-05-17T14:28:21.723Z (about 1 year ago)
- Topics: repository-pattern, sqlalchemy
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# coolrepo
```python
class ClientRepository(BaseRepository[Client]):
@queryset_builder
def marital_status(self, marital_statuses: list[ClientMaritalStatus]):
return self.queryset.filter(Client.marital_status.in_(marital_statuses))
@queryset_builder
@range_filter
def balance_range(self):
return Client.balance
@queryset_builder
@range_filter
def created_at_range(self):
return Client.created_at
async def find_boyfriend():
qs = (
ClientRepository()
.marital_status([ClientMaritalStatus.SINGLE, ClientMaritalStatus.DIVORCED])
.balance_range(min=1_000_000)
.all()
)
all_count = await fetch_scalar(session, qs.count())
first_page = await fetch_many(session, qs.paginate(page=1, per_page=10))
print(f"There are {all_count} available boyfriends")
print("Printing first page:")
for boyfriend in first_page:
print(boyfriend)
```