Skip to content

Commit cce4d7d

Browse files
Expect UUID instead of str for ids on queries now.
1 parent f7f7c78 commit cce4d7d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

db_wrapper/model/async_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Asynchronous Model objects."""
22

33
from typing import Any, Dict, List
4+
from uuid import UUID
45

56
from db_wrapper.client import AsyncClient
67
from .base import (
@@ -45,7 +46,7 @@ def __init__(self, client: AsyncClient, table: sql.Composable) -> None:
4546
super().__init__(table)
4647
self._client = client
4748

48-
async def one_by_id(self, id_value: str) -> T:
49+
async def one_by_id(self, id_value: UUID) -> T:
4950
"""Read a row by it's id."""
5051
result: List[T] = await self._client.execute_and_return(
5152
self._query_one_by_id(id_value))

db_wrapper/model/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ class ReadABC(Generic[T]):
105105
def __init__(self, table: sql.Composable) -> None:
106106
self._table = table
107107

108-
def _query_one_by_id(self, id_value: str) -> sql.Composed:
108+
def _query_one_by_id(self, id_value: UUID) -> sql.Composed:
109109
"""Build query to read a row by it's id."""
110110
query = sql.SQL(
111111
'SELECT * '
112112
'FROM {table} '
113113
'WHERE id = {id_value};'
114114
).format(
115115
table=self._table,
116-
id_value=sql.Literal(id_value)
116+
id_value=sql.Literal(str(id_value))
117117
)
118118

119119
return query

db_wrapper/model/sync_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Synchronous Model objects."""
22

33
from typing import Any, Dict, List
4+
from uuid import UUID
45

56
from db_wrapper.client import SyncClient
67
from .base import (
@@ -45,7 +46,7 @@ def __init__(self, client: SyncClient, table: sql.Composable) -> None:
4546
super().__init__(table)
4647
self._client = client
4748

48-
def one_by_id(self, id_value: str) -> T:
49+
def one_by_id(self, id_value: UUID) -> T:
4950
"""Read a row by it's id."""
5051
result: List[T] = self._client.execute_and_return(
5152
self._query_one_by_id(id_value))

0 commit comments

Comments
 (0)