refactor meta db to allow alternate implementations
This commit is contained in:
76
repertory/librepertory/include/db/i_meta_db.hpp
Normal file
76
repertory/librepertory/include/db/i_meta_db.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
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_DB_I_META_DB_HPP_
|
||||
#define REPERTORY_INCLUDE_DB_I_META_DB_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_meta_db {
|
||||
INTERFACE_SETUP(i_meta_db);
|
||||
|
||||
public:
|
||||
[[nodiscard]] virtual auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_api_path_list() const
|
||||
-> std::vector<std::string> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) const
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_pinned_files() const
|
||||
-> std::vector<std::string> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_total_item_count() const -> std::uint64_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_total_size() const -> std::uint64_t = 0;
|
||||
|
||||
virtual void remove_api_path(const std::string &api_path) = 0;
|
||||
|
||||
[[nodiscard]] virtual auto remove_item_meta(const std::string &api_path,
|
||||
const std::string &key)
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto rename_item_meta(const std::string &from_api_path,
|
||||
const std::string &to_api_path)
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto set_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto set_item_meta(const std::string &api_path,
|
||||
const api_meta_map &meta)
|
||||
-> api_error = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_DB_I_META_DB_HPP_
|
35
repertory/librepertory/include/db/meta_db.hpp
Normal file
35
repertory/librepertory/include/db/meta_db.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
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_DB_META_DB_HPP_
|
||||
#define REPERTORY_INCLUDE_DB_META_DB_HPP_
|
||||
|
||||
#include "db/i_meta_db.hpp"
|
||||
#include "db/sqlite_meta_db.hpp"
|
||||
|
||||
namespace repertory {
|
||||
[[nodiscard]] inline auto create_meta_db(const app_config &cfg)
|
||||
-> std::unique_ptr<i_meta_db> {
|
||||
return std::make_unique<sqlite_meta_db>(cfg);
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_DB_META_DB_HPP_
|
@ -19,24 +19,25 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef REPERTORY_INCLUDE_PROVIDERS_META_DB_HPP_
|
||||
#define REPERTORY_INCLUDE_PROVIDERS_META_DB_HPP_
|
||||
#ifndef REPERTORY_INCLUDE_DB_SQLITE_META_DB_HPP_
|
||||
#define REPERTORY_INCLUDE_DB_SQLITE_META_DB_HPP_
|
||||
|
||||
#include "db/i_meta_db.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/db/sqlite/db_common.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
|
||||
class meta_db final {
|
||||
class sqlite_meta_db final : public i_meta_db {
|
||||
public:
|
||||
meta_db(const app_config &cfg);
|
||||
~meta_db();
|
||||
sqlite_meta_db(const app_config &cfg);
|
||||
~sqlite_meta_db() override;
|
||||
|
||||
meta_db(const meta_db &) = delete;
|
||||
meta_db(meta_db &&) = delete;
|
||||
auto operator=(const meta_db &) -> meta_db & = delete;
|
||||
auto operator=(meta_db &&) -> meta_db & = delete;
|
||||
sqlite_meta_db(const sqlite_meta_db &) = delete;
|
||||
sqlite_meta_db(sqlite_meta_db &&) = delete;
|
||||
auto operator=(const sqlite_meta_db &) -> sqlite_meta_db & = delete;
|
||||
auto operator=(sqlite_meta_db &&) -> sqlite_meta_db & = delete;
|
||||
|
||||
private:
|
||||
utils::db::sqlite::db3_t db_;
|
||||
@ -48,39 +49,47 @@ private:
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) -> api_error;
|
||||
std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_api_path_list() -> std::vector<std::string>;
|
||||
[[nodiscard]] auto get_api_path_list() const
|
||||
-> std::vector<std::string> override;
|
||||
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error;
|
||||
api_meta_map &meta) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) const -> api_error;
|
||||
std::string &value) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_pinned_files() const -> std::vector<std::string>;
|
||||
[[nodiscard]] auto get_pinned_files() const
|
||||
-> std::vector<std::string> override;
|
||||
|
||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t;
|
||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto get_total_size() const -> std::uint64_t;
|
||||
[[nodiscard]] auto get_total_size() const -> std::uint64_t override;
|
||||
|
||||
void remove_api_path(const std::string &api_path);
|
||||
void remove_api_path(const std::string &api_path) override;
|
||||
|
||||
[[nodiscard]] auto remove_item_meta(const std::string &api_path,
|
||||
const std::string &key) -> api_error;
|
||||
const std::string &key)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto rename_item_meta(const std::string &from_api_path,
|
||||
const std::string &to_api_path)
|
||||
-> api_error;
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto set_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value) -> api_error;
|
||||
const std::string &value)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto set_item_meta(const std::string &api_path,
|
||||
const api_meta_map &meta) -> api_error;
|
||||
const api_meta_map &meta)
|
||||
-> api_error override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_PROVIDERS_META_DB_HPP_
|
||||
#endif // REPERTORY_INCLUDE_DB_SQLITE_META_DB_HPP_
|
@ -22,8 +22,8 @@
|
||||
#ifndef REPERTORY_INCLUDE_PROVIDERS_BASE_PROVIDER_HPP_
|
||||
#define REPERTORY_INCLUDE_PROVIDERS_BASE_PROVIDER_HPP_
|
||||
|
||||
#include "db/i_meta_db.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "providers/meta_db.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
@ -49,7 +49,7 @@ private:
|
||||
|
||||
private:
|
||||
api_item_added_callback api_item_added_;
|
||||
std::unique_ptr<meta_db> db3_;
|
||||
std::unique_ptr<i_meta_db> db3_;
|
||||
i_file_manager *fm_{};
|
||||
|
||||
private:
|
||||
@ -106,9 +106,9 @@ protected:
|
||||
return config_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_db() -> meta_db & { return *db3_; }
|
||||
[[nodiscard]] auto get_db() -> i_meta_db & { return *db3_; }
|
||||
|
||||
[[nodiscard]] auto get_db() const -> const meta_db & { return *db3_; }
|
||||
[[nodiscard]] auto get_db() const -> const i_meta_db & { return *db3_; }
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_items_impl(const std::string &api_path,
|
||||
|
Reference in New Issue
Block a user