www_site/services/api/app/db.py

15 lines
339 B
Python

from collections.abc import Generator
import psycopg
from psycopg.rows import dict_row
from .config import settings
def get_connection() -> Generator[psycopg.Connection, None, None]:
connection = psycopg.connect(settings.database_url, row_factory=dict_row)
try:
yield connection
finally:
connection.close()