File size: 552 Bytes
ae2c68f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""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}