refactor
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2024-10-22 19:11:00 -05:00
parent 84fc05acc0
commit 18c53fad9a
8 changed files with 55 additions and 56 deletions

View File

@ -24,8 +24,8 @@
#include "utils/db/sqlite/db_insert.hpp"
namespace repertory::utils::db::sqlite {
auto db_insert::column_value(std::string column_name, db_types_t value)
-> db_insert & {
auto db_insert::column_value(std::string column_name,
db_types_t value) -> db_insert & {
ctx_->values[column_name] = value;
return *this;
}
@ -71,17 +71,17 @@ auto db_insert::go() const -> db_result {
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(ctx_->values.size()); idx++) {
res = std::visit(overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(ctx_->stmt.get(), idx + 1,
data);
},
[this, &idx](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(ctx_->stmt.get(), idx + 1,
data.c_str(), -1, nullptr);
},
},
std::next(ctx_->values.begin(), idx)->second);
res = std::visit(
overloaded{
[&idx, &stmt_ptr](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(stmt_ptr, idx + 1, data);
},
[&idx, &stmt_ptr](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(stmt_ptr, idx + 1, data.c_str(), -1,
nullptr);
},
},
std::next(ctx_->values.begin(), idx)->second);
if (res != SQLITE_OK) {
return {stmt_ptr, res};
}

View File

@ -62,8 +62,8 @@ auto db_select::column(std::string column_name) -> db_select & {
return *this;
}
auto db_select::count(std::string column_name, std::string as_column_name)
-> db_select & {
auto db_select::count(std::string column_name,
std::string as_column_name) -> db_select & {
ctx_->count_columns[column_name] = as_column_name;
return *this;
}
@ -151,12 +151,12 @@ auto db_select::go() const -> db_result {
idx++) {
res = std::visit(
overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(ctx_->stmt.get(), idx + 1, data);
[&idx, &stmt_ptr](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(stmt_ptr, idx + 1, data);
},
[this, &idx](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(ctx_->stmt.get(), idx + 1, data.c_str(),
-1, nullptr);
[&idx, &stmt_ptr](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(stmt_ptr, idx + 1, data.c_str(), -1,
nullptr);
},
},
ctx_->where_data->values.at(static_cast<std::size_t>(idx)));
@ -195,8 +195,8 @@ auto db_select::offset(std::int32_t value) -> db_select & {
return *this;
}
auto db_select::order_by(std::string column_name, bool ascending)
-> db_select & {
auto db_select::order_by(std::string column_name,
bool ascending) -> db_select & {
ctx_->order_by = {column_name, ascending};
return *this;
}

View File

@ -45,8 +45,8 @@ auto db_update::context::db_update_op_t::order_by(std::string column_name,
return *this;
}
auto db_update::column_value(std::string column_name, db_types_t value)
-> db_update & {
auto db_update::column_value(std::string column_name,
db_types_t value) -> db_update & {
ctx_->column_values[column_name] = value;
return *this;
}
@ -97,17 +97,17 @@ auto db_update::go() const -> db_result {
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(ctx_->column_values.size()); idx++) {
res = std::visit(overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(ctx_->stmt.get(), idx + 1,
data);
},
[this, &idx](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(ctx_->stmt.get(), idx + 1,
data.c_str(), -1, nullptr);
},
},
std::next(ctx_->column_values.begin(), idx)->second);
res = std::visit(
overloaded{
[&stmt_ptr, &idx](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(stmt_ptr, idx + 1, data);
},
[&stmt_ptr, &idx](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(stmt_ptr, idx + 1, data.c_str(), -1,
nullptr);
},
},
std::next(ctx_->column_values.begin(), idx)->second);
if (res != SQLITE_OK) {
return {stmt_ptr, res};
}
@ -122,16 +122,16 @@ auto db_update::go() const -> db_result {
idx++) {
res = std::visit(
overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
[this, &idx, &stmt_ptr](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(
ctx_->stmt.get(),
stmt_ptr,
idx + static_cast<std::int32_t>(ctx_->column_values.size()) +
1,
data);
},
[this, &idx](const std::string &data) -> std::int32_t {
[this, &idx, &stmt_ptr](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(
ctx_->stmt.get(),
stmt_ptr,
idx + static_cast<std::int32_t>(ctx_->column_values.size()) +
1,
data.c_str(), -1, nullptr);
@ -163,8 +163,8 @@ auto db_update::limit(std::int32_t value) -> db_update & {
return *this;
}
auto db_update::order_by(std::string column_name, bool ascending)
-> db_update & {
auto db_update::order_by(std::string column_name,
bool ascending) -> db_update & {
ctx_->order_by = {column_name, ascending};
return *this;
}

View File

@ -19,10 +19,11 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <utils/config.hpp>
#if !defined(_WIN32)
#include "utils/unix.hpp"
#include "utils/collection.hpp"
#include "utils/unix.hpp"
namespace repertory::utils {
#if !defined(__APPLE__)
@ -39,7 +40,7 @@ auto get_thread_id() -> std::uint64_t {
auto is_uid_member_of_group(const uid_t &uid, const gid_t &gid) -> bool {
std::vector<gid_t> groups{};
use_getpwuid(uid, [&groups](struct passwd *pass) {
auto res = use_getpwuid(uid, [&groups](struct passwd *pass) {
int group_count{};
if (getgrouplist(pass->pw_name, pass->pw_gid, nullptr, &group_count) < 0) {
groups.resize(static_cast<std::size_t>(group_count));
@ -52,6 +53,11 @@ auto is_uid_member_of_group(const uid_t &uid, const gid_t &gid) -> bool {
}
});
if (not res.ok) {
throw utils::error::create_exception(res.function_name,
{"use_getpwuid failed", res.reason});
}
return collection::includes(groups, gid);
}