#ifndef MATADOR_SCHEMA_HPP #define MATADOR_SCHEMA_HPP #include "matador/object/repository.hpp" namespace matador::sql { class connection_pool; } namespace matador::orm { class schema; using schema_ref = std::reference_wrapper; class schema_repository final { public: utils::result add(const std::string &name, const schema &schema); utils::result remove(const std::string &name); [[nodiscard]] utils::result get(const std::string &name); private: std::unordered_map schema_map_; }; class schema final { public: schema(sql::connection_pool &pool, const std::string &name); template [[nodiscard]] utils::result attach(const std::string &name, const std::string &parent = "") { return repo_.attach(name, parent); } template [[nodiscard]] utils::result attach(const std::string &name) { return repo_.attach(name); } utils::result create() const; utils::result drop() const; template utils::result drop_table(); utils::result drop_table(const std::string &table_name) const; [[nodiscard]] utils::result, utils::error> describe_table(const std::string &table_name) const; [[nodiscard]] utils::result table_exists(const std::string &table_name) const; private: object::repository repo_; sql::connection_pool &pool_; }; template utils::result schema::drop_table() { auto info = repo_.info(); if (info) { return drop_table(info->get().name()); } return utils::failure(info.err()); } } #endif //MATADOR_SCHEMA_HPP