refactoring
This commit is contained in:
@ -31,6 +31,8 @@
|
||||
|
||||
namespace repertory {
|
||||
meta_db::meta_db(const app_config &cfg) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto db_path = utils::path::combine(cfg.get_data_directory(), {"meta.db3"});
|
||||
|
||||
sqlite3 *db3{nullptr};
|
||||
@ -38,9 +40,9 @@ meta_db::meta_db(const app_config &cfg) {
|
||||
sqlite3_open_v2(db_path.c_str(), &db3,
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
|
||||
if (res != SQLITE_OK) {
|
||||
utils::error::raise_error(__FUNCTION__, "failed to open db|" + db_path +
|
||||
'|' + std::to_string(res) +
|
||||
'|' + sqlite3_errstr(res));
|
||||
utils::error::raise_error(function_name, "failed to open db|" + db_path +
|
||||
'|' + std::to_string(res) +
|
||||
'|' + sqlite3_errstr(res));
|
||||
return;
|
||||
}
|
||||
db_.reset(db3);
|
||||
@ -56,7 +58,7 @@ meta_db::meta_db(const app_config &cfg) {
|
||||
");";
|
||||
std::string err;
|
||||
if (not db::execute_sql(*db_, create, err)) {
|
||||
utils::error::raise_error(__FUNCTION__,
|
||||
utils::error::raise_error(function_name,
|
||||
"failed to create db|" + db_path + '|' + err);
|
||||
db_.reset();
|
||||
return;
|
||||
@ -101,6 +103,8 @@ auto meta_db::get_api_path_list() -> std::vector<std::string> {
|
||||
|
||||
auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
|
||||
-> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto result = db::db_select{*db_, table_name}
|
||||
.column("*")
|
||||
.where("api_path")
|
||||
@ -128,7 +132,7 @@ auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
|
||||
|
||||
return api_error::item_not_found;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
|
||||
utils::error::raise_api_path_error(function_name, api_path, e,
|
||||
"failed to get item meta");
|
||||
}
|
||||
|
||||
@ -137,6 +141,8 @@ auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
|
||||
|
||||
auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
||||
std::string &value) const -> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto result = db::db_select{*db_, table_name}
|
||||
.column("*")
|
||||
.where("api_path")
|
||||
@ -167,7 +173,7 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
||||
|
||||
return api_error::item_not_found;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
|
||||
utils::error::raise_api_path_error(function_name, api_path, e,
|
||||
"failed to get item meta");
|
||||
}
|
||||
|
||||
@ -175,6 +181,8 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
||||
}
|
||||
|
||||
auto meta_db::get_pinned_files() const -> std::vector<std::string> {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::vector<std::string> ret{};
|
||||
|
||||
try {
|
||||
@ -190,13 +198,15 @@ auto meta_db::get_pinned_files() const -> std::vector<std::string> {
|
||||
}
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_error(__FUNCTION__, e, "failed to get pinned files");
|
||||
utils::error::raise_error(function_name, e, "failed to get pinned files");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto meta_db::get_total_item_count() const -> std::uint64_t {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::uint64_t ret{};
|
||||
|
||||
try {
|
||||
@ -209,7 +219,7 @@ auto meta_db::get_total_item_count() const -> std::uint64_t {
|
||||
row->get_column("count").get_value<std::int64_t>());
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_error(__FUNCTION__, e,
|
||||
utils::error::raise_error(function_name, e,
|
||||
"failed to get total item count");
|
||||
}
|
||||
|
||||
@ -217,6 +227,8 @@ auto meta_db::get_total_item_count() const -> std::uint64_t {
|
||||
}
|
||||
|
||||
void meta_db::remove_api_path(const std::string &api_path) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto result = db::db_select{*db_, table_name}
|
||||
.delete_query()
|
||||
.where("api_path")
|
||||
@ -224,7 +236,7 @@ void meta_db::remove_api_path(const std::string &api_path) {
|
||||
.go();
|
||||
if (not result.ok()) {
|
||||
utils::error::raise_api_path_error(
|
||||
__FUNCTION__, api_path, result.get_error(), "failed to remove meta");
|
||||
function_name, api_path, result.get_error(), "failed to remove meta");
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,6 +285,8 @@ auto meta_db::set_item_meta(const std::string &api_path,
|
||||
|
||||
auto meta_db::update_item_meta(const std::string &api_path, api_meta_map meta)
|
||||
-> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto directory = utils::string::to_bool(meta[META_DIRECTORY]);
|
||||
auto pinned = utils::string::to_bool(meta[META_PINNED]);
|
||||
auto source_path = meta[META_SOURCE];
|
||||
@ -290,7 +304,7 @@ auto meta_db::update_item_meta(const std::string &api_path, api_meta_map meta)
|
||||
.column_value("source_path", source_path)
|
||||
.go();
|
||||
if (not result.ok()) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path,
|
||||
utils::error::raise_api_path_error(function_name, api_path,
|
||||
result.get_error(),
|
||||
"failed to update item meta");
|
||||
return api_error::error;
|
||||
|
Reference in New Issue
Block a user