updated build system

This commit is contained in:
2024-10-17 10:20:07 -05:00
parent 39d644e115
commit 63ca3089da
22 changed files with 304 additions and 198 deletions

View File

@ -183,8 +183,6 @@ template <typename ctx_t> struct db_result final {
}
}
~db_result() { context_->clear(); }
private:
std::shared_ptr<ctx_t> context_;
mutable std::int32_t res_;

View File

@ -43,12 +43,9 @@ public:
: db_context_t(db3_, table_name_) {}
using w_t = db_where_t<context, db_delete_op_t>;
using wd_t = where_data_t<w_t>;
std::optional<w_t> where;
std::map<std::size_t, std::vector<w_t::action_t>> where_actions;
std::vector<db_types_t> where_values;
void clear();
std::unique_ptr<wd_t> where_data;
};
using row = db_row<context>;
@ -67,8 +64,8 @@ public:
[[nodiscard]] auto go() const -> db_result<context>;
[[nodiscard]] auto
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
[[nodiscard]] auto 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;
};

View File

@ -34,8 +34,6 @@ public:
bool or_replace{false};
std::map<std::string, db_types_t> values;
void clear() { values.clear(); }
};
using row = db_row<context>;

View File

@ -44,14 +44,15 @@ public:
[[nodiscard]] auto offset(std::int32_t value) -> db_select_op_t;
[[nodiscard]] auto order_by(std::string column_name,
bool ascending) -> db_select_op_t;
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
-> db_select_op_t;
};
context(sqlite3 *db3_, std::string table_name_)
: db_context_t(db3_, table_name_) {}
using w_t = db_where_t<context, db_select_op_t>;
using wd_t = where_data_t<w_t>;
std::vector<std::string> columns;
std::map<std::string, std::string> count_columns;
@ -60,11 +61,8 @@ public:
std::optional<std::int32_t> limit;
std::optional<std::int32_t> offset;
std::optional<std::pair<std::string, bool>> order_by;
std::optional<w_t> where;
std::map<std::size_t, std::vector<w_t::action_t>> where_actions;
std::vector<db_types_t> where_values;
void clear();
std::unique_ptr<wd_t> where_data;
};
using row = db_row<context>;
@ -81,8 +79,8 @@ private:
public:
[[nodiscard]] auto column(std::string column_name) -> db_select &;
[[nodiscard]] auto count(std::string column_name,
std::string as_column_name) -> db_select &;
[[nodiscard]] auto count(std::string column_name, std::string as_column_name)
-> db_select &;
[[nodiscard]] auto dump() const -> std::string;
@ -90,15 +88,15 @@ public:
[[nodiscard]] auto group_by(std::string column_name) -> db_select &;
[[nodiscard]] auto
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
[[nodiscard]] auto group(context::w_t::group_func_t func)
-> context::w_t::wn_t;
[[nodiscard]] auto limit(std::int32_t value) -> db_select &;
[[nodiscard]] auto offset(std::int32_t value) -> db_select &;
[[nodiscard]] auto order_by(std::string column_name,
bool ascending) -> db_select &;
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
-> db_select &;
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
};

View File

@ -43,20 +43,18 @@ public:
[[nodiscard]] auto limit(std::int32_t value) -> db_update_op_t;
[[nodiscard]] auto order_by(std::string column_name,
bool ascending) -> db_update_op_t;
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
-> db_update_op_t;
};
using w_t = db_where_t<context, db_update_op_t>;
using wd_t = where_data_t<w_t>;
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<w_t> where;
std::map<std::size_t, std::vector<w_t::action_t>> where_actions;
std::vector<db_types_t> where_values;
void clear();
std::unique_ptr<wd_t> where_data;
};
using row = db_row<context>;
@ -71,20 +69,20 @@ private:
std::shared_ptr<context> context_;
public:
[[nodiscard]] auto column_value(std::string column_name,
db_types_t value) -> db_update &;
[[nodiscard]] auto column_value(std::string column_name, db_types_t value)
-> db_update &;
[[nodiscard]] auto dump() const -> std::string;
[[nodiscard]] auto go() const -> db_result<context>;
[[nodiscard]] auto
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
[[nodiscard]] auto 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 order_by(std::string column_name, bool ascending)
-> db_update &;
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
};

View File

@ -26,6 +26,12 @@
#include "utils/db/sqlite/db_common.hpp"
namespace repertory::utils::db::sqlite {
template <typename w_t> struct where_data_t final {
w_t base;
std::map<std::size_t, std::vector<typename w_t::action_t>> actions;
std::vector<db_types_t> values;
};
template <typename cn_t, typename ctx_t, typename op_t, typename w_t,
typename wn_t>
struct db_next_t final {
@ -42,7 +48,7 @@ struct db_next_t final {
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
return ctx->where->dump(idx);
return ctx->where_data->base.dump(idx);
}
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
@ -72,14 +78,14 @@ struct db_where_next_t final {
"AND",
};
ctx->where_actions[action_idx].emplace_back(next);
ctx->where_data->actions[action_idx].emplace_back(next);
return next;
}
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
return ctx->where->dump(idx);
return ctx->where_data->base.dump(idx);
}
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
@ -97,7 +103,7 @@ struct db_where_next_t final {
"OR",
};
ctx->where_actions[action_idx].emplace_back(next);
ctx->where_data->actions[action_idx].emplace_back(next);
return next;
}
};
@ -111,12 +117,12 @@ struct db_comp_next_t final {
using wn_t = db_where_next_t<db_comp_next_t, ctx_t, op_t, w_t>;
[[nodiscard]] auto create(std::string operation, db_types_t value) {
ctx->where_actions[action_idx].emplace_back(db_comp_data_t{
ctx->where_data->actions[action_idx].emplace_back(db_comp_data_t{
column_name,
operation,
});
ctx->where_values.push_back(value);
ctx->where_data->values.push_back(value);
return wn_t{
action_idx,
@ -151,8 +157,8 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
using action_t = std::variant<db_comp_data_t, n_t, db_where_t>;
[[nodiscard]] static auto dump(std::int32_t &idx,
auto &&actions) -> std::string {
[[nodiscard]] static auto dump(std::int32_t &idx, auto &&actions)
-> std::string {
std::stringstream stream;
for (auto &&action : actions) {
@ -177,24 +183,24 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
return dump(idx, ctx->where_actions[action_idx]);
return dump(idx, ctx->where_data->actions[action_idx]);
}
[[nodiscard]] auto get_actions() -> auto & {
return ctx->where_actions[action_idx];
return ctx->where_data->actions[action_idx];
}
[[nodiscard]] auto get_actions() const -> const auto & {
return ctx->where_actions[action_idx];
return ctx->where_data->actions[action_idx];
}
[[nodiscard]] auto group(group_func_t func) -> wn_t {
ctx->where_actions[action_idx];
ctx->where_data->actions[action_idx];
db_where_t where{ctx->where_actions.size(), ctx};
db_where_t where{ctx->where_data->actions.size(), ctx};
func(where);
ctx->where_actions[action_idx].emplace_back(where);
ctx->where_data->actions[action_idx].emplace_back(where);
return wn_t{
action_idx,
@ -203,7 +209,7 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
}
[[nodiscard]] auto where(std::string column_name) -> cn_t {
ctx->where_actions[action_idx];
ctx->where_data->actions[action_idx];
return cn_t{
action_idx,