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

import sqlalchemy
import sqlalchemy.ext.asyncio

from . import models


GET_CRON_JOB_RUN_DETAILS = """-- name: get_cron_job_run_details \\:many
SELECT 
    jobid,
    runid,
    command,
    status,
    schedule_time,
    start_time,
    end_time
FROM hyrex_cron_job_run_details
WHERE jobid = :p1
ORDER BY schedule_time DESC
LIMIT 100
"""


@dataclasses.dataclass()
class GetCronJobRunDetailsParams:
    jobid: int


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

    def get_cron_job_run_details(self, arg: GetCronJobRunDetailsParams) -> Iterator[models.HyrexCronJobRunDetail]:
        result = self._conn.execute(sqlalchemy.text(GET_CRON_JOB_RUN_DETAILS), {"p1": arg.jobid})
        for row in result:
            yield models.HyrexCronJobRunDetail(
                jobid=row[0],
                runid=row[1],
                command=row[2],
                status=row[3],
                schedule_time=row[4],
                start_time=row[5],
                end_time=row[6],
            )


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

    async def get_cron_job_run_details(self, arg: GetCronJobRunDetailsParams) -> AsyncIterator[models.HyrexCronJobRunDetail]:
        result = await self._conn.stream(sqlalchemy.text(GET_CRON_JOB_RUN_DETAILS), {"p1": arg.jobid})
        async for row in result:
            yield models.HyrexCronJobRunDetail(
                jobid=row[0],
                runid=row[1],
                command=row[2],
                status=row[3],
                schedule_time=row[4],
                start_time=row[5],
                end_time=row[6],
            )
