refactor
This commit is contained in:
parent
49e518ac19
commit
08e381a307
@ -43,8 +43,8 @@
|
|||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto create_resume_entry(const repertory::i_open_file &file)
|
||||||
create_resume_entry(const repertory::i_open_file &file) -> json {
|
-> json {
|
||||||
return {
|
return {
|
||||||
{"chunk_size", file.get_chunk_size()},
|
{"chunk_size", file.get_chunk_size()},
|
||||||
{"path", file.get_api_path()},
|
{"path", file.get_api_path()},
|
||||||
@ -338,7 +338,7 @@ auto file_manager::get_stored_downloads() const -> std::vector<json> {
|
|||||||
auto result = utils::db::sqlite::db_select{*db_, resume_table}.go();
|
auto result = utils::db::sqlite::db_select{*db_, resume_table}.go();
|
||||||
while (result.has_row()) {
|
while (result.has_row()) {
|
||||||
try {
|
try {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not result.get_row(row)) {
|
if (not result.get_row(row)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -375,7 +375,7 @@ auto file_manager::handle_file_rename(const std::string &from_api_path,
|
|||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(from_api_path)
|
.equals(from_api_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
should_upload = result.get_row(row) && row.has_value();
|
should_upload = result.get_row(row) && row.has_value();
|
||||||
if (should_upload && source_path.empty()) {
|
if (should_upload && source_path.empty()) {
|
||||||
source_path = row->get_column("source_path").get_value<std::string>();
|
source_path = row->get_column("source_path").get_value<std::string>();
|
||||||
@ -438,10 +438,11 @@ auto file_manager::open(const std::string &api_path, bool directory,
|
|||||||
return open(api_path, directory, ofd, handle, file, nullptr);
|
return open(api_path, directory, ofd, handle, file, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file_manager::open(
|
auto file_manager::open(const std::string &api_path, bool directory,
|
||||||
const std::string &api_path, bool directory, const open_file_data &ofd,
|
const open_file_data &ofd, std::uint64_t &handle,
|
||||||
std::uint64_t &handle, std::shared_ptr<i_open_file> &file,
|
std::shared_ptr<i_open_file> &file,
|
||||||
std::shared_ptr<i_closeable_open_file> closeable_file) -> api_error {
|
std::shared_ptr<i_closeable_open_file> closeable_file)
|
||||||
|
-> api_error {
|
||||||
const auto create_and_add_handle =
|
const auto create_and_add_handle =
|
||||||
[&](std::shared_ptr<i_closeable_open_file> cur_file) {
|
[&](std::shared_ptr<i_closeable_open_file> cur_file) {
|
||||||
handle = get_next_handle();
|
handle = get_next_handle();
|
||||||
@ -700,8 +701,8 @@ auto file_manager::rename_directory(const std::string &from_api_path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto file_manager::rename_file(const std::string &from_api_path,
|
auto file_manager::rename_file(const std::string &from_api_path,
|
||||||
const std::string &to_api_path,
|
const std::string &to_api_path, bool overwrite)
|
||||||
bool overwrite) -> api_error {
|
-> api_error {
|
||||||
if (not provider_.is_rename_supported()) {
|
if (not provider_.is_rename_supported()) {
|
||||||
return api_error::not_implemented;
|
return api_error::not_implemented;
|
||||||
}
|
}
|
||||||
@ -800,7 +801,7 @@ void file_manager::start() {
|
|||||||
auto result = utils::db::sqlite::db_select{*db_, upload_active_table}.go();
|
auto result = utils::db::sqlite::db_select{*db_, upload_active_table}.go();
|
||||||
while (result.has_row()) {
|
while (result.has_row()) {
|
||||||
try {
|
try {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
active_items.emplace_back(active_item{
|
active_items.emplace_back(active_item{
|
||||||
row->get_column("api_path").get_value<std::string>(),
|
row->get_column("api_path").get_value<std::string>(),
|
||||||
@ -824,7 +825,7 @@ void file_manager::start() {
|
|||||||
|
|
||||||
while (result.has_row()) {
|
while (result.has_row()) {
|
||||||
try {
|
try {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not(result.get_row(row) && row.has_value())) {
|
if (not(result.get_row(row) && row.has_value())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1039,7 +1040,7 @@ void file_manager::upload_handler() {
|
|||||||
.limit(1)
|
.limit(1)
|
||||||
.go();
|
.go();
|
||||||
try {
|
try {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
auto api_path = row->get_column("api_path").get_value<std::string>();
|
auto api_path = row->get_column("api_path").get_value<std::string>();
|
||||||
auto source_path =
|
auto source_path =
|
||||||
|
@ -69,9 +69,10 @@ const std::map<std::string, std::string> sql_create_tables = {
|
|||||||
namespace repertory {
|
namespace repertory {
|
||||||
encrypt_provider::encrypt_provider(app_config &config) : config_(config) {}
|
encrypt_provider::encrypt_provider(app_config &config) : config_(config) {}
|
||||||
|
|
||||||
auto encrypt_provider::create_api_file(
|
auto encrypt_provider::create_api_file(const std::string &api_path,
|
||||||
const std::string &api_path, bool directory,
|
bool directory,
|
||||||
const std::string &source_path) -> api_file {
|
const std::string &source_path)
|
||||||
|
-> api_file {
|
||||||
auto times = utils::file::get_times(source_path);
|
auto times = utils::file::get_times(source_path);
|
||||||
if (not times.has_value()) {
|
if (not times.has_value()) {
|
||||||
throw std::runtime_error("failed to get file times");
|
throw std::runtime_error("failed to get file times");
|
||||||
@ -187,8 +188,9 @@ auto encrypt_provider::do_fs_operation(
|
|||||||
return callback(cfg, source_path);
|
return callback(cfg, source_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::get_api_path_from_source(
|
auto encrypt_provider::get_api_path_from_source(const std::string &source_path,
|
||||||
const std::string &source_path, std::string &api_path) const -> api_error {
|
std::string &api_path) const
|
||||||
|
-> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -197,7 +199,7 @@ auto encrypt_provider::get_api_path_from_source(
|
|||||||
.where("source_path")
|
.where("source_path")
|
||||||
.equals(source_path)
|
.equals(source_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
api_path = row->get_column("data")
|
api_path = row->get_column("data")
|
||||||
.get_value_as_json()
|
.get_value_as_json()
|
||||||
@ -253,8 +255,9 @@ auto encrypt_provider::get_directory_item_count(
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::get_directory_items(
|
auto encrypt_provider::get_directory_items(const std::string &api_path,
|
||||||
const std::string &api_path, directory_item_list &list) const -> api_error {
|
directory_item_list &list) const
|
||||||
|
-> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
return do_fs_operation(
|
return do_fs_operation(
|
||||||
@ -273,7 +276,7 @@ auto encrypt_provider::get_directory_items(
|
|||||||
.where("source_path")
|
.where("source_path")
|
||||||
.equals(dir_entry->get_path())
|
.equals(dir_entry->get_path())
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
current_api_path =
|
current_api_path =
|
||||||
row->get_column("api_path").get_value<std::string>();
|
row->get_column("api_path").get_value<std::string>();
|
||||||
@ -302,7 +305,7 @@ auto encrypt_provider::get_directory_items(
|
|||||||
.where("source_path")
|
.where("source_path")
|
||||||
.equals(dir_entry->get_path())
|
.equals(dir_entry->get_path())
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
api_path_data =
|
api_path_data =
|
||||||
row->get_column("data").get_value<std::string>();
|
row->get_column("data").get_value<std::string>();
|
||||||
@ -385,7 +388,7 @@ auto encrypt_provider::get_file(const std::string &api_path,
|
|||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not(result.get_row(row) && row.has_value())) {
|
if (not(result.get_row(row) && row.has_value())) {
|
||||||
return api_error::item_not_found;
|
return api_error::item_not_found;
|
||||||
}
|
}
|
||||||
@ -427,8 +430,9 @@ auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
|
|||||||
return api_error::error;
|
return api_error::error;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::get_file_size(
|
auto encrypt_provider::get_file_size(const std::string &api_path,
|
||||||
const std::string &api_path, std::uint64_t &file_size) const -> api_error {
|
std::uint64_t &file_size) const
|
||||||
|
-> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -437,7 +441,7 @@ auto encrypt_provider::get_file_size(
|
|||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not(result.get_row(row) && row.has_value())) {
|
if (not(result.get_row(row) && row.has_value())) {
|
||||||
return api_error::item_not_found;
|
return api_error::item_not_found;
|
||||||
}
|
}
|
||||||
@ -454,15 +458,16 @@ auto encrypt_provider::get_file_size(
|
|||||||
return api_error::error;
|
return api_error::error;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::get_filesystem_item(
|
auto encrypt_provider::get_filesystem_item(const std::string &api_path,
|
||||||
const std::string &api_path, bool directory,
|
bool directory,
|
||||||
filesystem_item &fsi) const -> api_error {
|
filesystem_item &fsi) const
|
||||||
|
-> api_error {
|
||||||
auto result = utils::db::sqlite::db_select{*db_, source_table}
|
auto result = utils::db::sqlite::db_select{*db_, source_table}
|
||||||
.column("source_path")
|
.column("source_path")
|
||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not(result.get_row(row) && row.has_value())) {
|
if (not(result.get_row(row) && row.has_value())) {
|
||||||
return api_error::item_not_found;
|
return api_error::item_not_found;
|
||||||
}
|
}
|
||||||
@ -532,9 +537,10 @@ auto encrypt_provider::get_filesystem_item_from_source_path(
|
|||||||
return get_filesystem_item(api_path, false, fsi);
|
return get_filesystem_item(api_path, false, fsi);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::get_filesystem_item_and_file(
|
auto encrypt_provider::get_filesystem_item_and_file(const std::string &api_path,
|
||||||
const std::string &api_path, api_file &file,
|
api_file &file,
|
||||||
filesystem_item &fsi) const -> api_error {
|
filesystem_item &fsi) const
|
||||||
|
-> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -576,7 +582,7 @@ auto encrypt_provider::get_item_meta(const std::string &api_path,
|
|||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not(result.get_row(row) && row.has_value())) {
|
if (not(result.get_row(row) && row.has_value())) {
|
||||||
return api_error::item_not_found;
|
return api_error::item_not_found;
|
||||||
}
|
}
|
||||||
@ -624,7 +630,7 @@ auto encrypt_provider::get_total_item_count() const -> std::uint64_t {
|
|||||||
.count("api_path", "count")
|
.count("api_path", "count")
|
||||||
.go();
|
.go();
|
||||||
|
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
return static_cast<std::uint64_t>(
|
return static_cast<std::uint64_t>(
|
||||||
row->get_column("count").get_value<std::int64_t>());
|
row->get_column("count").get_value<std::int64_t>());
|
||||||
@ -647,7 +653,7 @@ auto encrypt_provider::is_directory(const std::string &api_path,
|
|||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not(result.get_row(row) && row.has_value())) {
|
if (not(result.get_row(row) && row.has_value())) {
|
||||||
exists = false;
|
exists = false;
|
||||||
return api_error::success;
|
return api_error::success;
|
||||||
@ -661,14 +667,14 @@ auto encrypt_provider::is_directory(const std::string &api_path,
|
|||||||
return api_error::success;
|
return api_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::is_file(const std::string &api_path,
|
auto encrypt_provider::is_file(const std::string &api_path, bool &exists) const
|
||||||
bool &exists) const -> api_error {
|
-> api_error {
|
||||||
auto result = utils::db::sqlite::db_select{*db_, source_table}
|
auto result = utils::db::sqlite::db_select{*db_, source_table}
|
||||||
.column("source_path")
|
.column("source_path")
|
||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not(result.get_row(row) && row.has_value())) {
|
if (not(result.get_row(row) && row.has_value())) {
|
||||||
exists = false;
|
exists = false;
|
||||||
return api_error::success;
|
return api_error::success;
|
||||||
@ -730,7 +736,7 @@ auto encrypt_provider::process_directory_entry(
|
|||||||
.where("source_path")
|
.where("source_path")
|
||||||
.equals(current_source_path)
|
.equals(current_source_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
current_api_path = row->get_column("api_path").get_value<std::string>();
|
current_api_path = row->get_column("api_path").get_value<std::string>();
|
||||||
}
|
}
|
||||||
@ -780,7 +786,7 @@ auto encrypt_provider::process_directory_entry(
|
|||||||
.where("source_path")
|
.where("source_path")
|
||||||
.equals(dir_entry.get_path())
|
.equals(dir_entry.get_path())
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
api_path_data = row->get_column("data").get_value<std::string>();
|
api_path_data = row->get_column("data").get_value<std::string>();
|
||||||
}
|
}
|
||||||
@ -854,7 +860,7 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
|
|||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (not(result.get_row(row) && row.has_value())) {
|
if (not(result.get_row(row) && row.has_value())) {
|
||||||
return api_error::item_not_found;
|
return api_error::item_not_found;
|
||||||
}
|
}
|
||||||
@ -958,11 +964,11 @@ void encrypt_provider::remove_deleted_files() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<removed_item> removed_list{};
|
std::vector<removed_item> removed_list{};
|
||||||
std::vector<utils::db::sqlite::db_select::row> row_list{};
|
std::vector<utils::db::sqlite::db_result::row> row_list{};
|
||||||
|
|
||||||
auto result = utils::db::sqlite::db_select{*db_, source_table}.go();
|
auto result = utils::db::sqlite::db_select{*db_, source_table}.go();
|
||||||
while (result.has_row()) {
|
while (result.has_row()) {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
row_list.push_back(row.value());
|
row_list.push_back(row.value());
|
||||||
}
|
}
|
||||||
@ -1037,7 +1043,7 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
|
|||||||
.where("api_path")
|
.where("api_path")
|
||||||
.equals("/")
|
.equals("/")
|
||||||
.go();
|
.go();
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
source_path = row->get_column("source_path").get_value<std::string>();
|
source_path = row->get_column("source_path").get_value<std::string>();
|
||||||
} else {
|
} else {
|
||||||
|
@ -66,7 +66,7 @@ auto meta_db::get_api_path(const std::string &source_path,
|
|||||||
.limit(1)
|
.limit(1)
|
||||||
.go();
|
.go();
|
||||||
|
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
api_path = row->get_column("api_path").get_value<std::string>();
|
api_path = row->get_column("api_path").get_value<std::string>();
|
||||||
return api_error::success;
|
return api_error::success;
|
||||||
@ -81,7 +81,7 @@ auto meta_db::get_api_path_list() -> std::vector<std::string> {
|
|||||||
auto result =
|
auto result =
|
||||||
utils::db::sqlite::db_select{*db_, table_name}.column("api_path").go();
|
utils::db::sqlite::db_select{*db_, table_name}.column("api_path").go();
|
||||||
while (result.has_row()) {
|
while (result.has_row()) {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
ret.push_back(row->get_column("api_path").get_value<std::string>());
|
ret.push_back(row->get_column("api_path").get_value<std::string>());
|
||||||
}
|
}
|
||||||
@ -90,8 +90,8 @@ auto meta_db::get_api_path_list() -> std::vector<std::string> {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto meta_db::get_item_meta(const std::string &api_path,
|
auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
|
||||||
api_meta_map &meta) -> api_error {
|
-> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
||||||
@ -106,7 +106,7 @@ auto meta_db::get_item_meta(const std::string &api_path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
meta = json::parse(row->get_column("data").get_value<std::string>())
|
meta = json::parse(row->get_column("data").get_value<std::string>())
|
||||||
.get<api_meta_map>();
|
.get<api_meta_map>();
|
||||||
@ -145,7 +145,7 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
value =
|
value =
|
||||||
key == META_SOURCE
|
key == META_SOURCE
|
||||||
@ -183,7 +183,7 @@ auto meta_db::get_pinned_files() const -> std::vector<std::string> {
|
|||||||
.equals(1)
|
.equals(1)
|
||||||
.go();
|
.go();
|
||||||
while (result.has_row()) {
|
while (result.has_row()) {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
ret.emplace_back(row->get_column("api_path").get_value<std::string>());
|
ret.emplace_back(row->get_column("api_path").get_value<std::string>());
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ auto meta_db::get_total_item_count() const -> std::uint64_t {
|
|||||||
.count("api_path", "count")
|
.count("api_path", "count")
|
||||||
.go();
|
.go();
|
||||||
|
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
ret = static_cast<std::uint64_t>(
|
ret = static_cast<std::uint64_t>(
|
||||||
row->get_column("count").get_value<std::int64_t>());
|
row->get_column("count").get_value<std::int64_t>());
|
||||||
@ -274,8 +274,8 @@ auto meta_db::set_item_meta(const std::string &api_path,
|
|||||||
return update_item_meta(api_path, existing_meta);
|
return update_item_meta(api_path, existing_meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto meta_db::update_item_meta(const std::string &api_path,
|
auto meta_db::update_item_meta(const std::string &api_path, api_meta_map meta)
|
||||||
api_meta_map meta) -> api_error {
|
-> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto directory = utils::string::to_bool(meta[META_DIRECTORY]);
|
auto directory = utils::string::to_bool(meta[META_DIRECTORY]);
|
||||||
|
@ -66,8 +66,6 @@ struct db_context_t {
|
|||||||
|
|
||||||
sqlite3 *db3{};
|
sqlite3 *db3{};
|
||||||
std::string table_name;
|
std::string table_name;
|
||||||
|
|
||||||
db3_stmt_t stmt;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class db_column final {
|
class db_column final {
|
||||||
@ -178,9 +176,20 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ctx_t> struct db_result final {
|
struct db_result final {
|
||||||
db_result(std::shared_ptr<ctx_t> ctx, std::int32_t res)
|
struct context final {
|
||||||
: ctx_(std::move(ctx)), res_(res) {
|
db3_stmt_t stmt;
|
||||||
|
};
|
||||||
|
|
||||||
|
using row = db_row<context>;
|
||||||
|
|
||||||
|
db_result(sqlite3_stmt *stmt, std::int32_t res)
|
||||||
|
: ctx_(std::make_shared<context>()), res_(res) {
|
||||||
|
ctx_->stmt = db3_stmt_t{
|
||||||
|
stmt,
|
||||||
|
sqlite3_statement_deleter(),
|
||||||
|
};
|
||||||
|
|
||||||
if (res == SQLITE_OK) {
|
if (res == SQLITE_OK) {
|
||||||
set_res(sqlite3_step(ctx_->stmt.get()));
|
set_res(sqlite3_step(ctx_->stmt.get()));
|
||||||
}
|
}
|
||||||
@ -193,14 +202,8 @@ template <typename ctx_t> struct db_result final {
|
|||||||
auto operator=(const db_result &) -> db_result & = default;
|
auto operator=(const db_result &) -> db_result & = default;
|
||||||
auto operator=(db_result &&) -> db_result & = default;
|
auto operator=(db_result &&) -> db_result & = default;
|
||||||
|
|
||||||
~db_result() {
|
|
||||||
if (ctx_) {
|
|
||||||
ctx_->clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ctx_t> ctx_;
|
std::shared_ptr<context> ctx_;
|
||||||
mutable std::int32_t res_{};
|
mutable std::int32_t res_{};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -218,14 +221,14 @@ public:
|
|||||||
return err_msg == nullptr ? std::to_string(res_) : err_msg;
|
return err_msg == nullptr ? std::to_string(res_) : err_msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto get_row(std::optional<db_row<ctx_t>> &row) const -> bool {
|
[[nodiscard]] auto get_row(std::optional<row> &opt_row) const -> bool {
|
||||||
row.reset();
|
opt_row.reset();
|
||||||
|
|
||||||
if (not has_row()) {
|
if (not has_row()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = db_row{ctx_};
|
opt_row = db_row<context>{ctx_};
|
||||||
set_res(sqlite3_step(ctx_->stmt.get()));
|
set_res(sqlite3_step(ctx_->stmt.get()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string;
|
[[nodiscard]] auto dump() const -> std::string;
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> db_result<context>;
|
[[nodiscard]] auto go() const -> db_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
context(sqlite3 *db3_, std::string table_name_)
|
context(sqlite3 *db3_, std::string table_name_)
|
||||||
@ -64,10 +64,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
[[nodiscard]] auto dump() const -> std::string;
|
[[nodiscard]] auto dump() const -> std::string;
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> db_result<context>;
|
[[nodiscard]] auto go() const -> db_result;
|
||||||
|
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto group(context::w_t::group_func_t func)
|
||||||
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
|
-> context::w_t::wn_t;
|
||||||
|
|
||||||
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
|
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
|
||||||
};
|
};
|
||||||
|
@ -55,12 +55,14 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto column_value(std::string column_name,
|
[[nodiscard]] auto column_value(std::string column_name, db_types_t value)
|
||||||
db_types_t value) -> db_insert &;
|
|
||||||
|
|
||||||
|
-> db_insert &;
|
||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string;
|
[[nodiscard]] auto dump() const -> std::string;
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> db_result<context>;
|
[[nodiscard]] auto go() const -> db_result;
|
||||||
};
|
};
|
||||||
} // namespace repertory::utils::db::sqlite
|
} // namespace repertory::utils::db::sqlite
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string;
|
[[nodiscard]] auto dump() const -> std::string;
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> db_result<context>;
|
[[nodiscard]] auto go() const -> db_result;
|
||||||
|
|
||||||
[[nodiscard]] auto group_by(std::string column_name) -> db_select_op_t;
|
[[nodiscard]] auto group_by(std::string column_name) -> db_select_op_t;
|
||||||
|
|
||||||
@ -44,8 +44,10 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] auto offset(std::int32_t value) -> db_select_op_t;
|
[[nodiscard]] auto offset(std::int32_t value) -> db_select_op_t;
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name,
|
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
|
||||||
bool ascending) -> db_select_op_t;
|
|
||||||
|
|
||||||
|
-> db_select_op_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
context(sqlite3 *db3_, std::string table_name_)
|
context(sqlite3 *db3_, std::string table_name_)
|
||||||
@ -67,8 +69,6 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
using row = db_row<context>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
db_select(sqlite3 &db3, std::string table_name)
|
db_select(sqlite3 &db3, std::string table_name)
|
||||||
: ctx_(std::make_shared<context>(&db3, table_name)) {}
|
: ctx_(std::make_shared<context>(&db3, table_name)) {}
|
||||||
@ -81,24 +81,30 @@ private:
|
|||||||
public:
|
public:
|
||||||
[[nodiscard]] auto column(std::string column_name) -> db_select &;
|
[[nodiscard]] auto column(std::string column_name) -> db_select &;
|
||||||
|
|
||||||
[[nodiscard]] auto count(std::string column_name,
|
[[nodiscard]] auto count(std::string column_name, std::string as_column_name)
|
||||||
std::string as_column_name) -> db_select &;
|
|
||||||
|
|
||||||
|
-> db_select &;
|
||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string;
|
[[nodiscard]] auto dump() const -> std::string;
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> db_result<context>;
|
[[nodiscard]] auto go() const -> db_result;
|
||||||
|
|
||||||
[[nodiscard]] auto group_by(std::string column_name) -> db_select &;
|
[[nodiscard]] auto group_by(std::string column_name) -> db_select &;
|
||||||
|
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto group(context::w_t::group_func_t func)
|
||||||
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
|
|
||||||
|
|
||||||
|
-> context::w_t::wn_t;
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> db_select &;
|
[[nodiscard]] auto limit(std::int32_t value) -> db_select &;
|
||||||
|
|
||||||
[[nodiscard]] auto offset(std::int32_t value) -> db_select &;
|
[[nodiscard]] auto offset(std::int32_t value) -> db_select &;
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name,
|
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
|
||||||
bool ascending) -> db_select &;
|
|
||||||
|
|
||||||
|
-> db_select &;
|
||||||
|
|
||||||
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
|
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
|
||||||
};
|
};
|
||||||
|
@ -39,12 +39,14 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string;
|
[[nodiscard]] auto dump() const -> std::string;
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> db_result<context>;
|
[[nodiscard]] auto go() const -> db_result;
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> db_update_op_t;
|
[[nodiscard]] auto limit(std::int32_t value) -> db_update_op_t;
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name,
|
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
|
||||||
bool ascending) -> db_update_op_t;
|
|
||||||
|
|
||||||
|
-> db_update_op_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
using w_t = db_where_t<context, db_update_op_t>;
|
using w_t = db_where_t<context, db_update_op_t>;
|
||||||
@ -71,20 +73,26 @@ private:
|
|||||||
std::shared_ptr<context> ctx_;
|
std::shared_ptr<context> ctx_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] auto column_value(std::string column_name,
|
[[nodiscard]] auto column_value(std::string column_name, db_types_t value)
|
||||||
db_types_t value) -> db_update &;
|
|
||||||
|
|
||||||
|
-> db_update &;
|
||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string;
|
[[nodiscard]] auto dump() const -> std::string;
|
||||||
|
|
||||||
[[nodiscard]] auto go() const -> db_result<context>;
|
[[nodiscard]] auto go() const -> db_result;
|
||||||
|
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto group(context::w_t::group_func_t func)
|
||||||
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
|
|
||||||
|
|
||||||
|
-> context::w_t::wn_t;
|
||||||
|
|
||||||
[[nodiscard]] auto limit(std::int32_t value) -> db_update &;
|
[[nodiscard]] auto limit(std::int32_t value) -> db_update &;
|
||||||
|
|
||||||
[[nodiscard]] auto order_by(std::string column_name,
|
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
|
||||||
bool ascending) -> db_update &;
|
|
||||||
|
|
||||||
|
-> db_update &;
|
||||||
|
|
||||||
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
|
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@ auto db_delete::context::db_delete_op_t::dump() const -> std::string {
|
|||||||
return db_delete{ctx}.dump();
|
return db_delete{ctx}.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_delete::context::db_delete_op_t::go() const -> db_result<context> {
|
auto db_delete::context::db_delete_op_t::go() const -> db_result {
|
||||||
return db_delete{ctx}.go();
|
return db_delete{ctx}.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,22 +48,18 @@ auto db_delete::dump() const -> std::string {
|
|||||||
return query.str();
|
return query.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_delete::go() const -> db_result<context> {
|
auto db_delete::go() const -> db_result {
|
||||||
sqlite3_stmt *stmt_ptr{nullptr};
|
sqlite3_stmt *stmt_ptr{nullptr};
|
||||||
auto query_str = dump();
|
auto query_str = dump();
|
||||||
auto res =
|
auto res =
|
||||||
sqlite3_prepare_v2(ctx_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr);
|
sqlite3_prepare_v2(ctx_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr);
|
||||||
ctx_->stmt = db3_stmt_t{
|
|
||||||
stmt_ptr,
|
|
||||||
sqlite3_statement_deleter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not ctx_->where_data) {
|
if (not ctx_->where_data) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
@ -71,21 +67,21 @@ auto db_delete::go() const -> db_result<context> {
|
|||||||
idx++) {
|
idx++) {
|
||||||
res = std::visit(
|
res = std::visit(
|
||||||
overloaded{
|
overloaded{
|
||||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
[&stmt_ptr, &idx](std::int64_t data) -> std::int32_t {
|
||||||
return sqlite3_bind_int64(ctx_->stmt.get(), idx + 1, data);
|
return sqlite3_bind_int64(stmt_ptr, idx + 1, data);
|
||||||
},
|
},
|
||||||
[this, &idx](const std::string &data) -> std::int32_t {
|
[&stmt_ptr, &idx](const std::string &data) -> std::int32_t {
|
||||||
return sqlite3_bind_text(ctx_->stmt.get(), idx + 1, data.c_str(),
|
return sqlite3_bind_text(stmt_ptr, idx + 1, data.c_str(), -1,
|
||||||
-1, nullptr);
|
nullptr);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ctx_->where_data->values.at(static_cast<std::size_t>(idx)));
|
ctx_->where_data->values.at(static_cast<std::size_t>(idx)));
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_delete::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
auto db_delete::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
namespace repertory::utils::db::sqlite {
|
namespace repertory::utils::db::sqlite {
|
||||||
void db_insert::context::clear() { values.clear(); }
|
void db_insert::context::clear() { values.clear(); }
|
||||||
|
|
||||||
auto db_insert::column_value(std::string column_name,
|
auto db_insert::column_value(std::string column_name, db_types_t value)
|
||||||
db_types_t value) -> db_insert & {
|
-> db_insert & {
|
||||||
ctx_->values[column_name] = value;
|
ctx_->values[column_name] = value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -61,18 +61,14 @@ auto db_insert::dump() const -> std::string {
|
|||||||
return query.str();
|
return query.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_insert::go() const -> db_result<context> {
|
auto db_insert::go() const -> db_result {
|
||||||
sqlite3_stmt *stmt_ptr{nullptr};
|
sqlite3_stmt *stmt_ptr{nullptr};
|
||||||
auto query_str = dump();
|
auto query_str = dump();
|
||||||
auto res =
|
auto res =
|
||||||
sqlite3_prepare_v2(ctx_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr);
|
sqlite3_prepare_v2(ctx_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr);
|
||||||
ctx_->stmt = db3_stmt_t{
|
|
||||||
stmt_ptr,
|
|
||||||
sqlite3_statement_deleter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
@ -89,11 +85,11 @@ auto db_insert::go() const -> db_result<context> {
|
|||||||
},
|
},
|
||||||
std::next(ctx_->values.begin(), idx)->second);
|
std::next(ctx_->values.begin(), idx)->second);
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
} // namespace repertory::utils::db::sqlite
|
} // namespace repertory::utils::db::sqlite
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ auto db_select::context::db_select_op_t::dump() const -> std::string {
|
|||||||
return db_select{ctx}.dump();
|
return db_select{ctx}.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_select::context::db_select_op_t::go() const -> db_result<context> {
|
auto db_select::context::db_select_op_t::go() const -> db_result {
|
||||||
return db_select{ctx}.go();
|
return db_select{ctx}.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,8 +72,8 @@ auto db_select::column(std::string column_name) -> db_select & {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_select::count(std::string column_name,
|
auto db_select::count(std::string column_name, std::string as_column_name)
|
||||||
std::string as_column_name) -> db_select & {
|
-> db_select & {
|
||||||
ctx_->count_columns[column_name] = as_column_name;
|
ctx_->count_columns[column_name] = as_column_name;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -142,22 +142,18 @@ auto db_select::dump() const -> std::string {
|
|||||||
return query.str();
|
return query.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_select::go() const -> db_result<context> {
|
auto db_select::go() const -> db_result {
|
||||||
sqlite3_stmt *stmt_ptr{nullptr};
|
sqlite3_stmt *stmt_ptr{nullptr};
|
||||||
auto query_str = dump();
|
auto query_str = dump();
|
||||||
auto res =
|
auto res =
|
||||||
sqlite3_prepare_v2(ctx_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr);
|
sqlite3_prepare_v2(ctx_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr);
|
||||||
ctx_->stmt = db3_stmt_t{
|
|
||||||
stmt_ptr,
|
|
||||||
sqlite3_statement_deleter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not ctx_->where_data) {
|
if (not ctx_->where_data) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
@ -175,11 +171,11 @@ auto db_select::go() const -> db_result<context> {
|
|||||||
},
|
},
|
||||||
ctx_->where_data->values.at(static_cast<std::size_t>(idx)));
|
ctx_->where_data->values.at(static_cast<std::size_t>(idx)));
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_select::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
auto db_select::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
||||||
@ -209,8 +205,8 @@ auto db_select::offset(std::int32_t value) -> db_select & {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_select::order_by(std::string column_name,
|
auto db_select::order_by(std::string column_name, bool ascending)
|
||||||
bool ascending) -> db_select & {
|
-> db_select & {
|
||||||
ctx_->order_by = {column_name, ascending};
|
ctx_->order_by = {column_name, ascending};
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ auto db_update::context::db_update_op_t::dump() const -> std::string {
|
|||||||
return db_update{ctx}.dump();
|
return db_update{ctx}.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_update::context::db_update_op_t::go() const -> db_result<context> {
|
auto db_update::context::db_update_op_t::go() const -> db_result {
|
||||||
return db_update{ctx}.go();
|
return db_update{ctx}.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ auto db_update::context::db_update_op_t::order_by(std::string column_name,
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_update::column_value(std::string column_name,
|
auto db_update::column_value(std::string column_name, db_types_t value)
|
||||||
db_types_t value) -> db_update & {
|
-> db_update & {
|
||||||
ctx_->column_values[column_name] = value;
|
ctx_->column_values[column_name] = value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -91,18 +91,15 @@ auto db_update::dump() const -> std::string {
|
|||||||
return query.str();
|
return query.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_update::go() const -> db_result<context> {
|
auto db_update::go() const -> db_result {
|
||||||
sqlite3_stmt *stmt_ptr{nullptr};
|
sqlite3_stmt *stmt_ptr{nullptr};
|
||||||
|
|
||||||
auto query_str = dump();
|
auto query_str = dump();
|
||||||
auto res =
|
auto res =
|
||||||
sqlite3_prepare_v2(ctx_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr);
|
sqlite3_prepare_v2(ctx_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr);
|
||||||
ctx_->stmt = db3_stmt_t{
|
|
||||||
stmt_ptr,
|
|
||||||
sqlite3_statement_deleter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
@ -119,12 +116,12 @@ auto db_update::go() const -> db_result<context> {
|
|||||||
},
|
},
|
||||||
std::next(ctx_->column_values.begin(), idx)->second);
|
std::next(ctx_->column_values.begin(), idx)->second);
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not ctx_->where_data) {
|
if (not ctx_->where_data) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
@ -149,11 +146,11 @@ auto db_update::go() const -> db_result<context> {
|
|||||||
},
|
},
|
||||||
ctx_->where_data->values.at(static_cast<std::size_t>(idx)));
|
ctx_->where_data->values.at(static_cast<std::size_t>(idx)));
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {ctx_, res};
|
return {stmt_ptr, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_update::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
auto db_update::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
||||||
@ -173,8 +170,8 @@ auto db_update::limit(std::int32_t value) -> db_update & {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto db_update::order_by(std::string column_name,
|
auto db_update::order_by(std::string column_name, bool ascending)
|
||||||
bool ascending) -> db_update & {
|
-> db_update & {
|
||||||
ctx_->order_by = {column_name, ascending};
|
ctx_->order_by = {column_name, ascending};
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ static void common_select(sqlite3 &db3, std::string value1, std::string value2,
|
|||||||
|
|
||||||
std::size_t row_count{};
|
std::size_t row_count{};
|
||||||
while (res.has_row()) {
|
while (res.has_row()) {
|
||||||
std::optional<utils::db::sqlite::db_select::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
EXPECT_TRUE(res.get_row(row));
|
EXPECT_TRUE(res.get_row(row));
|
||||||
EXPECT_TRUE(row.has_value());
|
EXPECT_TRUE(row.has_value());
|
||||||
if (row.has_value()) {
|
if (row.has_value()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user