fix
This commit is contained in:
parent
7b375eb912
commit
ec8b7783f3
@ -23,7 +23,6 @@
|
|||||||
#define INCLUDE_DATABASE_DB_COMMON_HPP_
|
#define INCLUDE_DATABASE_DB_COMMON_HPP_
|
||||||
|
|
||||||
#include "utils/error_utils.hpp"
|
#include "utils/error_utils.hpp"
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace repertory::db {
|
namespace repertory::db {
|
||||||
using db_types_t = std::variant<std::int64_t, std::string>;
|
using db_types_t = std::variant<std::int64_t, std::string>;
|
||||||
@ -106,9 +105,9 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename context_t> class db_row final {
|
template <typename ctx_t> class db_row final {
|
||||||
public:
|
public:
|
||||||
db_row(std::shared_ptr<context_t> context) {
|
db_row(std::shared_ptr<ctx_t> context) {
|
||||||
auto column_count = sqlite3_column_count(context->stmt.get());
|
auto column_count = sqlite3_column_count(context->stmt.get());
|
||||||
for (std::int32_t col = 0; col < column_count; col++) {
|
for (std::int32_t col = 0; col < column_count; col++) {
|
||||||
std::string name{sqlite3_column_name(context->stmt.get(), col)};
|
std::string name{sqlite3_column_name(context->stmt.get(), col)};
|
||||||
@ -164,8 +163,8 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename context_t> struct db_result final {
|
template <typename ctx_t> struct db_result final {
|
||||||
db_result(std::shared_ptr<context_t> context, std::int32_t res)
|
db_result(std::shared_ptr<ctx_t> context, std::int32_t res)
|
||||||
: context_(std::move(context)), res_(res) {
|
: context_(std::move(context)), res_(res) {
|
||||||
constexpr const auto *function_name =
|
constexpr const auto *function_name =
|
||||||
static_cast<const char *>(__FUNCTION__);
|
static_cast<const char *>(__FUNCTION__);
|
||||||
@ -176,7 +175,7 @@ template <typename context_t> struct db_result final {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<context_t> context_;
|
std::shared_ptr<ctx_t> context_;
|
||||||
mutable std::int32_t res_;
|
mutable std::int32_t res_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -200,8 +199,7 @@ public:
|
|||||||
return sqlite3_errstr(res_);
|
return sqlite3_errstr(res_);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto get_row(std::optional<db_row<ctx_t>> &row) const -> bool {
|
||||||
get_row(std::optional<db_row<context_t>> &row) const -> bool {
|
|
||||||
constexpr const auto *function_name =
|
constexpr const auto *function_name =
|
||||||
static_cast<const char *>(__FUNCTION__);
|
static_cast<const char *>(__FUNCTION__);
|
||||||
|
|
||||||
@ -226,11 +224,13 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename cn_t, typename op_t, typename w_t, typename wn_t>
|
template <typename cn_t, typename ctx_t, typename op_t, typename w_t,
|
||||||
|
typename wn_t>
|
||||||
struct db_next_t final {
|
struct db_next_t final {
|
||||||
|
std::shared_ptr<ctx_t> ctx;
|
||||||
std::string action;
|
std::string action;
|
||||||
w_t &parent;
|
|
||||||
w_t next{parent.ctx, &parent};
|
w_t next{ctx};
|
||||||
|
|
||||||
using group_func_t = std::function<void(w_t &)>;
|
using group_func_t = std::function<void(w_t &)>;
|
||||||
|
|
||||||
@ -238,22 +238,26 @@ struct db_next_t final {
|
|||||||
return next.where(column_name);
|
return next.where(column_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
||||||
return parent.dump(idx);
|
return ctx->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> auto { return op_t{parent.ctx}.go(); }
|
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
||||||
|
|
||||||
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
||||||
return next.group(std::move(func));
|
return next.group(std::move(func));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename cn_t, typename op_t, typename w_t, typename wn_t>
|
template <typename cn_t, typename ctx_t, typename op_t, typename w_t,
|
||||||
|
typename wn_t>
|
||||||
struct db_next_limit_t final {
|
struct db_next_limit_t final {
|
||||||
|
std::shared_ptr<ctx_t> ctx;
|
||||||
std::string action;
|
std::string action;
|
||||||
w_t &parent;
|
|
||||||
w_t next{parent.ctx, &parent};
|
w_t next{ctx};
|
||||||
|
|
||||||
using group_func_t = std::function<void(w_t &)>;
|
using group_func_t = std::function<void(w_t &)>;
|
||||||
|
|
||||||
@ -261,114 +265,121 @@ struct db_next_limit_t final {
|
|||||||
return next.where(column_name);
|
return next.where(column_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
||||||
return parent.dump(idx);
|
return ctx->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> auto { return op_t{parent.ctx}.go(); }
|
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
||||||
|
|
||||||
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
||||||
return next.group(std::move(func));
|
return next.group(std::move(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> op_t {
|
[[nodiscard]] auto limit(std::int32_t value) -> op_t {
|
||||||
return op_t{parent.ctx}.limit(value);
|
return op_t{ctx}.limit(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name, bool ascending) -> op_t {
|
[[nodiscard]] auto order_by(std::string column_name, bool ascending) -> op_t {
|
||||||
return op_t{parent.ctx}.order_by(column_name, ascending);
|
return op_t{ctx}.order_by(column_name, ascending);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename cn_t, typename op_t, typename w_t>
|
template <typename cn_t, typename ctx_t, typename op_t, typename w_t>
|
||||||
struct db_where_next_t final {
|
struct db_where_next_t final {
|
||||||
w_t &owner;
|
std::shared_ptr<ctx_t> ctx;
|
||||||
w_t &parent;
|
w_t *owner;
|
||||||
|
|
||||||
using n_t = db_next_t<cn_t, op_t, w_t, db_where_next_t>;
|
using n_t = db_next_t<cn_t, ctx_t, op_t, w_t, db_where_next_t>;
|
||||||
|
|
||||||
[[nodiscard]] auto and_() -> n_t & {
|
[[nodiscard]] auto and_() -> n_t & {
|
||||||
owner.actions.emplace_back(n_t{
|
owner->actions.emplace_back(n_t{
|
||||||
|
ctx,
|
||||||
"AND",
|
"AND",
|
||||||
parent,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return std::get<n_t>(*std::prev(owner.actions.end()));
|
return std::get<n_t>(*std::prev(owner->actions.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
||||||
return parent.dump(idx);
|
return ctx->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> auto { return op_t{parent.ctx}.go(); }
|
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
||||||
|
|
||||||
[[nodiscard]] auto or_() -> n_t & {
|
[[nodiscard]] auto or_() -> n_t & {
|
||||||
owner.actions.emplace_back(n_t{
|
owner->actions.emplace_back(n_t{
|
||||||
|
ctx,
|
||||||
"OR",
|
"OR",
|
||||||
parent,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return std::get<n_t>(*std::prev(owner.actions.end()));
|
return std::get<n_t>(*std::prev(owner->actions.end()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename cn_t, typename op_t, typename w_t>
|
template <typename cn_t, typename ctx_t, typename op_t, typename w_t>
|
||||||
struct db_where_next_limit_t final {
|
struct db_where_next_limit_t final {
|
||||||
w_t &owner;
|
std::shared_ptr<ctx_t> ctx;
|
||||||
w_t &parent;
|
w_t *owner;
|
||||||
|
|
||||||
using n_t = db_next_limit_t<cn_t, op_t, w_t, db_where_next_limit_t>;
|
using n_t = db_next_limit_t<cn_t, ctx_t, op_t, w_t, db_where_next_limit_t>;
|
||||||
|
|
||||||
[[nodiscard]] auto and_() -> n_t & {
|
[[nodiscard]] auto and_() -> n_t & {
|
||||||
owner.actions.emplace_back(n_t{
|
owner->actions.emplace_back(n_t{
|
||||||
|
ctx,
|
||||||
"AND",
|
"AND",
|
||||||
parent,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return std::get<n_t>(*std::prev(owner.actions.end()));
|
return std::get<n_t>(*std::prev(owner->actions.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
||||||
return parent.dump(idx);
|
return ctx->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> auto { return op_t{parent.ctx}.go(); }
|
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> op_t {
|
[[nodiscard]] auto limit(std::int32_t value) -> op_t {
|
||||||
return op_t{parent.ctx}.limit(value);
|
return op_t{ctx}.limit(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name, bool ascending) -> op_t {
|
[[nodiscard]] auto order_by(std::string column_name, bool ascending) -> op_t {
|
||||||
return op_t{parent.ctx}.order_by(column_name, ascending);
|
return op_t{ctx}.order_by(column_name, ascending);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto or_() -> n_t & {
|
[[nodiscard]] auto or_() -> n_t & {
|
||||||
owner.actions.emplace_back(n_t{
|
owner->actions.emplace_back(n_t{
|
||||||
|
ctx,
|
||||||
"OR",
|
"OR",
|
||||||
parent,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return std::get<n_t>(*std::prev(owner.actions.end()));
|
return std::get<n_t>(*std::prev(owner->actions.end()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename op_t, typename w_t> struct db_comp_next_t final {
|
template <typename ctx_t, typename op_t, typename w_t>
|
||||||
w_t &owner;
|
struct db_comp_next_t final {
|
||||||
w_t &parent;
|
std::shared_ptr<ctx_t> ctx;
|
||||||
|
w_t *owner;
|
||||||
std::string column_name;
|
std::string column_name;
|
||||||
|
|
||||||
using wn_t = db_where_next_t<db_comp_next_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(comp_data_t{
|
||||||
column_name,
|
column_name,
|
||||||
operation,
|
operation,
|
||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
|
|
||||||
return wn_t{
|
return wn_t{
|
||||||
|
ctx,
|
||||||
owner,
|
owner,
|
||||||
parent,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,23 +398,24 @@ template <typename op_t, typename w_t> struct db_comp_next_t final {
|
|||||||
auto not_equals(db::db_types_t value) -> wn_t { return create("!=", value); };
|
auto not_equals(db::db_types_t value) -> wn_t { return create("!=", value); };
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename op_t, typename w_t> struct db_comp_next_limit_t final {
|
template <typename ctx_t, typename op_t, typename w_t>
|
||||||
w_t &owner;
|
struct db_comp_next_limit_t final {
|
||||||
w_t &parent;
|
std::shared_ptr<ctx_t> ctx;
|
||||||
|
w_t *owner;
|
||||||
std::string column_name;
|
std::string column_name;
|
||||||
|
|
||||||
using wn_t = db_where_next_limit_t<db_comp_next_limit_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(comp_data_t{
|
||||||
column_name,
|
column_name,
|
||||||
operation,
|
operation,
|
||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
|
|
||||||
return wn_t{
|
return wn_t{
|
||||||
|
ctx,
|
||||||
owner,
|
owner,
|
||||||
parent,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,13 +434,12 @@ template <typename op_t, typename w_t> struct db_comp_next_limit_t final {
|
|||||||
auto not_equals(db::db_types_t value) -> wn_t { return create("!=", value); };
|
auto not_equals(db::db_types_t value) -> wn_t { return create("!=", value); };
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename context_t, typename operation_t> struct db_where_t final {
|
template <typename ctx_t, typename op_t> struct db_where_t final {
|
||||||
std::shared_ptr<context_t> ctx;
|
std::shared_ptr<ctx_t> ctx;
|
||||||
db_where_t *parent{this};
|
|
||||||
|
|
||||||
using cn_t = db_comp_next_t<operation_t, db_where_t>;
|
using cn_t = db_comp_next_t<ctx_t, op_t, db_where_t>;
|
||||||
using wn_t = db_where_next_t<cn_t, operation_t, db_where_t>;
|
using wn_t = db_where_next_t<cn_t, ctx_t, op_t, db_where_t>;
|
||||||
using n_t = db_next_t<cn_t, operation_t, db_where_t, wn_t>;
|
using n_t = db_next_t<cn_t, ctx_t, op_t, db_where_t, wn_t>;
|
||||||
|
|
||||||
using group_func_t = std::function<void(db_where_t &)>;
|
using group_func_t = std::function<void(db_where_t &)>;
|
||||||
|
|
||||||
@ -460,38 +471,38 @@ template <typename context_t, typename operation_t> struct db_where_t final {
|
|||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
||||||
return dump(idx, *this);
|
return dump(idx, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
||||||
db_where_t where{ctx, parent};
|
db_where_t where{ctx};
|
||||||
func(where);
|
func(where);
|
||||||
|
|
||||||
actions.emplace_back(std::move(where));
|
actions.emplace_back(std::move(where));
|
||||||
return wn_t{
|
return wn_t{
|
||||||
*this,
|
ctx,
|
||||||
*parent,
|
this,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto where(std::string column_name) -> cn_t {
|
[[nodiscard]] auto where(std::string column_name) -> cn_t {
|
||||||
return cn_t{
|
return cn_t{
|
||||||
*this,
|
ctx,
|
||||||
*parent,
|
this,
|
||||||
column_name,
|
column_name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename context_t, typename operation_t>
|
template <typename ctx_t, typename op_t> struct db_where_with_limit_t final {
|
||||||
struct db_where_with_limit_t final {
|
std::shared_ptr<ctx_t> ctx;
|
||||||
std::shared_ptr<context_t> ctx;
|
|
||||||
db_where_with_limit_t *parent{this};
|
|
||||||
|
|
||||||
using cn_t = db_comp_next_limit_t<operation_t, db_where_with_limit_t>;
|
using cn_t = db_comp_next_limit_t<ctx_t, op_t, db_where_with_limit_t>;
|
||||||
using wn_t = db_where_next_limit_t<cn_t, operation_t, db_where_with_limit_t>;
|
using wn_t = db_where_next_limit_t<cn_t, ctx_t, op_t, db_where_with_limit_t>;
|
||||||
using n_t = db_next_limit_t<cn_t, operation_t, db_where_with_limit_t, wn_t>;
|
using n_t = db_next_limit_t<cn_t, ctx_t, op_t, db_where_with_limit_t, wn_t>;
|
||||||
|
|
||||||
using group_func_t = std::function<void(db_where_with_limit_t &)>;
|
using group_func_t = std::function<void(db_where_with_limit_t &)>;
|
||||||
|
|
||||||
@ -523,34 +534,35 @@ struct db_where_with_limit_t final {
|
|||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
||||||
return dump(idx, *this);
|
return dump(idx, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
||||||
db_where_with_limit_t where{ctx, parent};
|
db_where_with_limit_t where{ctx};
|
||||||
func(where);
|
func(where);
|
||||||
|
|
||||||
actions.emplace_back(std::move(where));
|
actions.emplace_back(std::move(where));
|
||||||
return wn_t{
|
return wn_t{
|
||||||
*this,
|
ctx,
|
||||||
*parent,
|
this,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> operation_t {
|
[[nodiscard]] auto limit(std::int32_t value) -> op_t {
|
||||||
return operation_t{ctx}.limit(value);
|
return op_t{ctx}.limit(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name,
|
[[nodiscard]] auto order_by(std::string column_name, bool ascending) -> op_t {
|
||||||
bool ascending) -> operation_t {
|
return op_t{ctx}.order_by(column_name, ascending);
|
||||||
return operation_t{ctx}.order_by(column_name, ascending);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto where(std::string column_name) -> cn_t {
|
[[nodiscard]] auto where(std::string column_name) -> cn_t {
|
||||||
return cn_t{
|
return cn_t{
|
||||||
*this,
|
ctx,
|
||||||
*parent,
|
this,
|
||||||
column_name,
|
column_name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -141,8 +141,7 @@ TEST_F(database_test, db_delete_where_query) {
|
|||||||
.and_()
|
.and_()
|
||||||
.where("column2")
|
.where("column2")
|
||||||
.equals("test2");
|
.equals("test2");
|
||||||
std::int64_t idx{};
|
auto query_str = query.dump();
|
||||||
auto query_str = query.dump(idx);
|
|
||||||
std::cout << query_str << std::endl;
|
std::cout << query_str << std::endl;
|
||||||
EXPECT_STREQ(R"(DELETE FROM "table" WHERE ("column1"=?1 AND "column2"=?2);)",
|
EXPECT_STREQ(R"(DELETE FROM "table" WHERE ("column1"=?1 AND "column2"=?2);)",
|
||||||
query_str.c_str());
|
query_str.c_str());
|
||||||
@ -184,8 +183,7 @@ TEST_F(database_test, db_select_where_query) {
|
|||||||
.and_()
|
.and_()
|
||||||
.where("column2")
|
.where("column2")
|
||||||
.equals("test2");
|
.equals("test2");
|
||||||
std::int64_t idx{};
|
auto query_str = query.dump();
|
||||||
auto query_str = query.dump(idx);
|
|
||||||
std::cout << query_str << std::endl;
|
std::cout << query_str << std::endl;
|
||||||
EXPECT_STREQ(
|
EXPECT_STREQ(
|
||||||
R"(SELECT * FROM "table" WHERE ("column1"=?1 AND "column2"=?2);)",
|
R"(SELECT * FROM "table" WHERE ("column1"=?1 AND "column2"=?2);)",
|
||||||
@ -201,8 +199,7 @@ TEST_F(database_test, db_select_columns_query) {
|
|||||||
.and_()
|
.and_()
|
||||||
.where("column2")
|
.where("column2")
|
||||||
.equals("test2");
|
.equals("test2");
|
||||||
std::int64_t idx{};
|
auto query_str = query.dump();
|
||||||
auto query_str = query.dump(idx);
|
|
||||||
std::cout << query_str << std::endl;
|
std::cout << query_str << std::endl;
|
||||||
EXPECT_STREQ(
|
EXPECT_STREQ(
|
||||||
R"(SELECT column1, column2 FROM "table" WHERE ("column1"=?1 AND "column2"=?2);)",
|
R"(SELECT column1, column2 FROM "table" WHERE ("column1"=?1 AND "column2"=?2);)",
|
||||||
@ -217,8 +214,7 @@ TEST_F(database_test, db_update_query) {
|
|||||||
.and_()
|
.and_()
|
||||||
.where("column2")
|
.where("column2")
|
||||||
.equals("test2");
|
.equals("test2");
|
||||||
std::int64_t idx{};
|
auto query_str = query.dump();
|
||||||
auto query_str = query.dump(idx);
|
|
||||||
std::cout << query_str << std::endl;
|
std::cout << query_str << std::endl;
|
||||||
EXPECT_STREQ(
|
EXPECT_STREQ(
|
||||||
R"(UPDATE "table" SET "column1"=?1 WHERE ("column1"=?2 AND "column2"=?3);)",
|
R"(UPDATE "table" SET "column1"=?1 WHERE ("column1"=?2 AND "column2"=?3);)",
|
||||||
@ -241,8 +237,7 @@ TEST_F(database_test, insert_update_delete) {
|
|||||||
.column_value("column1", "moose")
|
.column_value("column1", "moose")
|
||||||
.where("column1")
|
.where("column1")
|
||||||
.equals("test0");
|
.equals("test0");
|
||||||
std::int64_t idx{};
|
std::cout << query.dump() << std::endl;
|
||||||
std::cout << query.dump(idx) << std::endl;
|
|
||||||
auto res = query.go();
|
auto res = query.go();
|
||||||
EXPECT_TRUE(res.ok());
|
EXPECT_TRUE(res.ok());
|
||||||
}
|
}
|
||||||
@ -269,26 +264,4 @@ TEST_F(database_test, insert_or_replace_and_delete) {
|
|||||||
|
|
||||||
common_delete(*db3.get());
|
common_delete(*db3.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(database, groups) {
|
|
||||||
// // "s=a and r=t"
|
|
||||||
// std::int64_t idx{0U};
|
|
||||||
// auto str =
|
|
||||||
// db_where_t().column("s").equals("a").and_().column("r").equals("t").dump(
|
|
||||||
// idx);
|
|
||||||
// std::cout << str << std::endl;
|
|
||||||
//
|
|
||||||
// // "(s=a and r=t) OR (s=c or s=x)"
|
|
||||||
// idx = 0U;
|
|
||||||
// str = db_where_t()
|
|
||||||
// .group([](db_where_t &where) {
|
|
||||||
// where.column("s").equals("a").and_().column("r").equals("t");
|
|
||||||
// })
|
|
||||||
// .or_()
|
|
||||||
// .group([](db_where_t &where) {
|
|
||||||
// where.column("s").equals("c").or_().column("s").equals("x");
|
|
||||||
// })
|
|
||||||
// .dump(idx);
|
|
||||||
// std::cout << str << std::endl;
|
|
||||||
}
|
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user