From d144101a7e6bcda86b53d7e4e52298136e56f091 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 8 Oct 2024 17:50:57 -0500 Subject: [PATCH] refactor --- .../librepertory/include/database/db_common.hpp | 9 +++++++++ .../librepertory/include/database/db_delete.hpp | 12 +++--------- .../librepertory/include/database/db_insert.hpp | 8 ++------ .../librepertory/include/database/db_select.hpp | 10 ++-------- .../librepertory/include/database/db_update.hpp | 9 ++------- 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/repertory/librepertory/include/database/db_common.hpp b/repertory/librepertory/include/database/db_common.hpp index 6a0e2572..25fa3e1a 100644 --- a/repertory/librepertory/include/database/db_common.hpp +++ b/repertory/librepertory/include/database/db_common.hpp @@ -57,6 +57,15 @@ struct db_comp_data_t final { std::string op_type; }; +struct db_context_t { + db_context_t(sqlite3 &db3_, std::string table_name_) + : db3(db3_), table_name(std::move(table_name_)) {} + sqlite3 &db3; + std::string table_name; + + db3_stmt_t stmt{nullptr}; +}; + class db_column final { public: db_column() noexcept = default; diff --git a/repertory/librepertory/include/database/db_delete.hpp b/repertory/librepertory/include/database/db_delete.hpp index 45c2809f..a986bb04 100644 --- a/repertory/librepertory/include/database/db_delete.hpp +++ b/repertory/librepertory/include/database/db_delete.hpp @@ -29,19 +29,13 @@ namespace repertory::db { class db_delete final { public: - struct context final { - using w_t = db_where_t; - + struct context final : db_context_t { context(sqlite3 &db3_, std::string table_name_) - : db3(db3_), table_name(std::move(table_name_)) {} - - sqlite3 &db3; - std::string table_name; + : db_context_t(db3_, table_name_) {} + using w_t = db_where_t; std::optional where; std::vector where_values; - - db3_stmt_t stmt{nullptr}; }; using row = db_row; diff --git a/repertory/librepertory/include/database/db_insert.hpp b/repertory/librepertory/include/database/db_insert.hpp index 387518a8..34d81af2 100644 --- a/repertory/librepertory/include/database/db_insert.hpp +++ b/repertory/librepertory/include/database/db_insert.hpp @@ -27,16 +27,12 @@ namespace repertory::db { class db_insert final { public: - struct context final { + struct context final : db_context_t { context(sqlite3 &db3_, std::string table_name_) - : db3(db3_), table_name(std::move(table_name_)) {} - - sqlite3 &db3; - std::string table_name; + : db_context_t(db3_, table_name_) {} bool or_replace{false}; std::map values{}; - db3_stmt_t stmt{nullptr}; }; using row = db_row; diff --git a/repertory/librepertory/include/database/db_select.hpp b/repertory/librepertory/include/database/db_select.hpp index f5df677f..8beb9e99 100644 --- a/repertory/librepertory/include/database/db_select.hpp +++ b/repertory/librepertory/include/database/db_select.hpp @@ -29,23 +29,17 @@ namespace repertory::db { class db_select final { public: - struct context final { + struct context final : db_context_t { context(sqlite3 &db3_, std::string table_name_) - : db3(db3_), table_name(std::move(table_name_)) {} - + : db_context_t(db3_, table_name_) {} using w_t = db_where_with_limit_t; - sqlite3 &db3; - std::string table_name; - std::vector columns{}; std::map count_columns{}; std::optional limit; std::optional> order_by; std::optional where; std::vector where_values; - - db3_stmt_t stmt{nullptr}; }; using row = db_row; diff --git a/repertory/librepertory/include/database/db_update.hpp b/repertory/librepertory/include/database/db_update.hpp index e89321e4..7608a2fc 100644 --- a/repertory/librepertory/include/database/db_update.hpp +++ b/repertory/librepertory/include/database/db_update.hpp @@ -29,21 +29,16 @@ namespace repertory::db { class db_update final { public: - struct context final { + struct context final : db_context_t { context(sqlite3 &db3_, std::string table_name_) - : db3(db3_), table_name(std::move(table_name_)) {} + : db_context_t(db3_, table_name_) {} using w_t = db_where_with_limit_t; - sqlite3 &db3; - std::string table_name; - std::map column_values{}; std::optional limit; std::optional> order_by; std::optional where; std::vector where_values; - - db3_stmt_t stmt{nullptr}; }; using row = db_row;