2020-10-13 21:02:40 +02:00
|
|
|
import psycopg2
|
2021-06-19 20:11:55 +02:00
|
|
|
from settings import DB_HOST, DB_NAME, DB_USERNAME, DB_PASSWORD
|
2020-10-13 21:02:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2020-10-13 21:02:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def reconnect():
|
|
|
|
global connection
|
|
|
|
|
|
|
|
connection.close()
|
|
|
|
create_connection()
|