Spaces:
Runtime error
Runtime error
Download _db_.py from Joe6636564/lynkup: direct link, hf CLI and curl.
- Browser
- Download file 623 Bytes
-
https://huggingface.co/spaces/Joe6636564/lynkup/resolve/main/_db_.py
- Command line
-
hf download hf://spaces/Joe6636564/lynkup/_db_.py
-
curl -L -o _db_.py https://huggingface.co/spaces/Joe6636564/lynkup/resolve/main/_db_.py
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") | |