25 lines
633 B
Python
25 lines
633 B
Python
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
import psycopg
|
|
from psycopg.rows import dict_row
|
|
|
|
|
|
def connect_db():
|
|
return psycopg.connect(
|
|
host=os.getenv("PGHOST", "postgres"),
|
|
port=int(os.getenv("PGPORT", "5432")),
|
|
dbname=os.getenv("PGDATABASE", "messenger"),
|
|
user=os.getenv("PGUSER", "messenger"),
|
|
password=os.environ["PGPASSWORD"],
|
|
connect_timeout=3,
|
|
autocommit=True,
|
|
row_factory=dict_row,
|
|
options=(
|
|
"-c statement_timeout=3000 "
|
|
"-c lock_timeout=2000 "
|
|
"-c idle_in_transaction_session_timeout=60000"
|
|
),
|
|
)
|