dth-pingpong-backend/db.py

18 lines
434 B
Python
Raw Permalink Normal View History

2024-11-19 21:19:56 +01:00
import psycopg2
from psycopg2.extras import RealDictCursor
import os
from dotenv import load_dotenv
load_dotenv()
def get_db_connection():
conn = psycopg2.connect(
host=os.getenv("DB_HOST"),
port=os.getenv("DB_PORT"),
database=os.getenv("DB_NAME"),
user=os.getenv("DB_USER"),
password=os.getenv("DB_PASSWORD"),
cursor_factory=RealDictCursor
)
return conn