From 5dcf235a70a5e2fc84265207f3a55b685fc66612 Mon Sep 17 00:00:00 2001 From: ansipunk Date: Sun, 3 Mar 2024 12:43:43 +0500 Subject: [PATCH] S01E05 --- databases/backends/psycopg.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/databases/backends/psycopg.py b/databases/backends/psycopg.py index 885e8336..f25d456f 100644 --- a/databases/backends/psycopg.py +++ b/databases/backends/psycopg.py @@ -2,6 +2,7 @@ import psycopg import psycopg_pool +from psycopg.rows import namedtuple_row from sqlalchemy.engine.interfaces import Dialect from sqlalchemy.dialects.postgresql.psycopg import PGDialect_psycopg from sqlalchemy.sql import ClauseElement @@ -88,7 +89,7 @@ async def fetch_all(self, query: ClauseElement) -> typing.List[RecordInterface]: query_str, args, result_columns = self._compile(query) - async with self._connection.cursor() as cursor: + async with self._connection.cursor(row_factory=namedtuple_row) as cursor: await cursor.execute(query_str, args) rows = await cursor.fetchall() @@ -101,7 +102,7 @@ async def fetch_one(self, query: ClauseElement) -> typing.Optional[RecordInterfa query_str, args, result_columns = self._compile(query) - async with self._connection.cursor() as cursor: + async with self._connection.cursor(row_factory=namedtuple_row) as cursor: await cursor.execute(query_str, args) row = await cursor.fetchone() @@ -127,7 +128,7 @@ async def execute(self, query: ClauseElement) -> typing.Any: query_str, args, _ = self._compile(query) - async with self._connection.cursor() as cursor: + async with self._connection.cursor(row_factory=namedtuple_row) as cursor: await cursor.execute(query_str, args) async def execute_many(self, queries: typing.List[ClauseElement]) -> None: @@ -144,7 +145,7 @@ async def iterate( query_str, args, result_columns = self._compile(query) column_maps = create_column_maps(result_columns) - async with self._connection.cursor() as cursor: + async with self._connection.cursor(row_factory=namedtuple_row) as cursor: await cursor.execute(query_str, args) while True: