Spaces:
Running on Zero
Running on Zero
Download app/db/repos/groups.py from cipher-attacks/Dbu-central-bot: direct link, hf CLI and curl.
- Browser
- Download file 672 Bytes
-
https://huggingface.co/spaces/cipher-attacks/Dbu-central-bot/resolve/main/app/db/repos/groups.py
- Command line
-
hf download hf://spaces/cipher-attacks/Dbu-central-bot/app/db/repos/groups.py
-
curl -L -o groups.py https://huggingface.co/spaces/cipher-attacks/Dbu-central-bot/resolve/main/app/db/repos/groups.py
672 Bytes
| from typing import Optional | |
| from sqlalchemy import func, select | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from app.db.models import BotGroup | |
| async def upsert(session: AsyncSession, chat_id: int, title: Optional[str], active: bool) -> None: | |
| group = await session.get(BotGroup, chat_id) | |
| if group: | |
| group.title, group.active = title, active | |
| else: | |
| session.add(BotGroup(chat_id=chat_id, title=title, active=active)) | |
| await session.flush() | |
| async def count_active(session: AsyncSession) -> int: | |
| res = await session.execute(select(func.count()).select_from(BotGroup).where(BotGroup.active.is_(True))) | |
| return int(res.scalar_one()) | |