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

This commit is contained in:
Scott E. Graves 2024-10-08 17:32:11 -05:00
parent 9a3d6e725e
commit 572351067c
6 changed files with 27 additions and 35 deletions

View File

@ -30,13 +30,15 @@ namespace repertory::db {
class db_delete final {
public:
struct context final {
using w_t = db_where_t<context, db_delete>;
context(sqlite3 &db3_, std::string table_name_)
: db3(db3_), table_name(std::move(table_name_)) {}
sqlite3 &db3;
std::string table_name;
std::optional<db_where_t<context, db_delete>> where;
std::optional<w_t> where;
std::vector<db_types_t *> where_values;
db3_stmt_t stmt{nullptr};
@ -58,11 +60,10 @@ public:
[[nodiscard]] auto go() const -> db_result<context>;
[[nodiscard]] auto group(db_where_t<context, db_delete>::group_func_t func)
-> db_where_t<context, db_delete>::wn_t;
[[nodiscard]] auto
where(std::string column_name) const -> db_where_t<context, db_delete>::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

View File

@ -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<context, db_select>;
sqlite3 &db3;
std::string table_name;
@ -40,7 +42,7 @@ public:
std::map<std::string, std::string> count_columns{};
std::optional<std::int32_t> limit;
std::optional<std::pair<std::string, bool>> order_by;
std::optional<db_where_with_limit_t<context, db_select>> where;
std::optional<w_t> where;
std::vector<db_types_t *> where_values;
db3_stmt_t stmt{nullptr};
@ -68,16 +70,14 @@ public:
[[nodiscard]] auto go() const -> db_result<context>;
[[nodiscard]] auto
group(db_where_with_limit_t<context, db_select>::group_func_t func)
-> db_where_with_limit_t<context, db_select>::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<context, db_select>::cn_t;
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
};
} // namespace repertory::db

View File

@ -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<context, db_update>;
sqlite3 &db3;
std::string table_name;
@ -39,7 +40,7 @@ public:
std::map<std::string, db_types_t> column_values{};
std::optional<std::int32_t> limit;
std::optional<std::pair<std::string, bool>> order_by;
std::optional<db_where_with_limit_t<context, db_update>> where;
std::optional<w_t> where;
std::vector<db_types_t *> where_values;
db3_stmt_t stmt{nullptr};
@ -65,16 +66,14 @@ public:
[[nodiscard]] auto go() const -> db_result<context>;
[[nodiscard]] auto
group(db_where_with_limit_t<context, db_update>::group_func_t func)
-> db_where_with_limit_t<context, db_update>::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<context, db_update>::cn_t;
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
};
} // namespace repertory::db

View File

@ -77,19 +77,17 @@ auto db_delete::go() const -> db_result<context> {
return {context_, res};
}
auto db_delete::group(db_where_t<context, db_delete>::group_func_t func)
-> db_where_t<context, db_delete>::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, db_delete>{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<context, db_delete>::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, db_delete>{context_};
context_->where = context::w_t{context_};
}
return context_->where->where(column_name);

View File

@ -123,11 +123,9 @@ auto db_select::go() const -> db_result<context> {
return {context_, res};
}
auto db_select::group(
db_where_with_limit_t<context, db_select>::group_func_t func)
-> db_where_with_limit_t<context, db_select>::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, db_select>{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<context, db_select>::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, db_select>{context_};
context_->where = context::w_t{context_};
}
return context_->where->where(column_name);

View File

@ -133,11 +133,9 @@ auto db_update::go() const -> db_result<context> {
return {context_, res};
}
auto db_update::group(
db_where_with_limit_t<context, db_update>::group_func_t func)
-> db_where_with_limit_t<context, db_update>::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, db_update>{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<context, db_update>::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, db_update>{context_};
context_->where = context::w_t{context_};
}
return context_->where->where(column_name);