felicity-lims/felicity/utils/psql.py
2023-09-11 08:20:47 +02:00

10 lines
371 B
Python

async def psql_records_to_dict(records, many=False):
"""Converts a database record(s) to dict
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]