generated from Sithas/conan_template
DAO - доведение до конца
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ public:
|
|||||||
|
|
||||||
virtual std::optional<User> GetByLogin(std::string login) = 0;
|
virtual std::optional<User> GetByLogin(std::string login) = 0;
|
||||||
|
|
||||||
virtual std::vector<User> GetAll(size_t limit, size_t offset) = 0;
|
virtual std::pair<bool, std::vector<User>> GetAll(size_t limit, size_t offset) = 0;
|
||||||
|
|
||||||
virtual bool Update(const User& u) = 0;
|
virtual bool Update(const User& u) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -47,11 +47,49 @@ optional<User> MySQLUserDAO::GetByLogin(string login)
|
|||||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<User> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
pair<bool, vector<User>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||||
{
|
{
|
||||||
vector<User> users{};
|
mysqlx::SqlResult sql_result = session_
|
||||||
|
.sql("SELECT * FROM `up_and_down`.`users` LIMIT ? OFFSET ?;"s)
|
||||||
|
.bind(limit, offset)
|
||||||
|
.execute();
|
||||||
|
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||||
|
pair<bool, vector<User>> ret;
|
||||||
|
|
||||||
return {};
|
if (!rows.size())
|
||||||
|
{
|
||||||
|
ret.first = true
|
||||||
|
;
|
||||||
|
ret.second = vector<User>{};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.first = rows.size() < limit + 1;
|
||||||
|
ret.second = vector<User>{};
|
||||||
|
|
||||||
|
ret.second.reserve(limit);
|
||||||
|
|
||||||
|
for (const auto& row : rows)
|
||||||
|
{
|
||||||
|
if (!limit)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
User user;
|
||||||
|
|
||||||
|
string user_uuid = row[0].get<string>();
|
||||||
|
string user_login = row[1].get<string>();
|
||||||
|
|
||||||
|
user.SetLogin(user_login);
|
||||||
|
user.SetUUID(user_uuid);
|
||||||
|
|
||||||
|
ret.second.push_back(std::move(user));
|
||||||
|
--limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MySQLUserDAO::Update(const User& u)
|
bool MySQLUserDAO::Update(const User& u)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
|
|
||||||
std::optional<User> GetByLogin(std::string login) override;
|
std::optional<User> GetByLogin(std::string login) override;
|
||||||
|
|
||||||
std::vector<User> GetAll(size_t limit, size_t offset) override;
|
std::pair<bool, std::vector<User>> GetAll(size_t limit, size_t offset) override;
|
||||||
|
|
||||||
bool Update(const User& u) override;
|
bool Update(const User& u) override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user