revelupex/connect.py

18 lines
462 B
Python
Raw Permalink Normal View History

2024-08-10 19:47:47 +00:00
import psycopg2
from config import load_config
def connect(config):
""" Connect to the PostgreSQL database server """
try:
# connecting to the PostgreSQL server
with psycopg2.connect(**config) as conn:
print('Connected to the PostgreSQL server.')
return conn
except (psycopg2.DatabaseError, Exception) as error:
print(error)
if __name__ == '__main__':
config = load_config()
connect(config)