refactor
This commit is contained in:
parent
572351067c
commit
b84202a689
@ -52,10 +52,9 @@ using db3_stmt_t = std::unique_ptr<sqlite3_stmt, sqlite3_statement_deleter>;
|
||||
|
||||
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 {
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
std::string table_name;
|
||||
|
||||
std::optional<w_t> where;
|
||||
std::vector<db_types_t *> where_values;
|
||||
std::vector<db_types_t> where_values;
|
||||
|
||||
db3_stmt_t stmt{nullptr};
|
||||
};
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
std::optional<std::int32_t> limit;
|
||||
std::optional<std::pair<std::string, bool>> order_by;
|
||||
std::optional<w_t> where;
|
||||
std::vector<db_types_t *> where_values;
|
||||
std::vector<db_types_t> where_values;
|
||||
|
||||
db3_stmt_t stmt{nullptr};
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
std::optional<std::int32_t> limit;
|
||||
std::optional<std::pair<std::string, bool>> order_by;
|
||||
std::optional<w_t> where;
|
||||
std::vector<db_types_t *> where_values;
|
||||
std::vector<db_types_t> where_values;
|
||||
|
||||
db3_stmt_t stmt{nullptr};
|
||||
};
|
||||
|
@ -111,14 +111,12 @@ struct db_comp_next_limit_t final {
|
||||
using wn_t = db_where_next_limit_t<db_comp_next_limit_t, ctx_t, op_t, w_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<comp_data_t>(*std::prev(owner->actions.end())).value);
|
||||
ctx->where_values.push_back(value);
|
||||
|
||||
return wn_t{
|
||||
ctx,
|
||||
@ -150,7 +148,7 @@ template <typename ctx_t, typename op_t> struct db_where_with_limit_t final {
|
||||
|
||||
using group_func_t = std::function<void(db_where_with_limit_t &)>;
|
||||
|
||||
using action_t = std::variant<comp_data_t, n_t, db_where_with_limit_t>;
|
||||
using action_t = std::variant<db_comp_data_t, n_t, db_where_with_limit_t>;
|
||||
|
||||
std::vector<action_t> actions{};
|
||||
|
||||
@ -160,7 +158,7 @@ template <typename ctx_t, typename op_t> 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);
|
||||
},
|
||||
|
@ -95,14 +95,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::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<comp_data_t>(*std::prev(owner->actions.end())).value);
|
||||
ctx->where_values.push_back(value);
|
||||
|
||||
return wn_t{
|
||||
ctx,
|
||||
@ -134,7 +132,7 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
|
||||
|
||||
using group_func_t = std::function<void(db_where_t &)>;
|
||||
|
||||
using action_t = std::variant<comp_data_t, n_t, db_where_t>;
|
||||
using action_t = std::variant<db_comp_data_t, n_t, db_where_t>;
|
||||
|
||||
std::vector<action_t> actions{};
|
||||
|
||||
@ -144,7 +142,7 @@ template <typename ctx_t, typename op_t> 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);
|
||||
},
|
||||
|
@ -65,7 +65,7 @@ auto db_delete::go() const -> db_result<context> {
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
*context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
if (res != SQLITE_OK) {
|
||||
utils::error::raise_error(function_name,
|
||||
"failed to bind|" + std::to_string(res) + '|' +
|
||||
|
@ -111,7 +111,7 @@ auto db_select::go() const -> db_result<context> {
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
*context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
if (res != SQLITE_OK) {
|
||||
utils::error::raise_error(function_name,
|
||||
"failed to bind|" + std::to_string(res) + '|' +
|
||||
|
@ -121,7 +121,7 @@ auto db_update::go() const -> db_result<context> {
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
*context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
if (res != SQLITE_OK) {
|
||||
utils::error::raise_error(function_name,
|
||||
"failed to bind|" + std::to_string(res) + '|' +
|
||||
|
Loading…
x
Reference in New Issue
Block a user