Spaces:
Running on T4
Running on T4
Download backend/app/modules/billing/repository.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/modules/billing/repository.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/backend/app/modules/billing/repository.py
-
curl -L -o repository.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/modules/billing/repository.py
1.09 kB
| """Subscription rows, keyed by the store's stable transaction id.""" | |
| from sqlalchemy import select | |
| from sqlalchemy.dialects.postgresql import insert | |
| from app.common.base_repository import BaseRepository | |
| from app.modules.billing.models import Subscription | |
| class SubscriptionRepository(BaseRepository[Subscription]): | |
| model = Subscription | |
| async def lock_by_original_id(self, original_transaction_id: str) -> Subscription | None: | |
| result = await self.session.execute(select(Subscription).where( | |
| Subscription.original_transaction_id == original_transaction_id).with_for_update()) | |
| return result.scalars().first() | |
| async def insert_if_absent(self, **values) -> bool: | |
| """Inserts unless the original_transaction_id exists (concurrent posts are safe). Returns True if inserted.""" | |
| result = await self.session.execute( | |
| insert(Subscription).values(**values) | |
| .on_conflict_do_nothing(index_elements=[Subscription.original_transaction_id]) | |
| .returning(Subscription.id)) | |
| return result.scalar() is not None | |