generated from Sithas/conan_template
Рабочая сборка с третьей ручкой
This commit is contained in:
+23
-15
@@ -9,7 +9,8 @@ using namespace string_literals;
|
|||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
MySQLUserDAO::MySQLUserDAO(mysqlx::Session& session) : session_(session)
|
MySQLUserDAO::MySQLUserDAO(mysqlx::Session& session) :
|
||||||
|
session_(session)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,10 +18,12 @@ string MySQLUserDAO::Create(const user& created_user)
|
|||||||
{
|
{
|
||||||
boost::uuids::random_generator generator;
|
boost::uuids::random_generator generator;
|
||||||
boost::uuids::uuid uuid = generator();
|
boost::uuids::uuid uuid = generator();
|
||||||
std::string uuid_str = boost::uuids::to_string(uuid);
|
const std::string uuid_str = boost::uuids::to_string(uuid);
|
||||||
|
|
||||||
string sql_script =
|
|
||||||
"INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES (?, ?, ?);"s;
|
const string sql_script =
|
||||||
|
"INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('"
|
||||||
|
+ uuid_str + "', '" + created_user.login +"', '" + created_user.hashed_password + "');"s;
|
||||||
|
|
||||||
session_.sql(sql_script)
|
session_.sql(sql_script)
|
||||||
.bind(uuid_str, created_user.login, created_user.hashed_password)
|
.bind(uuid_str, created_user.login, created_user.hashed_password)
|
||||||
@@ -31,18 +34,22 @@ string MySQLUserDAO::Create(const user& created_user)
|
|||||||
|
|
||||||
optional<user> MySQLUserDAO::GetByUUID(const string& uuid)
|
optional<user> MySQLUserDAO::GetByUUID(const string& uuid)
|
||||||
{
|
{
|
||||||
|
const string sql_script = "SELECT * FROM `up_and_down`.`users`"s +
|
||||||
|
"WHERE (uuid = '"s + uuid +
|
||||||
|
"') LIMIT 1;"s;
|
||||||
mysqlx::SqlResult sql_result = session_.
|
mysqlx::SqlResult sql_result = session_.
|
||||||
sql("SELECT * FROM `up_and_down`.`users` WHERE (uuid = '" + uuid +
|
sql(sql_script).execute();
|
||||||
"') LIMIT 1;"s).execute();
|
|
||||||
|
|
||||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<user> MySQLUserDAO::GetByLogin(const string& login)
|
optional<user> MySQLUserDAO::GetByLogin(const string& login)
|
||||||
{
|
{
|
||||||
|
const std::string sql_script = "SELECT * FROM `up_and_down`.`users`" +
|
||||||
|
"WHERE (login = '" + login
|
||||||
|
+ "') LIMIT 1;"s;
|
||||||
mysqlx::SqlResult sql_result = session_.
|
mysqlx::SqlResult sql_result = session_.
|
||||||
sql("SELECT * FROM `up_and_down`.`users` WHERE (login = '" + login
|
sql(sql_script).execute();
|
||||||
+ "') LIMIT 1;"s).execute();
|
|
||||||
|
|
||||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||||
}
|
}
|
||||||
@@ -50,8 +57,9 @@ optional<user> MySQLUserDAO::GetByLogin(const string& login)
|
|||||||
pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||||
{
|
{
|
||||||
mysqlx::SqlResult sql_result = session_
|
mysqlx::SqlResult sql_result = session_
|
||||||
.sql("SELECT * FROM `up_and_down`.`users` LIMIT ? OFFSET ?;"s)
|
.sql("SELECT * FROM `up_and_down`.`users` "s +
|
||||||
.bind(limit, offset)
|
"LIMIT "s + to_string(limit) +
|
||||||
|
" OFFSET "s + to_string(offset) + ";"s)
|
||||||
.execute();
|
.execute();
|
||||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||||
pair<bool, vector<user>> ret;
|
pair<bool, vector<user>> ret;
|
||||||
@@ -78,8 +86,8 @@ pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
|||||||
|
|
||||||
user user;
|
user user;
|
||||||
|
|
||||||
string user_uuid = row[0].get<string>();
|
const string user_uuid = row[0].get<string>();
|
||||||
string user_login = row[1].get<string>();
|
const string user_login = row[1].get<string>();
|
||||||
|
|
||||||
user.login = user_login;
|
user.login = user_login;
|
||||||
user.uuid = user_uuid;
|
user.uuid = user_uuid;
|
||||||
@@ -128,9 +136,9 @@ std::optional<user> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& s
|
|||||||
|
|
||||||
auto row_data = *rows.begin();
|
auto row_data = *rows.begin();
|
||||||
|
|
||||||
string user_uuid = row_data[0].get<string>();
|
const string user_uuid = row_data[0].get<string>();
|
||||||
string user_login = row_data[1].get<string>();
|
const string user_login = row_data[1].get<string>();
|
||||||
string user_hashed_password = row_data[2].get<string>();
|
const string user_hashed_password = row_data[2].get<string>();
|
||||||
|
|
||||||
user single_user;
|
user single_user;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user