vox-beta / _db_.py
EllenBeta's picture
Update _db_.py
86693c5 verified
raw
history blame contribute delete
638 Bytes
import psycopg2
from psycopg2 import OperationalError
import os
# Neon database connection string
CONN_STRING = os.getenv("CONN_URL")
def create_connection():
"""Create a connection to the Neon PostgreSQL database."""
try:
connection = psycopg2.connect(CONN_STRING)
print("โœ… Connection to Neon PostgreSQL DB successful")
return connection
except OperationalError as e:
print(f"โŒ The error '{e}' occurred")
return None
def close_connection(connection):
"""Close the database connection."""
if connection:
connection.close()
print("๐Ÿ”’ Connection closed")