From 572351067c000f18d86b3041720963e47b642354 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 8 Oct 2024 17:32:11 -0500 Subject: [PATCH] refactor --- repertory/librepertory/include/database/db_delete.hpp | 11 ++++++----- repertory/librepertory/include/database/db_select.hpp | 10 +++++----- repertory/librepertory/include/database/db_update.hpp | 9 ++++----- repertory/librepertory/src/database/db_delete.cpp | 10 ++++------ repertory/librepertory/src/database/db_select.cpp | 11 ++++------- repertory/librepertory/src/database/db_update.cpp | 11 ++++------- 6 files changed, 27 insertions(+), 35 deletions(-) diff --git a/repertory/librepertory/include/database/db_delete.hpp b/repertory/librepertory/include/database/db_delete.hpp index 2aa68024..ff2a6690 100644 --- a/repertory/librepertory/include/database/db_delete.hpp +++ b/repertory/librepertory/include/database/db_delete.hpp @@ -30,13 +30,15 @@ namespace repertory::db { class db_delete final { public: struct context final { + using w_t = db_where_t; + context(sqlite3 &db3_, std::string table_name_) : db3(db3_), table_name(std::move(table_name_)) {} sqlite3 &db3; std::string table_name; - std::optional> where; + std::optional where; std::vector where_values; db3_stmt_t stmt{nullptr}; @@ -58,11 +60,10 @@ public: [[nodiscard]] auto go() const -> db_result; - [[nodiscard]] auto group(db_where_t::group_func_t func) - -> db_where_t::wn_t; - [[nodiscard]] auto - where(std::string column_name) const -> db_where_t::cn_t; + group(context::w_t::group_func_t func) -> context::w_t::wn_t; + + [[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t; }; } // namespace repertory::db diff --git a/repertory/librepertory/include/database/db_select.hpp b/repertory/librepertory/include/database/db_select.hpp index b5d9c27d..ad9081b0 100644 --- a/repertory/librepertory/include/database/db_select.hpp +++ b/repertory/librepertory/include/database/db_select.hpp @@ -33,6 +33,8 @@ public: context(sqlite3 &db3_, std::string table_name_) : db3(db3_), table_name(std::move(table_name_)) {} + using w_t = db_where_with_limit_t; + sqlite3 &db3; std::string table_name; @@ -40,7 +42,7 @@ public: std::map count_columns{}; std::optional limit; std::optional> order_by; - std::optional> where; + std::optional where; std::vector where_values; db3_stmt_t stmt{nullptr}; @@ -68,16 +70,14 @@ public: [[nodiscard]] auto go() const -> db_result; [[nodiscard]] auto - group(db_where_with_limit_t::group_func_t func) - -> db_where_with_limit_t::wn_t; + group(context::w_t::group_func_t func) -> context::w_t::wn_t; [[nodiscard]] auto limit(std::int32_t value) -> db_select &; [[nodiscard]] auto order_by(std::string column_name, bool ascending) -> db_select &; - [[nodiscard]] auto where(std::string column_name) const - -> db_where_with_limit_t::cn_t; + [[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t; }; } // namespace repertory::db diff --git a/repertory/librepertory/include/database/db_update.hpp b/repertory/librepertory/include/database/db_update.hpp index 55c38b31..abd1efc3 100644 --- a/repertory/librepertory/include/database/db_update.hpp +++ b/repertory/librepertory/include/database/db_update.hpp @@ -32,6 +32,7 @@ public: struct context final { context(sqlite3 &db3_, std::string table_name_) : db3(db3_), table_name(std::move(table_name_)) {} + using w_t = db_where_with_limit_t; sqlite3 &db3; std::string table_name; @@ -39,7 +40,7 @@ public: std::map column_values{}; std::optional limit; std::optional> order_by; - std::optional> where; + std::optional where; std::vector where_values; db3_stmt_t stmt{nullptr}; @@ -65,16 +66,14 @@ public: [[nodiscard]] auto go() const -> db_result; [[nodiscard]] auto - group(db_where_with_limit_t::group_func_t func) - -> db_where_with_limit_t::wn_t; + group(context::w_t::group_func_t func) -> context::w_t::wn_t; [[nodiscard]] auto limit(std::int32_t value) -> db_update &; [[nodiscard]] auto order_by(std::string column_name, bool ascending) -> db_update &; - [[nodiscard]] auto where(std::string column_name) const - -> db_where_with_limit_t::cn_t; + [[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t; }; } // namespace repertory::db diff --git a/repertory/librepertory/src/database/db_delete.cpp b/repertory/librepertory/src/database/db_delete.cpp index 5eb74e3a..b1ff2292 100644 --- a/repertory/librepertory/src/database/db_delete.cpp +++ b/repertory/librepertory/src/database/db_delete.cpp @@ -77,19 +77,17 @@ auto db_delete::go() const -> db_result { return {context_, res}; } -auto db_delete::group(db_where_t::group_func_t func) - -> db_where_t::wn_t { +auto db_delete::group(context::w_t::group_func_t func) -> context::w_t::wn_t { if (not context_->where.has_value()) { - context_->where = db_where_t{context_}; + context_->where = context::w_t{context_}; } return context_->where->group(std::move(func)); } -auto db_delete::where(std::string column_name) const - -> db_where_t::cn_t { +auto db_delete::where(std::string column_name) const -> context::w_t::cn_t { if (not context_->where.has_value()) { - context_->where = db_where_t{context_}; + context_->where = context::w_t{context_}; } return context_->where->where(column_name); diff --git a/repertory/librepertory/src/database/db_select.cpp b/repertory/librepertory/src/database/db_select.cpp index 5b88598e..5c615ac4 100644 --- a/repertory/librepertory/src/database/db_select.cpp +++ b/repertory/librepertory/src/database/db_select.cpp @@ -123,11 +123,9 @@ auto db_select::go() const -> db_result { return {context_, res}; } -auto db_select::group( - db_where_with_limit_t::group_func_t func) - -> db_where_with_limit_t::wn_t { +auto db_select::group(context::w_t::group_func_t func) -> context::w_t::wn_t { if (not context_->where.has_value()) { - context_->where = db_where_with_limit_t{context_}; + context_->where = context::w_t{context_}; } return context_->where->group(std::move(func)); @@ -144,10 +142,9 @@ auto db_select::order_by(std::string column_name, return *this; } -auto db_select::where(std::string column_name) const - -> db_where_with_limit_t::cn_t { +auto db_select::where(std::string column_name) const -> context::w_t::cn_t { if (not context_->where.has_value()) { - context_->where = db_where_with_limit_t{context_}; + context_->where = context::w_t{context_}; } return context_->where->where(column_name); diff --git a/repertory/librepertory/src/database/db_update.cpp b/repertory/librepertory/src/database/db_update.cpp index 81c2e35c..2b5aa3e2 100644 --- a/repertory/librepertory/src/database/db_update.cpp +++ b/repertory/librepertory/src/database/db_update.cpp @@ -133,11 +133,9 @@ auto db_update::go() const -> db_result { return {context_, res}; } -auto db_update::group( - db_where_with_limit_t::group_func_t func) - -> db_where_with_limit_t::wn_t { +auto db_update::group(context::w_t::group_func_t func) -> context::w_t::wn_t { if (not context_->where.has_value()) { - context_->where = db_where_with_limit_t{context_}; + context_->where = context::w_t{context_}; } return context_->where->group(std::move(func)); @@ -154,10 +152,9 @@ auto db_update::order_by(std::string column_name, return *this; } -auto db_update::where(std::string column_name) const - -> db_where_with_limit_t::cn_t { +auto db_update::where(std::string column_name) const -> context::w_t::cn_t { if (not context_->where.has_value()) { - context_->where = db_where_with_limit_t{context_}; + context_->where = context::w_t{context_}; } return context_->where->where(column_name);