updated build system
This commit is contained in:
parent
1f4872769d
commit
ba2850ea21
@ -31,17 +31,23 @@ namespace repertory::utils::db::sqlite {
|
||||
class db_delete final {
|
||||
public:
|
||||
struct context final : db_context_t {
|
||||
struct db_delete_op_t final {
|
||||
std::shared_ptr<context> ctx;
|
||||
|
||||
[[nodiscard]] auto dump() const -> std::string;
|
||||
|
||||
[[nodiscard]] auto go() const -> db_result<context>;
|
||||
};
|
||||
|
||||
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_op_t>;
|
||||
|
||||
std::optional<w_t> where;
|
||||
std::vector<db_types_t> where_values;
|
||||
|
||||
void clear() {
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
void clear();
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
|
@ -31,26 +31,36 @@ namespace repertory::utils::db::sqlite {
|
||||
class db_select final {
|
||||
public:
|
||||
struct context final : db_context_t {
|
||||
struct db_select_op_t final {
|
||||
std::shared_ptr<context> ctx;
|
||||
|
||||
[[nodiscard]] auto dump() const -> std::string;
|
||||
|
||||
[[nodiscard]] auto go() const -> db_result<context>;
|
||||
|
||||
[[nodiscard]] auto group_by(std::string column_name) -> db_select_op_t;
|
||||
|
||||
[[nodiscard]] auto limit(std::int32_t value) -> 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>;
|
||||
using w_t = db_where_t<context, db_select_op_t>;
|
||||
|
||||
std::vector<std::string> columns;
|
||||
std::map<std::string, std::string> count_columns;
|
||||
|
||||
std::vector<std::string> group_by;
|
||||
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;
|
||||
|
||||
void clear() {
|
||||
columns.clear();
|
||||
count_columns.clear();
|
||||
limit.reset();
|
||||
order_by.reset();
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
void clear();
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
@ -74,6 +84,8 @@ public:
|
||||
|
||||
[[nodiscard]] auto go() const -> db_result<context>;
|
||||
|
||||
[[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;
|
||||
|
||||
|
@ -34,7 +34,20 @@ public:
|
||||
context(sqlite3 &db3_, std::string table_name_)
|
||||
: db_context_t(db3_, table_name_) {}
|
||||
|
||||
using w_t = db_where_t<context, db_update>;
|
||||
struct db_update_op_t final {
|
||||
std::shared_ptr<context> ctx;
|
||||
|
||||
[[nodiscard]] auto dump() const -> std::string;
|
||||
|
||||
[[nodiscard]] auto go() const -> db_result<context>;
|
||||
|
||||
[[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;
|
||||
};
|
||||
|
||||
using w_t = db_where_t<context, db_update_op_t>;
|
||||
|
||||
std::map<std::string, db_types_t> column_values;
|
||||
std::optional<std::int32_t> limit;
|
||||
@ -42,13 +55,7 @@ public:
|
||||
std::optional<w_t> where;
|
||||
std::vector<db_types_t> where_values;
|
||||
|
||||
void clear() {
|
||||
column_values.clear();
|
||||
limit.reset();
|
||||
order_by.reset();
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
void clear();
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
|
@ -24,6 +24,19 @@
|
||||
#if defined(PROJECT_ENABLE_SQLITE)
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
void db_delete::context::clear() {
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
|
||||
db_delete::context::db_delete_op_t::auto dump() const -> std::string {
|
||||
return db_delete{ctx}.dump();
|
||||
}
|
||||
|
||||
db_delete::context::db_delete_op_t::auto go() const -> db_result<context> {
|
||||
return db_delete{ctx}.go();
|
||||
}
|
||||
|
||||
auto db_delete::dump() const -> std::string {
|
||||
std::stringstream query;
|
||||
query << "DELETE FROM \"" << context_->table_name << "\"";
|
||||
|
@ -24,6 +24,42 @@
|
||||
#if defined(PROJECT_ENABLE_SQLITE)
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
void db_select::context::clear() {
|
||||
columns.clear();
|
||||
count_columns.clear();
|
||||
limit.reset();
|
||||
order_by.reset();
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
|
||||
db_select::context::db_select_op_t::auto dump() const -> std::string {
|
||||
return db_select{ctx}.dump();
|
||||
}
|
||||
|
||||
db_select::context::db_select_op_t::auto go() const -> db_result<context> {
|
||||
return db_select{ctx}.go();
|
||||
}
|
||||
|
||||
db_select::context::db_select_op_t::auto
|
||||
group_by(std::string column_name) -> db_select::context::db_select_op_t {
|
||||
db_select{ctx}.group_by(column_name);
|
||||
return *this;
|
||||
}
|
||||
|
||||
db_select::context::db_select_op_t::auto
|
||||
limit(std::int32_t value) -> db_select::context::db_select_op_t {
|
||||
db_select{ctx}.limit(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::context::db_select_op_t::order_by(std::string column_name,
|
||||
bool ascending)
|
||||
-> db_select::context::db_select_op_t {
|
||||
db_select{ctx}.order_by(column_name, ascending);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::column(std::string column_name) -> db_select & {
|
||||
context_->columns.push_back(column_name);
|
||||
return *this;
|
||||
@ -70,6 +106,17 @@ auto db_select::dump() const -> std::string {
|
||||
query << " WHERE " << context_->where->dump(idx);
|
||||
}
|
||||
|
||||
if (not context_->group_by.empty()) {
|
||||
query << " GROUP BY ";
|
||||
for (std::size_t idx = 0U; idx < context_->group_by.size(); idx++) {
|
||||
if (idx > 0U) {
|
||||
group << ", ";
|
||||
}
|
||||
|
||||
query << "\"" << context_->group_by.at(idx) << "\"";
|
||||
}
|
||||
}
|
||||
|
||||
if (context_->order_by.has_value()) {
|
||||
query << " ORDER BY \"" << context_->order_by.value().first << "\" ";
|
||||
query << (context_->order_by.value().second ? "ASC" : "DESC");
|
||||
@ -127,6 +174,11 @@ auto db_select::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
||||
return context_->where->group(std::move(func));
|
||||
}
|
||||
|
||||
auto db_select::group_by(std::string column_name) -> db_select & {
|
||||
context_->group_by.emplace_back(std::move(column_name));
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::limit(std::int32_t value) -> db_select & {
|
||||
context_->limit = value;
|
||||
return *this;
|
||||
|
@ -24,6 +24,35 @@
|
||||
#if defined(PROJECT_ENABLE_SQLITE)
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
void db_update::context::clear() {
|
||||
column_values.clear();
|
||||
limit.reset();
|
||||
order_by.reset();
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
|
||||
db_update::context::db_update_op_t::auto dump() const -> std::string {
|
||||
return db_update{ctx}.dump();
|
||||
}
|
||||
|
||||
db_update::context::db_update_op_t::auto go() const -> db_result<context> {
|
||||
return db_update{ctx}.go();
|
||||
}
|
||||
|
||||
db_update::context::db_update_op_t::auto
|
||||
limit(std::int32_t value) -> db_update::context::db_update_op_t {
|
||||
db_update{ctx}.limit(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_update::context::db_update_op_t::order_by(std::string column_name,
|
||||
bool ascending)
|
||||
-> db_update::context::db_update_op_t {
|
||||
db_update{ctx}.order_by(column_name, ascending);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_update::column_value(std::string column_name,
|
||||
db_types_t value) -> db_update & {
|
||||
context_->column_values[column_name] = value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user