Commit ac0fc1af authored by Anthony Jacob's avatar Anthony Jacob
Browse files

add a db helpers

parent 88530939
Loading
Loading
Loading
Loading

app/helpers/db.py

0 → 100644
+13 −0
Original line number Diff line number Diff line
from contextlib import contextmanager
from flask import current_app
from psycopg.rows import dict_row

@contextmanager
def db_cursor(dict_results=False):
    try:
        with current_app.db_pool.connection() as conn:
            with conn.cursor(row_factory=dict_row if dict_results else None) as cur:
                yield conn, cur
    except Exception as e:
        current_app.logger.error(f"Database error: {e}")
        raise
 No newline at end of file