Skip to content

Commit b2cf502

Browse files
committed
Added row_factory method for query results
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent 5f2355e commit b2cf502

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

python/tests/test_value_converter.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,33 @@ def point_encoder(point_bytes: bytes) -> str:
571571
)
572572

573573
assert result[0]["geo_point"] == "Just An Example"
574+
575+
576+
async def test_row_factory_query_result(
577+
psql_pool: ConnectionPool,
578+
table_name: str,
579+
number_database_records: int,
580+
) -> None:
581+
select_result = await psql_pool.execute(
582+
f"SELECT * FROM {table_name}",
583+
)
584+
585+
def row_factory(db_result: dict[str, Any]) -> list[str]:
586+
return list(db_result.keys())
587+
588+
as_pydantic = select_result.row_factory(
589+
row_factory=row_factory,
590+
)
591+
assert len(as_pydantic) == number_database_records
592+
593+
for single_record in as_pydantic:
594+
assert isinstance(single_record, DefaultPydanticModel)
595+
596+
as_py_class = select_result.as_class(
597+
as_class=DefaultPythonModelClass,
598+
)
599+
600+
assert len(as_py_class) == number_database_records
601+
602+
for single_py_record in as_py_class:
603+
assert isinstance(single_py_record, DefaultPythonModelClass)

0 commit comments

Comments
 (0)