github-actions[bot]
Automated Deploy: 83f1f6fa59ef9d22788ee608e3ba12967f91dd5c
ae2c68f
Raw History Blame Contribute Delete
552 Bytes
"""Display names for a set of accounts in one query."""
from collections.abc import Iterable
from uuid import UUID
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.modules.accounts.models import Account
async def account_names(session: AsyncSession, ids: Iterable[UUID | None]) -> dict[UUID, str | None]:
wanted = {i for i in ids if i}
if not wanted:
return {}
rows = await session.execute(select(Account.id, Account.name).where(Account.id.in_(wanted)))
return {i: n for i, n in rows}