Compare commits
2 Commits
572351067c
...
d144101a7e
Author | SHA1 | Date | |
---|---|---|---|
d144101a7e | |||
b84202a689 |
@ -52,10 +52,18 @@ using db3_stmt_t = std::unique_ptr<sqlite3_stmt, sqlite3_statement_deleter>;
|
|||||||
|
|
||||||
void set_journal_mode(sqlite3 &db3);
|
void set_journal_mode(sqlite3 &db3);
|
||||||
|
|
||||||
struct comp_data_t final {
|
struct db_comp_data_t final {
|
||||||
std::string column_name;
|
std::string column_name;
|
||||||
std::string op_type;
|
std::string op_type;
|
||||||
db_types_t value;
|
};
|
||||||
|
|
||||||
|
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 {
|
class db_column final {
|
||||||
|
@ -29,19 +29,13 @@
|
|||||||
namespace repertory::db {
|
namespace repertory::db {
|
||||||
class db_delete final {
|
class db_delete final {
|
||||||
public:
|
public:
|
||||||
struct context final {
|
struct context final : db_context_t {
|
||||||
|
context(sqlite3 &db3_, std::string table_name_)
|
||||||
|
: db_context_t(db3_, table_name_) {}
|
||||||
using w_t = db_where_t<context, db_delete>;
|
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<w_t> where;
|
std::optional<w_t> where;
|
||||||
std::vector<db_types_t *> where_values;
|
std::vector<db_types_t> where_values;
|
||||||
|
|
||||||
db3_stmt_t stmt{nullptr};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using row = db_row<context>;
|
using row = db_row<context>;
|
||||||
|
@ -27,16 +27,12 @@
|
|||||||
namespace repertory::db {
|
namespace repertory::db {
|
||||||
class db_insert final {
|
class db_insert final {
|
||||||
public:
|
public:
|
||||||
struct context final {
|
struct context final : db_context_t {
|
||||||
context(sqlite3 &db3_, std::string table_name_)
|
context(sqlite3 &db3_, std::string table_name_)
|
||||||
: db3(db3_), table_name(std::move(table_name_)) {}
|
: db_context_t(db3_, table_name_) {}
|
||||||
|
|
||||||
sqlite3 &db3;
|
|
||||||
std::string table_name;
|
|
||||||
|
|
||||||
bool or_replace{false};
|
bool or_replace{false};
|
||||||
std::map<std::string, db_types_t> values{};
|
std::map<std::string, db_types_t> values{};
|
||||||
db3_stmt_t stmt{nullptr};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using row = db_row<context>;
|
using row = db_row<context>;
|
||||||
|
@ -29,23 +29,17 @@
|
|||||||
namespace repertory::db {
|
namespace repertory::db {
|
||||||
class db_select final {
|
class db_select final {
|
||||||
public:
|
public:
|
||||||
struct context final {
|
struct context final : db_context_t {
|
||||||
context(sqlite3 &db3_, std::string table_name_)
|
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<context, db_select>;
|
using w_t = db_where_with_limit_t<context, db_select>;
|
||||||
|
|
||||||
sqlite3 &db3;
|
|
||||||
std::string table_name;
|
|
||||||
|
|
||||||
std::vector<std::string> columns{};
|
std::vector<std::string> columns{};
|
||||||
std::map<std::string, std::string> count_columns{};
|
std::map<std::string, std::string> count_columns{};
|
||||||
std::optional<std::int32_t> limit;
|
std::optional<std::int32_t> limit;
|
||||||
std::optional<std::pair<std::string, bool>> order_by;
|
std::optional<std::pair<std::string, bool>> order_by;
|
||||||
std::optional<w_t> where;
|
std::optional<w_t> where;
|
||||||
std::vector<db_types_t *> where_values;
|
std::vector<db_types_t> where_values;
|
||||||
|
|
||||||
db3_stmt_t stmt{nullptr};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using row = db_row<context>;
|
using row = db_row<context>;
|
||||||
|
@ -29,21 +29,16 @@
|
|||||||
namespace repertory::db {
|
namespace repertory::db {
|
||||||
class db_update final {
|
class db_update final {
|
||||||
public:
|
public:
|
||||||
struct context final {
|
struct context final : db_context_t {
|
||||||
context(sqlite3 &db3_, std::string table_name_)
|
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<context, db_update>;
|
using w_t = db_where_with_limit_t<context, db_update>;
|
||||||
|
|
||||||
sqlite3 &db3;
|
|
||||||
std::string table_name;
|
|
||||||
|
|
||||||
std::map<std::string, db_types_t> column_values{};
|
std::map<std::string, db_types_t> column_values{};
|
||||||
std::optional<std::int32_t> limit;
|
std::optional<std::int32_t> limit;
|
||||||
std::optional<std::pair<std::string, bool>> order_by;
|
std::optional<std::pair<std::string, bool>> order_by;
|
||||||
std::optional<w_t> where;
|
std::optional<w_t> where;
|
||||||
std::vector<db_types_t *> where_values;
|
std::vector<db_types_t> where_values;
|
||||||
|
|
||||||
db3_stmt_t stmt{nullptr};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using row = db_row<context>;
|
using row = db_row<context>;
|
||||||
|
@ -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>;
|
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) {
|
[[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,
|
column_name,
|
||||||
operation,
|
operation,
|
||||||
value,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx->where_values.push_back(
|
ctx->where_values.push_back(value);
|
||||||
&std::get<comp_data_t>(*std::prev(owner->actions.end())).value);
|
|
||||||
|
|
||||||
return wn_t{
|
return wn_t{
|
||||||
ctx,
|
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 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{};
|
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) {
|
for (auto &&action : data.actions) {
|
||||||
std::visit(overloaded{
|
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
|
stream << '"' << comp.column_name << '"' << comp.op_type
|
||||||
<< '?' + std::to_string(++idx);
|
<< '?' + 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>;
|
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) {
|
[[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,
|
column_name,
|
||||||
operation,
|
operation,
|
||||||
value,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx->where_values.push_back(
|
ctx->where_values.push_back(value);
|
||||||
&std::get<comp_data_t>(*std::prev(owner->actions.end())).value);
|
|
||||||
|
|
||||||
return wn_t{
|
return wn_t{
|
||||||
ctx,
|
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 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{};
|
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) {
|
for (auto &&action : data.actions) {
|
||||||
std::visit(overloaded{
|
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
|
stream << '"' << comp.column_name << '"' << comp.op_type
|
||||||
<< '?' + std::to_string(++idx);
|
<< '?' + std::to_string(++idx);
|
||||||
},
|
},
|
||||||
|
@ -65,7 +65,7 @@ auto db_delete::go() const -> db_result<context> {
|
|||||||
data.c_str(), -1, nullptr);
|
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) {
|
if (res != SQLITE_OK) {
|
||||||
utils::error::raise_error(function_name,
|
utils::error::raise_error(function_name,
|
||||||
"failed to bind|" + std::to_string(res) + '|' +
|
"failed to bind|" + std::to_string(res) + '|' +
|
||||||
|
@ -111,7 +111,7 @@ auto db_select::go() const -> db_result<context> {
|
|||||||
data.c_str(), -1, nullptr);
|
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) {
|
if (res != SQLITE_OK) {
|
||||||
utils::error::raise_error(function_name,
|
utils::error::raise_error(function_name,
|
||||||
"failed to bind|" + std::to_string(res) + '|' +
|
"failed to bind|" + std::to_string(res) + '|' +
|
||||||
|
@ -121,7 +121,7 @@ auto db_update::go() const -> db_result<context> {
|
|||||||
data.c_str(), -1, nullptr);
|
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) {
|
if (res != SQLITE_OK) {
|
||||||
utils::error::raise_error(function_name,
|
utils::error::raise_error(function_name,
|
||||||
"failed to bind|" + std::to_string(res) + '|' +
|
"failed to bind|" + std::to_string(res) + '|' +
|
||||||
|
Reference in New Issue
Block a user