# Code generated by sqlc. DO NOT EDIT.
# versions:
#   sqlc v1.29.0
# source: fetch_result.sql
import dataclasses
from typing import Any, AsyncIterator, Iterator, Optional
import uuid

import sqlalchemy
import sqlalchemy.ext.asyncio

from . import models


FETCH_RESULT = """-- name: fetch_result \\:many
SELECT result
FROM hyrex_task_result
WHERE task_id = :p1
"""


@dataclasses.dataclass()
class FetchResultParams:
    task_id: uuid.UUID


class Querier:
    def __init__(self, conn: sqlalchemy.engine.Connection):
        self._conn = conn

    def fetch_result(self, arg: FetchResultParams) -> Iterator[Optional[Any]]:
        result = self._conn.execute(sqlalchemy.text(FETCH_RESULT), {"p1": arg.task_id})
        for row in result:
            yield row[0]


class AsyncQuerier:
    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
        self._conn = conn

    async def fetch_result(self, arg: FetchResultParams) -> AsyncIterator[Optional[Any]]:
        result = await self._conn.stream(sqlalchemy.text(FETCH_RESULT), {"p1": arg.task_id})
        async for row in result:
            yield row[0]
