Modify the createDbClient() method

This commit is contained in:
antao 2019-01-10 13:24:03 +08:00
parent 5f108b510d
commit e8c7cf3c72
2 changed files with 13 additions and 1 deletions

View File

@ -231,9 +231,9 @@ static void loadApp(const Json::Value &app)
}
static void loadDbClients(const Json::Value &dbClients)
{
#if USE_ORM
if (!dbClients)
return;
#if USE_ORM
for (auto &client : dbClients)
{
auto type = client.get("rdbms", "postgresql").asString();
@ -252,6 +252,9 @@ static void loadDbClients(const Json::Value &dbClients)
auto filename = client.get("filename", "").asString();
drogon::app().createDbClient(type, host, (u_short)port, dbname, user, password, connNum, filename, name);
}
#else
std::cout << "No database is supported by drogon, please install the database development library first." << std::endl;
exit(1);
#endif
}
static void loadListeners(const Json::Value &listeners)

View File

@ -1277,6 +1277,9 @@ void HttpAppFrameworkImpl::createDbClient(const std::string &dbType,
#if USE_POSTGRESQL
auto client = drogon::orm::DbClient::newPgClient(connStr, connectionNum);
_dbClientsMap[name] = client;
#else
std::cout << "The PostgreSQL is not supported by drogon, please install the development library first." << std::endl;
exit(1);
#endif
}
else if (type == "mysql")
@ -1284,6 +1287,9 @@ void HttpAppFrameworkImpl::createDbClient(const std::string &dbType,
#if USE_MYSQL
auto client = drogon::orm::DbClient::newMysqlClient(connStr, connectionNum);
_dbClientsMap[name] = client;
#else
std::cout << "The Mysql is not supported by drogon, please install the development library first." << std::endl;
exit(1);
#endif
}
else if (type == "sqlite3")
@ -1292,6 +1298,9 @@ void HttpAppFrameworkImpl::createDbClient(const std::string &dbType,
std::string sqlite3ConnStr = "filename=" + filename;
auto client = drogon::orm::DbClient::newSqlite3Client(sqlite3ConnStr, connectionNum);
_dbClientsMap[name] = client;
#else
std::cout << "The Sqlite3 is not supported by drogon, please install the development library first." << std::endl;
exit(1);
#endif
}
}