import asyncpg from utils.read.models import AccountView async def self_user_id(pool: asyncpg.Pool, account_id: int) -> int | None: return await pool.fetchval( "SELECT tg_user_id FROM accounts WHERE account_id = $1", account_id ) async def list_accounts(pool: asyncpg.Pool) -> list[AccountView]: rows = await pool.fetch( "SELECT account_id, label, phone, tg_user_id, is_active FROM accounts " "ORDER BY account_id" ) return [AccountView(**dict(row)) for row in rows]