updated build system
This commit is contained in:
parent
ea249723f9
commit
d3f3048568
@ -82,6 +82,7 @@ auto meta_db::get_api_path(const std::string &source_path,
|
|||||||
.column("api_path")
|
.column("api_path")
|
||||||
.where("source_path")
|
.where("source_path")
|
||||||
.equals(source_path)
|
.equals(source_path)
|
||||||
|
.op()
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.go();
|
.go();
|
||||||
|
|
||||||
@ -120,6 +121,7 @@ auto meta_db::get_item_meta(const std::string &api_path,
|
|||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
|
.op()
|
||||||
.go();
|
.go();
|
||||||
if (not result.has_row()) {
|
if (not result.has_row()) {
|
||||||
return api_error::item_not_found;
|
return api_error::item_not_found;
|
||||||
@ -159,6 +161,7 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
|||||||
.column("*")
|
.column("*")
|
||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
|
.op()
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.go();
|
.go();
|
||||||
if (not result.has_row()) {
|
if (not result.has_row()) {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "utils/db/sqlite/db_common.hpp"
|
#include "utils/db/sqlite/db_common.hpp"
|
||||||
|
|
||||||
#include "utils/db/sqlite/db_where_limit_t.hpp"
|
#include "utils/db/sqlite/db_where_t.hpp"
|
||||||
|
|
||||||
namespace repertory::utils::db::sqlite {
|
namespace repertory::utils::db::sqlite {
|
||||||
class db_select final {
|
class db_select final {
|
||||||
@ -34,7 +34,7 @@ public:
|
|||||||
context(sqlite3 &db3_, std::string table_name_)
|
context(sqlite3 &db3_, std::string table_name_)
|
||||||
: db_context_t(db3_, table_name_) {}
|
: db_context_t(db3_, table_name_) {}
|
||||||
|
|
||||||
using w_t = db_where_limit_t<context, db_select>;
|
using w_t = db_where_t<context, db_select>;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "utils/db/sqlite/db_common.hpp"
|
#include "utils/db/sqlite/db_common.hpp"
|
||||||
|
|
||||||
#include "utils/db/sqlite/db_where_limit_t.hpp"
|
#include "utils/db/sqlite/db_where_t.hpp"
|
||||||
|
|
||||||
namespace repertory::utils::db::sqlite {
|
namespace repertory::utils::db::sqlite {
|
||||||
class db_update final {
|
class db_update final {
|
||||||
@ -34,7 +34,7 @@ public:
|
|||||||
context(sqlite3 &db3_, std::string table_name_)
|
context(sqlite3 &db3_, std::string table_name_)
|
||||||
: db_context_t(db3_, table_name_) {}
|
: db_context_t(db3_, table_name_) {}
|
||||||
|
|
||||||
using w_t = db_where_limit_t<context, db_update>;
|
using w_t = db_where_t<context, db_update>;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -1,235 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
#ifndef REPERTORY_INCLUDE_UTILS_DB_SQLITE_DB_WHERE_LIMIT_T_HPP_
|
|
||||||
#define REPERTORY_INCLUDE_UTILS_DB_SQLITE_DB_WHERE_LIMIT_T_HPP_
|
|
||||||
#if defined(PROJECT_ENABLE_SQLITE)
|
|
||||||
|
|
||||||
#include "utils/db/sqlite/db_common.hpp"
|
|
||||||
|
|
||||||
namespace repertory::utils::db::sqlite {
|
|
||||||
template <typename cn_t, typename ctx_t, typename op_t, typename w_t,
|
|
||||||
typename wn_t>
|
|
||||||
struct db_next_limit_t final {
|
|
||||||
std::shared_ptr<ctx_t> ctx;
|
|
||||||
w_t *owner;
|
|
||||||
|
|
||||||
std::string action;
|
|
||||||
|
|
||||||
using group_func_t = std::function<void(w_t &)>;
|
|
||||||
|
|
||||||
[[nodiscard]] auto where(std::string column_name) -> cn_t {
|
|
||||||
return get_next().where(column_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[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);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_next() -> w_t & {
|
|
||||||
return std::get<w_t>(std::prev(owner->sub_actions->end()));
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_next() const -> const w_t & {
|
|
||||||
return std::get<w_t>(std::prev(owner->sub_actions->end()));
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
|
||||||
|
|
||||||
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
|
||||||
return get_next().group(std::move(func));
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> op_t {
|
|
||||||
return op_t{ctx}.limit(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name, bool ascending) -> op_t {
|
|
||||||
return op_t{ctx}.order_by(column_name, ascending);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename cn_t, typename ctx_t, typename op_t, typename w_t>
|
|
||||||
struct db_where_next_limit_t final {
|
|
||||||
std::shared_ptr<ctx_t> ctx;
|
|
||||||
w_t *owner;
|
|
||||||
|
|
||||||
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 {
|
|
||||||
owner->actions.emplace_back(n_t{
|
|
||||||
ctx,
|
|
||||||
owner,
|
|
||||||
"AND",
|
|
||||||
});
|
|
||||||
|
|
||||||
owner->sub_actions.emplace_back(w_t{
|
|
||||||
ctx,
|
|
||||||
});
|
|
||||||
|
|
||||||
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::int32_t &idx) const -> std::string {
|
|
||||||
return ctx->where->dump(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> op_t {
|
|
||||||
return op_t{ctx}.limit(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name, bool ascending) -> op_t {
|
|
||||||
return op_t{ctx}.order_by(column_name, ascending);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto or_() -> n_t {
|
|
||||||
owner->actions.emplace_back(n_t{
|
|
||||||
ctx,
|
|
||||||
owner,
|
|
||||||
"OR",
|
|
||||||
});
|
|
||||||
|
|
||||||
owner->sub_actions.emplace_back(w_t{
|
|
||||||
ctx,
|
|
||||||
});
|
|
||||||
|
|
||||||
return std::get<n_t>(*std::prev(owner->actions.end()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename ctx_t, typename op_t, typename w_t>
|
|
||||||
struct db_comp_next_limit_t final {
|
|
||||||
std::shared_ptr<ctx_t> ctx;
|
|
||||||
w_t *owner;
|
|
||||||
std::string column_name;
|
|
||||||
|
|
||||||
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_types_t value) {
|
|
||||||
owner->actions.emplace_back(db_comp_data_t{
|
|
||||||
column_name,
|
|
||||||
operation,
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx->where_values.push_back(value);
|
|
||||||
|
|
||||||
return wn_t{
|
|
||||||
ctx,
|
|
||||||
owner,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto equals(db_types_t value) -> wn_t { return create("=", value); };
|
|
||||||
|
|
||||||
auto gt(db_types_t value) -> wn_t { return create(">", value); }
|
|
||||||
|
|
||||||
auto gte(db_types_t value) -> wn_t { return create(">=", value); }
|
|
||||||
|
|
||||||
auto like(db_types_t value) -> wn_t { return create("LIKE", value); }
|
|
||||||
|
|
||||||
auto lt(db_types_t value) -> wn_t { return create("<", value); }
|
|
||||||
|
|
||||||
auto lte(db_types_t value) -> wn_t { return create("<=", value); }
|
|
||||||
|
|
||||||
auto not_equals(db_types_t value) -> wn_t { return create("!=", value); };
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename ctx_t, typename op_t> struct db_where_limit_t final {
|
|
||||||
std::shared_ptr<ctx_t> ctx;
|
|
||||||
|
|
||||||
using cn_t = db_comp_next_limit_t<ctx_t, op_t, db_where_limit_t>;
|
|
||||||
using wn_t = db_where_next_limit_t<cn_t, ctx_t, op_t, db_where_limit_t>;
|
|
||||||
using n_t = db_next_limit_t<cn_t, ctx_t, op_t, db_where_limit_t, wn_t>;
|
|
||||||
|
|
||||||
using group_func_t = std::function<void(db_where_limit_t &)>;
|
|
||||||
|
|
||||||
using action_t = std::variant<db_comp_data_t, n_t, db_where_limit_t>;
|
|
||||||
|
|
||||||
std::vector<action_t> actions{};
|
|
||||||
std::vector<db_where_limit_t> sub_actions{};
|
|
||||||
|
|
||||||
[[nodiscard]] static auto dump(std::int32_t &idx,
|
|
||||||
auto &&data) -> std::string {
|
|
||||||
std::stringstream stream;
|
|
||||||
|
|
||||||
for (auto &&action : data.actions) {
|
|
||||||
std::visit(overloaded{
|
|
||||||
[&idx, &stream](const db_comp_data_t &comp) {
|
|
||||||
stream << '"' << comp.column_name << '"' << comp.op_type
|
|
||||||
<< '?' + std::to_string(++idx);
|
|
||||||
},
|
|
||||||
[&idx, &stream](const n_t &next) {
|
|
||||||
stream << ' ' << next.action << ' '
|
|
||||||
<< dump(idx, next.get_next());
|
|
||||||
},
|
|
||||||
[&idx, &stream](const db_where_limit_t &where) {
|
|
||||||
stream << '(' << dump(idx, where) << ')';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
action);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stream.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
|
|
||||||
return dump(idx, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
|
||||||
db_where_limit_t where{ctx};
|
|
||||||
func(where);
|
|
||||||
|
|
||||||
actions.emplace_back(std::move(where));
|
|
||||||
return wn_t{
|
|
||||||
ctx,
|
|
||||||
this,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> op_t {
|
|
||||||
return op_t{ctx}.limit(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name, bool ascending) -> op_t {
|
|
||||||
return op_t{ctx}.order_by(column_name, ascending);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto where(std::string column_name) -> cn_t {
|
|
||||||
return cn_t{
|
|
||||||
ctx,
|
|
||||||
this,
|
|
||||||
column_name,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace repertory::utils::db::sqlite
|
|
||||||
|
|
||||||
#endif // defined(PROJECT_ENABLE_SQLITE)
|
|
||||||
#endif // REPERTORY_INCLUDE_UTILS_DB_SQLITE_DB_WHERE_LIMIT_T_HPP_
|
|
@ -46,11 +46,11 @@ struct db_next_t final {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto get_next() -> w_t & {
|
[[nodiscard]] auto get_next() -> w_t & {
|
||||||
return std::get<w_t>(std::prev(owner->sub_actions->end()));
|
return std::get<w_t>(std::prev(owner->sub_actions.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto get_next() const -> const w_t & {
|
[[nodiscard]] auto get_next() const -> const w_t & {
|
||||||
return std::get<w_t>(std::prev(owner->sub_actions->end()));
|
return std::get<w_t>(std::prev(owner->sub_actions.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
||||||
@ -58,6 +58,12 @@ struct db_next_t final {
|
|||||||
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
||||||
return get_next().group(std::move(func));
|
return get_next().group(std::move(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto op() -> op_t {
|
||||||
|
return op_t{
|
||||||
|
ctx,
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename cn_t, typename ctx_t, typename op_t, typename w_t>
|
template <typename cn_t, typename ctx_t, typename op_t, typename w_t>
|
||||||
@ -89,6 +95,12 @@ struct db_where_next_t final {
|
|||||||
|
|
||||||
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
||||||
|
|
||||||
|
[[nodiscard]] auto op() -> op_t {
|
||||||
|
return op_t{
|
||||||
|
ctx,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto or_() -> n_t {
|
[[nodiscard]] auto or_() -> n_t {
|
||||||
owner->actions.emplace_back(n_t{
|
owner->actions.emplace_back(n_t{
|
||||||
ctx,
|
ctx,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user