|
| 1 | +# Code generated by sqlc. DO NOT EDIT. |
| 2 | +# versions: |
| 3 | +# sqlc v1.31.1 |
| 4 | +# source: query.sql |
| 5 | +from typing import AsyncIterator, Iterator, Optional |
| 6 | + |
| 7 | +import my.module |
| 8 | +import sqlalchemy |
| 9 | +import sqlalchemy.ext.asyncio |
| 10 | + |
| 11 | +from db import models |
| 12 | + |
| 13 | + |
| 14 | +GET_JOB = """-- name: get_job \\:one |
| 15 | +SELECT id, status, priority FROM jobs |
| 16 | +WHERE id = :p1 LIMIT 1 |
| 17 | +""" |
| 18 | + |
| 19 | + |
| 20 | +LIST_JOBS_BY_STATUS = """-- name: list_jobs_by_status \\:many |
| 21 | +SELECT id, status, priority FROM jobs |
| 22 | +WHERE status = :p1 |
| 23 | +ORDER BY priority |
| 24 | +""" |
| 25 | + |
| 26 | + |
| 27 | +class Querier: |
| 28 | + def __init__(self, conn: sqlalchemy.engine.Connection): |
| 29 | + self._conn = conn |
| 30 | + |
| 31 | + def get_job(self, *, id: int) -> Optional[models.Job]: |
| 32 | + row = self._conn.execute(sqlalchemy.text(GET_JOB), {"p1": id}).first() |
| 33 | + if row is None: |
| 34 | + return None |
| 35 | + return models.Job( |
| 36 | + id=row[0], |
| 37 | + status=row[1], |
| 38 | + priority=row[2], |
| 39 | + ) |
| 40 | + |
| 41 | + def list_jobs_by_status(self, *, status: my.module.JobStatus) -> Iterator[models.Job]: |
| 42 | + result = self._conn.execute(sqlalchemy.text(LIST_JOBS_BY_STATUS), {"p1": status}) |
| 43 | + for row in result: |
| 44 | + yield models.Job( |
| 45 | + id=row[0], |
| 46 | + status=row[1], |
| 47 | + priority=row[2], |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +class AsyncQuerier: |
| 52 | + def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): |
| 53 | + self._conn = conn |
| 54 | + |
| 55 | + async def get_job(self, *, id: int) -> Optional[models.Job]: |
| 56 | + row = (await self._conn.execute(sqlalchemy.text(GET_JOB), {"p1": id})).first() |
| 57 | + if row is None: |
| 58 | + return None |
| 59 | + return models.Job( |
| 60 | + id=row[0], |
| 61 | + status=row[1], |
| 62 | + priority=row[2], |
| 63 | + ) |
| 64 | + |
| 65 | + async def list_jobs_by_status(self, *, status: my.module.JobStatus) -> AsyncIterator[models.Job]: |
| 66 | + rows = (await self._conn.execute(sqlalchemy.text(LIST_JOBS_BY_STATUS), {"p1": status})).all() |
| 67 | + for row in rows: |
| 68 | + yield models.Job( |
| 69 | + id=row[0], |
| 70 | + status=row[1], |
| 71 | + priority=row[2], |
| 72 | + ) |
0 commit comments