generated from Sithas/conan_template
соединение с базой!
This commit is contained in:
@@ -35,6 +35,8 @@ add_executable(App ./src/main.cpp
|
|||||||
./src/session/WebsocketSession.cpp
|
./src/session/WebsocketSession.cpp
|
||||||
./src/listener/Listener.h
|
./src/listener/Listener.h
|
||||||
./src/listener/Listener.cpp
|
./src/listener/Listener.cpp
|
||||||
|
./src/db/mysql_connector.cpp
|
||||||
|
./src/db/mysql_connector.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(App PRIVATE Boost::boost Threads::Threads mysql::concpp)
|
target_link_libraries(App PRIVATE Boost::boost Threads::Threads mysql::concpp)
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ CREATE TABLE `up_and_down`.`anxiety` (
|
|||||||
PRIMARY KEY (`level`)
|
PRIMARY KEY (`level`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE `up_and_down`.`user_treatment_schemes` (
|
||||||
|
`guid` CHAR(36) NOT NULL,
|
||||||
|
`user_guid` CHAR(36) NOT NULL,
|
||||||
|
`treatment_name` TEXT NOT NULL,
|
||||||
|
`instructions` TEXT,
|
||||||
|
PRIMARY KEY (`guid`),
|
||||||
|
FOREIGN KEY (`user_guid`) REFERENCES `users`(`guid`)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE `up_and_down`.`diaries` (
|
CREATE TABLE `up_and_down`.`diaries` (
|
||||||
`guid` CHAR(36) NOT NULL,
|
`guid` CHAR(36) NOT NULL,
|
||||||
`user_guid` CHAR(36) NOT NULL,
|
`user_guid` CHAR(36) NOT NULL,
|
||||||
@@ -93,15 +102,6 @@ CREATE TABLE `up_and_down`.`treatment_schemes` (
|
|||||||
FOREIGN KEY (`medication_guid`) REFERENCES `medications`(`guid`)
|
FOREIGN KEY (`medication_guid`) REFERENCES `medications`(`guid`)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE `up_and_down`.`user_treatment_schemes` (
|
|
||||||
`guid` CHAR(36) NOT NULL,
|
|
||||||
`user_guid` CHAR(36) NOT NULL,
|
|
||||||
`treatment_name` TEXT NOT NULL,
|
|
||||||
`instructions` TEXT,
|
|
||||||
PRIMARY KEY (`guid`),
|
|
||||||
FOREIGN KEY (`user_guid`) REFERENCES `users`(`guid`)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- insert constants
|
-- insert constants
|
||||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (1, 'Полное отсутствие мании');
|
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (1, 'Полное отсутствие мании');
|
||||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (2, 'Слегка приподнятое настроение');
|
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (2, 'Слегка приподнятое настроение');
|
||||||
|
|||||||
@@ -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 "./session/WebsocketSession.h"
|
||||||
#include "./listener/Listener.h"
|
#include "./listener/Listener.h"
|
||||||
|
#include "./db/mysql_connector.h"
|
||||||
|
|
||||||
namespace beast = boost::beast;
|
namespace beast = boost::beast;
|
||||||
namespace http = beast::http;
|
namespace http = beast::http;
|
||||||
@@ -24,12 +25,14 @@ namespace websocket = beast::websocket;
|
|||||||
namespace net = boost::asio;
|
namespace net = boost::asio;
|
||||||
using tcp = boost::asio::ip::tcp;
|
using tcp = boost::asio::ip::tcp;
|
||||||
using namespace uad;
|
using namespace uad;
|
||||||
|
using namespace std;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
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"
|
<< "Example:\n"
|
||||||
<< " advanced-server 0.0.0.0 8080 . 1\n";
|
<< " advanced-server 0.0.0.0 8080 . 1\n";
|
||||||
return EXIT_FAILURE;
|
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 port = static_cast<unsigned short>(std::atoi(argv[2]));
|
||||||
auto const doc_root = std::make_shared<std::string>(argv[3]);
|
auto const doc_root = std::make_shared<std::string>(argv[3]);
|
||||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
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};
|
net::io_context ioc{threads};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user