22 lines
558 B
Python
22 lines
558 B
Python
import psycopg2
|
|
import os
|
|
|
|
def get_db_connection():
|
|
db_uri = os.getenv("DB_URI")
|
|
print("test")
|
|
if not db_uri:
|
|
raise ValueError("DB_URI 환경변수 없음.")
|
|
|
|
try:
|
|
conn = psycopg2.connect(db_uri)
|
|
cursor = conn.cursor()
|
|
cursor.execute("SELECT version();")
|
|
db_version = cursor.fetchone()
|
|
print(f"Connected to the database. Version: {db_version[0]}")
|
|
|
|
cursor.close()
|
|
conn.close()
|
|
|
|
except Exception as e:
|
|
print(f"Error connecting to the database: {e}")
|
|
raise |