I'm trying to get the PostgreSQL database connection in the python flask app and I would like to get it return the rows so I can have a name-based access to columns. I've tried to do it in accordance with Psycopg2 documentation, but wasn't successful.
Here's the code:
def get_connection():
conn = psycopg2.connect(dbname=DB_USER, user=DB_USER, password=DB_PASS, host=DB_HOST)
cur = conn.cursor(cursor_factory=psycopg2.extras.DictRow)
return cur
According to the documentation it seems fine but I'm getting an error:
File "/app/app.py", line 34, in get_connection
cur = conn.cursor(cursor_factory=psycopg2.extras.DictRow)
TypeError: __init__() takes 2 positional arguments but 3 were given
Can somebody please help me out with this?
Thank you.