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

import sqlalchemy
import sqlalchemy.ext.asyncio

from . import models


FETCH_RESULT = """-- name: fetch_result \\:one
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) -> Optional[Optional[Any]]:
        row = self._conn.execute(sqlalchemy.text(FETCH_RESULT), {"p1": arg.task_id}).first()
        if row is None:
            return None
        return row[0]


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

    async def fetch_result(self, arg: FetchResultParams) -> Optional[Optional[Any]]:
        row = (await self._conn.execute(sqlalchemy.text(FETCH_RESULT), {"p1": arg.task_id})).first()
        if row is None:
            return None
        return row[0]
