felicity-lims/felicity/utils/psql.py

11 lines
371 B
Python
Raw Normal View History

async def psql_records_to_dict(records, many=False):
2023-09-11 14:20:47 +08:00
"""Converts a database record(s) to dict
2021-01-06 19:52:14 +08:00
database usually return a databases.backends.postgres.Record
or if you access the ._row key you get the asyncpg.Record
"""
if not records:
return records
if not many:
return dict(records)
return [dict(record) for record in records]