didier/functions/database/utils.py

32 lines
500 B
Python
Raw Normal View History

import psycopg2
2021-06-19 20:11:55 +02:00
from settings import DB_HOST, DB_NAME, DB_USERNAME, DB_PASSWORD
connection = None
def connect():
global connection
if connection is None:
create_connection()
return connection
def create_connection():
global connection
connection = psycopg2.connect(
2021-06-19 20:11:55 +02:00
host=DB_HOST,
database=DB_NAME,
user=DB_USERNAME,
password=DB_PASSWORD
)
def reconnect():
global connection
connection.close()
create_connection()