lynkup / _db_.py
Devity4756's picture
begaj
6751ba4
Raw History Blame Contribute Delete
623 Bytes
import psycopg2
from psycopg2 import OperationalError
# Neon database connection string
def create_connection(CONN_STRING):
"""Create a connection to the Neon PostgreSQL database."""
try:
connection = psycopg2.connect(CONN_STRING, sslmode="require")
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")