database connection
This commit is contained in:
@@ -52,7 +52,7 @@ class ConfigLoader(QObject):
|
||||
|
||||
|
||||
def getConfig(self):
|
||||
print(self.__config['database'])
|
||||
|
||||
return self.__config
|
||||
|
||||
def createConfig(self):
|
||||
|
||||
@@ -13,7 +13,7 @@ class BusinessModel(QAbstractTableModel):
|
||||
|
||||
def __getData(self):
|
||||
cursor = self.con.cursor()
|
||||
cursor.execute("SELECT * FROM test")
|
||||
cursor.execute("SELECT * FROM users")
|
||||
return cursor.fetchall()
|
||||
|
||||
def rowCount(self, parent= QModelIndex()):
|
||||
|
||||
@@ -7,16 +7,22 @@ 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):
|
||||
__con_param = __initializeConfig(dbconf)
|
||||
self.__connection = mysql.connector.connect(__con_param)
|
||||
return self.__connection
|
||||
#def __init__ (self, dbconf, *args):
|
||||
@classmethod
|
||||
def connectDB(cls, dbconf):
|
||||
|
||||
def __initializeConfig(self, dbconf):
|
||||
__con_param = {'user': dbconf['DB_USER'], 'password': dbconf['DB_PASS'], 'port': dbconf['DB_PORT'], 'host': dbconf['DB_HOST'], 'name': dbconf['DB_NAME']}
|
||||
return __con_param
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user