DAO - доведение до конца

This commit is contained in:
Антон
2025-08-31 09:49:57 +03:00
parent eb22915b76
commit af321ff534
3 changed files with 43 additions and 5 deletions
+41 -3
View File
@@ -47,11 +47,49 @@ optional<User> MySQLUserDAO::GetByLogin(string login)
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)