29 lines
784 B
Python
29 lines
784 B
Python
# This Python file uses the following encoding: utf-8
|
|
import toml
|
|
import mysql.connector
|
|
|
|
|
|
class DbManager(object):
|
|
__connection = None
|
|
__con_param = None
|
|
def __new__ (cls):
|
|
|
|
if not hasattr(cls, "__instance"):
|
|
cls.__instance = super().__new__(cls)
|
|
return cls.__instance
|
|
|
|
#def __init__ (self, dbconf, *args):
|
|
@classmethod
|
|
def connectDB(cls, dbconf):
|
|
|
|
con_param = cls.__initializeConfig(dbconf)
|
|
cls.__connection = mysql.connector.connect(**con_param)
|
|
return cls.__connection
|
|
|
|
def __initializeConfig(dbconf):
|
|
|
|
con_param = {'user': dbconf['DB_USER'], 'password': dbconf['DB_PASS'], 'port': int (dbconf['DB_PORT']), 'host': dbconf['DB_HOST'], 'database': dbconf['DB_NAME']}
|
|
|
|
return con_param
|
|
|