18 lines
434 B
Python
18 lines
434 B
Python
|
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
|