From b84202a689e4436230e44dcb1b060c02dcda4753 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 8 Oct 2024 17:45:14 -0500 Subject: [PATCH] refactor --- repertory/librepertory/include/database/db_common.hpp | 3 +-- repertory/librepertory/include/database/db_delete.hpp | 2 +- repertory/librepertory/include/database/db_select.hpp | 2 +- repertory/librepertory/include/database/db_update.hpp | 2 +- .../librepertory/include/database/db_where_limit_t.hpp | 10 ++++------ repertory/librepertory/include/database/db_where_t.hpp | 10 ++++------ repertory/librepertory/src/database/db_delete.cpp | 2 +- repertory/librepertory/src/database/db_select.cpp | 2 +- repertory/librepertory/src/database/db_update.cpp | 2 +- 9 files changed, 15 insertions(+), 20 deletions(-) diff --git a/repertory/librepertory/include/database/db_common.hpp b/repertory/librepertory/include/database/db_common.hpp index 0243ac73..6a0e2572 100644 --- a/repertory/librepertory/include/database/db_common.hpp +++ b/repertory/librepertory/include/database/db_common.hpp @@ -52,10 +52,9 @@ using db3_stmt_t = std::unique_ptr; void set_journal_mode(sqlite3 &db3); -struct comp_data_t final { +struct db_comp_data_t final { std::string column_name; std::string op_type; - db_types_t value; }; class db_column final { diff --git a/repertory/librepertory/include/database/db_delete.hpp b/repertory/librepertory/include/database/db_delete.hpp index ff2a6690..45c2809f 100644 --- a/repertory/librepertory/include/database/db_delete.hpp +++ b/repertory/librepertory/include/database/db_delete.hpp @@ -39,7 +39,7 @@ public: std::string table_name; std::optional where; - std::vector where_values; + std::vector where_values; db3_stmt_t stmt{nullptr}; }; diff --git a/repertory/librepertory/include/database/db_select.hpp b/repertory/librepertory/include/database/db_select.hpp index ad9081b0..f5df677f 100644 --- a/repertory/librepertory/include/database/db_select.hpp +++ b/repertory/librepertory/include/database/db_select.hpp @@ -43,7 +43,7 @@ public: std::optional limit; std::optional> order_by; std::optional where; - std::vector where_values; + std::vector where_values; db3_stmt_t stmt{nullptr}; }; diff --git a/repertory/librepertory/include/database/db_update.hpp b/repertory/librepertory/include/database/db_update.hpp index abd1efc3..e89321e4 100644 --- a/repertory/librepertory/include/database/db_update.hpp +++ b/repertory/librepertory/include/database/db_update.hpp @@ -41,7 +41,7 @@ public: std::optional limit; std::optional> order_by; std::optional where; - std::vector where_values; + std::vector where_values; db3_stmt_t stmt{nullptr}; }; diff --git a/repertory/librepertory/include/database/db_where_limit_t.hpp b/repertory/librepertory/include/database/db_where_limit_t.hpp index a45a09c0..baa7d580 100644 --- a/repertory/librepertory/include/database/db_where_limit_t.hpp +++ b/repertory/librepertory/include/database/db_where_limit_t.hpp @@ -111,14 +111,12 @@ struct db_comp_next_limit_t final { using wn_t = db_where_next_limit_t; [[nodiscard]] auto create(std::string operation, db::db_types_t value) { - owner->actions.emplace_back(comp_data_t{ + owner->actions.emplace_back(db_comp_data_t{ column_name, operation, - value, }); - ctx->where_values.push_back( - &std::get(*std::prev(owner->actions.end())).value); + ctx->where_values.push_back(value); return wn_t{ ctx, @@ -150,7 +148,7 @@ template struct db_where_with_limit_t final { using group_func_t = std::function; - using action_t = std::variant; + using action_t = std::variant; std::vector actions{}; @@ -160,7 +158,7 @@ template struct db_where_with_limit_t final { for (auto &&action : data.actions) { std::visit(overloaded{ - [&idx, &stream](const comp_data_t &comp) { + [&idx, &stream](const db_comp_data_t &comp) { stream << '"' << comp.column_name << '"' << comp.op_type << '?' + std::to_string(++idx); }, diff --git a/repertory/librepertory/include/database/db_where_t.hpp b/repertory/librepertory/include/database/db_where_t.hpp index 51c38bd5..ea729e5a 100644 --- a/repertory/librepertory/include/database/db_where_t.hpp +++ b/repertory/librepertory/include/database/db_where_t.hpp @@ -95,14 +95,12 @@ struct db_comp_next_t final { using wn_t = db_where_next_t; [[nodiscard]] auto create(std::string operation, db::db_types_t value) { - owner->actions.emplace_back(comp_data_t{ + owner->actions.emplace_back(db_comp_data_t{ column_name, operation, - value, }); - ctx->where_values.push_back( - &std::get(*std::prev(owner->actions.end())).value); + ctx->where_values.push_back(value); return wn_t{ ctx, @@ -134,7 +132,7 @@ template struct db_where_t final { using group_func_t = std::function; - using action_t = std::variant; + using action_t = std::variant; std::vector actions{}; @@ -144,7 +142,7 @@ template struct db_where_t final { for (auto &&action : data.actions) { std::visit(overloaded{ - [&idx, &stream](const comp_data_t &comp) { + [&idx, &stream](const db_comp_data_t &comp) { stream << '"' << comp.column_name << '"' << comp.op_type << '?' + std::to_string(++idx); }, diff --git a/repertory/librepertory/src/database/db_delete.cpp b/repertory/librepertory/src/database/db_delete.cpp index b1ff2292..2749742c 100644 --- a/repertory/librepertory/src/database/db_delete.cpp +++ b/repertory/librepertory/src/database/db_delete.cpp @@ -65,7 +65,7 @@ auto db_delete::go() const -> db_result { data.c_str(), -1, nullptr); }, }, - *context_->where_values.at(static_cast(idx))); + context_->where_values.at(static_cast(idx))); if (res != SQLITE_OK) { utils::error::raise_error(function_name, "failed to bind|" + std::to_string(res) + '|' + diff --git a/repertory/librepertory/src/database/db_select.cpp b/repertory/librepertory/src/database/db_select.cpp index 5c615ac4..7bbcf2b7 100644 --- a/repertory/librepertory/src/database/db_select.cpp +++ b/repertory/librepertory/src/database/db_select.cpp @@ -111,7 +111,7 @@ auto db_select::go() const -> db_result { data.c_str(), -1, nullptr); }, }, - *context_->where_values.at(static_cast(idx))); + context_->where_values.at(static_cast(idx))); if (res != SQLITE_OK) { utils::error::raise_error(function_name, "failed to bind|" + std::to_string(res) + '|' + diff --git a/repertory/librepertory/src/database/db_update.cpp b/repertory/librepertory/src/database/db_update.cpp index 2b5aa3e2..8c049b50 100644 --- a/repertory/librepertory/src/database/db_update.cpp +++ b/repertory/librepertory/src/database/db_update.cpp @@ -121,7 +121,7 @@ auto db_update::go() const -> db_result { data.c_str(), -1, nullptr); }, }, - *context_->where_values.at(static_cast(idx))); + context_->where_values.at(static_cast(idx))); if (res != SQLITE_OK) { utils::error::raise_error(function_name, "failed to bind|" + std::to_string(res) + '|' +