Compare commits
12 Commits
9aafb62961
...
196aeae11f
Author | SHA1 | Date | |
---|---|---|---|
196aeae11f | |||
ba2850ea21 | |||
1f4872769d | |||
24c647966b | |||
d3f3048568 | |||
ea249723f9 | |||
52a2df2576 | |||
6645b322bd | |||
7a683a46a9 | |||
cb24252286 | |||
fff3dc4685 | |||
9c01d51334 |
@ -1,15 +1,15 @@
|
||||
set(BINUTILS_VERSION 2.41)
|
||||
set(BOOST2_MAJOR_VERSION 1)
|
||||
set(BOOST2_MINOR_VERSION 76)
|
||||
set(BOOST2_PATCH_VERSION 0)
|
||||
set(BOOST_MAJOR_VERSION 1)
|
||||
set(BOOST_MINOR_VERSION 85)
|
||||
set(BOOST_PATCH_VERSION 0)
|
||||
set(BOOST2_MAJOR_VERSION 1)
|
||||
set(BOOST2_MINOR_VERSION 76)
|
||||
set(BOOST2_PATCH_VERSION 0)
|
||||
set(CPP_HTTPLIB_VERSION 0.16.3)
|
||||
set(CURL2_VERSION 8_9_1)
|
||||
set(CURL_VERSION 8.9.1)
|
||||
set(EXPAT2_VERSION 2_6_2)
|
||||
set(CURL2_VERSION 8_9_1)
|
||||
set(EXPAT_VERSION 2.6.2)
|
||||
set(EXPAT2_VERSION 2_6_2)
|
||||
set(GCC_VERSION 14.2.0)
|
||||
set(GTEST_VERSION 1.15.2)
|
||||
set(ICU_VERSION 75-1)
|
||||
@ -21,7 +21,7 @@ set(OPENSSL_VERSION 3.3.1)
|
||||
set(PKG_CONFIG_VERSION 0.29.2)
|
||||
set(PUGIXML_VERSION 1.14)
|
||||
set(SPDLOG_VERSION 1.14.1)
|
||||
set(SQLITE2_VERSION 3.46.1)
|
||||
set(SQLITE_VERSION 3460100)
|
||||
set(SQLITE2_VERSION 3.46.1)
|
||||
set(STDUUID_VERSION 1.2.3)
|
||||
set(ZLIB_VERSION 1.3.1)
|
||||
|
@ -82,6 +82,7 @@ auto meta_db::get_api_path(const std::string &source_path,
|
||||
.column("api_path")
|
||||
.where("source_path")
|
||||
.equals(source_path)
|
||||
.op()
|
||||
.limit(1)
|
||||
.go();
|
||||
|
||||
@ -119,6 +120,7 @@ auto meta_db::get_item_meta(const std::string &api_path,
|
||||
.column("*")
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.op()
|
||||
.limit(1)
|
||||
.go();
|
||||
if (not result.has_row()) {
|
||||
@ -159,6 +161,7 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
||||
.column("*")
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.op()
|
||||
.limit(1)
|
||||
.go();
|
||||
if (not result.has_row()) {
|
||||
|
@ -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>;
|
||||
|
@ -25,32 +25,42 @@
|
||||
|
||||
#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 {
|
||||
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_with_limit_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;
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#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 {
|
||||
class db_update final {
|
||||
@ -33,7 +33,21 @@ public:
|
||||
struct context final : db_context_t {
|
||||
context(sqlite3 &db3_, std::string table_name_)
|
||||
: db_context_t(db3_, table_name_) {}
|
||||
using w_t = db_where_with_limit_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;
|
||||
@ -41,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>;
|
||||
|
@ -1,216 +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;
|
||||
std::string action;
|
||||
|
||||
w_t next{ctx};
|
||||
|
||||
using group_func_t = std::function<void(w_t &)>;
|
||||
|
||||
[[nodiscard]] auto where(std::string column_name) -> cn_t {
|
||||
return 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 go() const -> auto { return op_t{ctx}.go(); }
|
||||
|
||||
[[nodiscard]] auto group(group_func_t func) -> wn_t {
|
||||
return 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,
|
||||
"AND",
|
||||
});
|
||||
|
||||
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,
|
||||
"OR",
|
||||
});
|
||||
|
||||
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_with_limit_t final {
|
||||
std::shared_ptr<ctx_t> ctx;
|
||||
|
||||
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, ctx_t, op_t, db_where_with_limit_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 action_t = std::variant<db_comp_data_t, n_t, db_where_with_limit_t>;
|
||||
|
||||
std::vector<action_t> 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.next);
|
||||
},
|
||||
[&idx, &stream](const db_where_with_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_with_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_
|
@ -30,14 +30,13 @@ template <typename cn_t, typename ctx_t, typename op_t, typename w_t,
|
||||
typename wn_t>
|
||||
struct db_next_t final {
|
||||
std::shared_ptr<ctx_t> ctx;
|
||||
w_t *owner;
|
||||
std::string action;
|
||||
|
||||
w_t next{ctx};
|
||||
|
||||
using group_func_t = std::function<void(w_t &)>;
|
||||
|
||||
[[nodiscard]] auto where(std::string column_name) -> cn_t {
|
||||
return next.where(column_name);
|
||||
return get_next().where(column_name);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||
@ -46,10 +45,24 @@ struct db_next_t final {
|
||||
return ctx->where->dump(idx);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_next() -> w_t & {
|
||||
return *std::prev(owner->sub_actions.end());
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_next() const -> const w_t & {
|
||||
return *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 next.group(std::move(func));
|
||||
return get_next().group(std::move(func));
|
||||
}
|
||||
|
||||
[[nodiscard]] auto op() -> op_t {
|
||||
return op_t{
|
||||
ctx,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@ -60,12 +73,17 @@ struct db_where_next_t final {
|
||||
|
||||
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{
|
||||
ctx,
|
||||
owner,
|
||||
"AND",
|
||||
});
|
||||
|
||||
owner->sub_actions.emplace_back(w_t{
|
||||
ctx,
|
||||
});
|
||||
|
||||
return std::get<n_t>(*std::prev(owner->actions.end()));
|
||||
}
|
||||
|
||||
@ -77,12 +95,23 @@ struct db_where_next_t final {
|
||||
|
||||
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
|
||||
|
||||
[[nodiscard]] auto or_() -> n_t & {
|
||||
[[nodiscard]] auto op() -> op_t {
|
||||
return op_t{
|
||||
ctx,
|
||||
};
|
||||
}
|
||||
|
||||
[[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()));
|
||||
}
|
||||
};
|
||||
@ -136,6 +165,7 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
|
||||
using action_t = std::variant<db_comp_data_t, n_t, db_where_t>;
|
||||
|
||||
std::vector<action_t> actions{};
|
||||
std::vector<db_where_t> sub_actions{};
|
||||
|
||||
[[nodiscard]] static auto dump(std::int32_t &idx,
|
||||
auto &&data) -> std::string {
|
||||
@ -149,7 +179,7 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
|
||||
},
|
||||
[&idx, &stream](const n_t &next) {
|
||||
stream << ' ' << next.action << ' '
|
||||
<< dump(idx, next.next);
|
||||
<< dump(idx, next.get_next());
|
||||
},
|
||||
[&idx, &stream](const db_where_t &where) {
|
||||
stream << '(' << dump(idx, where) << ')';
|
||||
|
@ -44,7 +44,9 @@ auto execute_sql(sqlite3 &db3, const std::string &sql,
|
||||
}
|
||||
|
||||
void set_journal_mode(sqlite3 &db3) {
|
||||
sqlite3_exec(&db3, "PRAGMA journal_mode = WAL;PRAGMA synchronous = NORMAL;",
|
||||
sqlite3_exec(&db3,
|
||||
"PRAGMA journal_mode = WAL;PRAGMA synchronous = NORMAL;PRAGMA "
|
||||
"auto_vacuum = FULL;",
|
||||
nullptr, nullptr, nullptr);
|
||||
}
|
||||
} // namespace repertory::utils::db::sqlite
|
||||
|
@ -24,6 +24,19 @@
|
||||
#if defined(PROJECT_ENABLE_SQLITE)
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
void db_delete::context::clear() {
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
|
||||
auto db_delete::context::db_delete_op_t::dump() const -> std::string {
|
||||
return db_delete{ctx}.dump();
|
||||
}
|
||||
|
||||
auto db_delete::context::db_delete_op_t::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();
|
||||
}
|
||||
|
||||
auto db_select::context::db_select_op_t::dump() const -> std::string {
|
||||
return db_select{ctx}.dump();
|
||||
}
|
||||
|
||||
auto db_select::context::db_select_op_t::go() const -> db_result<context> {
|
||||
return db_select{ctx}.go();
|
||||
}
|
||||
|
||||
auto db_select::context::db_select_op_t::group_by(std::string column_name)
|
||||
-> db_select::context::db_select_op_t {
|
||||
db_select{ctx}.group_by(column_name);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::context::db_select_op_t::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();
|
||||
}
|
||||
|
||||
auto db_update::context::db_update_op_t::dump() const -> std::string {
|
||||
return db_update{ctx}.dump();
|
||||
}
|
||||
|
||||
auto db_update::context::db_update_op_t::go() const -> db_result<context> {
|
||||
return db_update{ctx}.go();
|
||||
}
|
||||
|
||||
auto db_update::context::db_update_op_t::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;
|
||||
|
@ -30,10 +30,15 @@
|
||||
namespace {
|
||||
[[nodiscard]] auto resolve(std::string path) -> std::string {
|
||||
#if defined(_WIN32)
|
||||
if (repertory::utils::string::contains(path, "~\\") ||
|
||||
repertory::utils::string::contains(path, "%")) {
|
||||
if (repertory::utils::string::contains(path, "~\\")) {
|
||||
repertory::utils::string::replace(path, "~\\", "%USERPROFILE%\\");
|
||||
}
|
||||
|
||||
if (repertory::utils::string::contains(path, "~/")) {
|
||||
repertory::utils::string::replace(path, "~/", "%USERPROFILE%\\");
|
||||
}
|
||||
|
||||
if (repertory::utils::string::contains(path, "%")) {
|
||||
auto size = ::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0);
|
||||
|
||||
std::string dest;
|
||||
@ -43,6 +48,10 @@ namespace {
|
||||
path = dest.c_str();
|
||||
}
|
||||
#else // !defined (_WIN32)
|
||||
if (repertory::utils::string::contains(path, "~\\")) {
|
||||
repertory::utils::string::replace(path, "~\\", "~/");
|
||||
}
|
||||
|
||||
if (repertory::utils::string::contains(path, "~/")) {
|
||||
std::string home{};
|
||||
auto res =
|
||||
@ -57,11 +66,11 @@ namespace {
|
||||
throw std::runtime_error("failed to getpwuid: " + res.reason);
|
||||
}
|
||||
|
||||
return repertory::utils::string::replace(path, "~/", home + "/");
|
||||
path = repertory::utils::string::replace(path, "~/", home + "/");
|
||||
}
|
||||
#endif // defined (_WIN32)
|
||||
|
||||
return path;
|
||||
return repertory::utils::path::finalize(path);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -72,7 +81,7 @@ auto absolute(std::string_view path) -> std::string {
|
||||
return abs_path;
|
||||
}
|
||||
|
||||
abs_path = finalize(resolve(abs_path));
|
||||
abs_path = resolve(abs_path);
|
||||
#if defined(_WIN32)
|
||||
if (not utils::string::contains(abs_path, dot)) {
|
||||
return abs_path;
|
||||
|
@ -387,13 +387,7 @@ TEST(utils_path, absolute) {
|
||||
|
||||
path = utils::path::absolute(R"(\\server\share)");
|
||||
EXPECT_STREQ(R"(/server/share)", path.c_str());
|
||||
|
||||
auto home_env = utils::get_environment_variable("HOME");
|
||||
#endif // defined(_WIN32)
|
||||
auto home = utils::path::absolute(home_env);
|
||||
|
||||
path = utils::path::absolute("~");
|
||||
EXPECT_STREQ(home.c_str(), path.c_str());
|
||||
}
|
||||
|
||||
TEST(utils_path, absolute_can_resolve_path_variables) {
|
||||
@ -408,19 +402,20 @@ TEST(utils_path, absolute_can_resolve_path_variables) {
|
||||
static_cast<DWORD>(home.size()));
|
||||
home = utils::path::absolute(home);
|
||||
|
||||
auto expanded_str = utils::path::absolute("%USERPROFILE%");
|
||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
||||
|
||||
expanded_str = utils::path::absolute("~");
|
||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
||||
EXPECT_STREQ((home + home).c_str(), expanded_str.c_str());
|
||||
EXPECT_STREQ(home.c_str(), utils::path::absolute("%USERPROFILE%").c_str());
|
||||
#else // !defined(_WIN32)
|
||||
home = std::getenv("HOME");
|
||||
home = utils::path::absolute(home);
|
||||
|
||||
auto expanded_str = utils::path::absolute("~");
|
||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
auto expanded_str = utils::path::absolute("~\\");
|
||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
||||
|
||||
expanded_str = utils::path::absolute("~/");
|
||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
||||
|
||||
expanded_str = utils::path::absolute("~");
|
||||
EXPECT_STREQ("~", expanded_str.c_str());
|
||||
}
|
||||
|
||||
TEST(utils_path, get_parent_path) {
|
||||
|
Reference in New Issue
Block a user