moved schema to query namespace
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#ifndef MATADOR_SCHEMA_HPP
|
||||
#define MATADOR_SCHEMA_HPP
|
||||
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "matador/sql/query_context.hpp"
|
||||
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
class connection_pool;
|
||||
}
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
class schema;
|
||||
|
||||
using schema_ref = std::reference_wrapper<schema>;
|
||||
|
||||
class schema_repository final {
|
||||
public:
|
||||
utils::result<void, utils::error> add(const std::string &name, const schema &schema);
|
||||
utils::result<void, utils::error> remove(const std::string &name);
|
||||
|
||||
[[nodiscard]] utils::result<schema_ref, utils::error> get(const std::string &name);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, schema> schema_map_;
|
||||
};
|
||||
|
||||
class schema final {
|
||||
public:
|
||||
explicit schema(sql::connection_pool &pool);
|
||||
schema(sql::connection_pool &pool, const std::string &name);
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &name, const std::string &parent = "") {
|
||||
return repo_.attach<Type>(name, parent);
|
||||
}
|
||||
|
||||
template<typename Type, typename SuperType>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &name) {
|
||||
return repo_.attach<Type, SuperType>(name);
|
||||
}
|
||||
|
||||
[[nodiscard]] utils::result<void, utils::error> create() const;
|
||||
[[nodiscard]] utils::result<void, utils::error> drop() const;
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<void, utils::error> drop_table();
|
||||
[[nodiscard]] utils::result<void, utils::error> drop_table(const std::string &table_name) const;
|
||||
|
||||
[[nodiscard]] utils::result<std::vector<object::attribute>, utils::error> describe_table(const std::string &table_name) const;
|
||||
[[nodiscard]] utils::result<bool, utils::error> table_exists(const std::string &table_name) const;
|
||||
|
||||
private:
|
||||
[[nodiscard]] sql::query_context build_add_constraint_context( const object::repository_node& node, const object::restriction& cons ) const;
|
||||
[[nodiscard]] sql::query_context build_drop_constraint_context( const object::repository_node& node, const object::restriction& cons ) const;
|
||||
|
||||
private:
|
||||
object::repository repo_;
|
||||
std::unordered_map<std::type_index, table> table_map_;
|
||||
sql::connection_pool &pool_;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
utils::result<void, utils::error> schema::drop_table() {
|
||||
auto info = repo_.info<Type>();
|
||||
if (info) {
|
||||
return drop_table(info->get().name());
|
||||
}
|
||||
|
||||
return utils::failure(info.err());
|
||||
}
|
||||
|
||||
}
|
||||
#endif //MATADOR_SCHEMA_HPP
|
||||
Reference in New Issue
Block a user