You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

#include "DataBaseManager.h"
#include <QSqlDatabase>
#include <QxOrm.h>
DataBaseManager::DataBaseManager()
{
}
void DataBaseManager::init(const QMap<QString, QVariant> &conf)
{
auto driver = conf.find("driver")->toString();
auto host = conf.find("host")->toString();
auto port = conf.find("port")->toInt();
auto database = conf.find("database")->toString();
auto username = conf.find("username")->toString();
auto password = conf.find("password")->toString();
qx::QxSqlDatabase::getSingleton()->setDriverName(driver);
qx::QxSqlDatabase::getSingleton()->setDatabaseName(database);
qx::QxSqlDatabase::getSingleton()->setHostName(host);
qx::QxSqlDatabase::getSingleton()->setPort(port);
qx::QxSqlDatabase::getSingleton()->setUserName(username);
qx::QxSqlDatabase::getSingleton()->setPassword(password);
qx::QxSqlDatabase::getSingleton()->setFormatSqlQueryBeforeLogging(true);
QSqlDatabase db = qx::QxSqlDatabase::getSingleton()->getDatabase();
if (db.open()) {
qWarning("QxOrm is connect success!");
} else {
qWarning("QxOrm is connect failed!");
}
}