generated from Sithas/conan_template
соединение с базой!
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#include <string>
|
||||
|
||||
#include "mysql_connector.h"
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
namespace uad
|
||||
{
|
||||
static mysqlx::Session* mysql_session = nullptr;
|
||||
|
||||
void SetMySqlSession(mysqlx::Session* ptr)
|
||||
{
|
||||
mysql_session = ptr;
|
||||
}
|
||||
|
||||
mysqlx::Session& GetMySqlSession()
|
||||
{
|
||||
mysqlx::Schema schema = mysql_session->getSchema("up_and_down"s);
|
||||
|
||||
return *mysql_session;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <mysqlx/xdevapi.h>
|
||||
|
||||
namespace uad
|
||||
{
|
||||
void SetMySqlSession(mysqlx::Session* ptr);
|
||||
|
||||
mysqlx::Session& GetMySqlSession();
|
||||
}
|
||||
+10
-2
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "./session/WebsocketSession.h"
|
||||
#include "./listener/Listener.h"
|
||||
#include "./db/mysql_connector.h"
|
||||
|
||||
namespace beast = boost::beast;
|
||||
namespace http = beast::http;
|
||||
@@ -24,12 +25,14 @@ namespace websocket = beast::websocket;
|
||||
namespace net = boost::asio;
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
using namespace uad;
|
||||
using namespace std;
|
||||
using namespace std::string_literals;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 5)
|
||||
if (argc != 6)
|
||||
{
|
||||
std::cerr << "Usage: advanced-server <address> <port> <doc_root> <threads>\n"
|
||||
std::cerr << "Usage: advanced-server <address> <port> <doc_root> <threads> <mysqlx://user:password@localhost:3306>\n"
|
||||
<< "Example:\n"
|
||||
<< " advanced-server 0.0.0.0 8080 . 1\n";
|
||||
return EXIT_FAILURE;
|
||||
@@ -38,6 +41,11 @@ int main(int argc, char* argv[])
|
||||
auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
|
||||
auto const doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
string mysql_credentials = argv[5];
|
||||
|
||||
mysqlx::Session session(mysql_credentials);
|
||||
|
||||
uad::SetMySqlSession(&session);
|
||||
|
||||
net::io_context ioc{threads};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user