from typing import Sequence, Type, TypeVar, Union, TYPE_CHECKING
from . import errors as e
+from .rows import dict_row
from .proto import AdaptContext
if TYPE_CHECKING:
if isinstance(name, Composable):
name = name.as_string(conn)
- cur = conn.cursor(binary=True, row_factory=None)
+ cur = conn.cursor(binary=True, row_factory=dict_row)
cur.execute(cls._info_query, {"name": name})
- recs: Sequence[Sequence[Any]] = cur.fetchall()
- fields = [d[0] for d in cur.description or ()]
- return cls._fetch(name, fields, recs)
+ recs: Sequence[Dict[str, Any]] = cur.fetchall()
+ return cls._fetch(name, recs)
@classmethod
async def fetch_async(
if isinstance(name, Composable):
name = name.as_string(conn)
- cur = conn.cursor(binary=True, row_factory=None)
+ cur = conn.cursor(binary=True, row_factory=dict_row)
await cur.execute(cls._info_query, {"name": name})
- recs: Sequence[Sequence[Any]] = await cur.fetchall()
- fields = [d[0] for d in cur.description or ()]
- return cls._fetch(name, fields, recs)
+ recs: Sequence[Dict[str, Any]] = await cur.fetchall()
+ return cls._fetch(name, recs)
@classmethod
def _fetch(
cls: Type[T],
name: str,
- fields: Sequence[str],
- recs: Sequence[Sequence[Any]],
+ recs: Sequence[Dict[str, Any]],
) -> Optional[T]:
if len(recs) == 1:
- return cls(**dict(zip(fields, recs[0])))
+ return cls(**recs[0])
elif not recs:
return None
else:
class RowMaker(Protocol):
- def __call__(self, __values: Sequence[Any]) -> Row:
+ def __call__(self, __values: Sequence[Any]) -> Any:
...
class RowFactory(Protocol):
- def __call__(
- self, __cursor: "BaseCursor[ConnectionType]"
- ) -> Optional[RowMaker]:
+ def __call__(self, __cursor: "BaseCursor[Any]") -> Optional[RowMaker]:
...