File size: 638 Bytes
ef03156 86693c5 ef03156 86693c5 ef03156 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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")
|