moved schema to query namespace
This commit is contained in:
parent
9eec5b64fb
commit
6307850721
|
|
@ -5,11 +5,13 @@
|
|||
|
||||
#include "matador/sql/query_context.hpp"
|
||||
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
class connection_pool;
|
||||
}
|
||||
|
||||
namespace matador::orm {
|
||||
namespace matador::query {
|
||||
|
||||
class schema;
|
||||
|
||||
|
|
@ -52,11 +54,12 @@ public:
|
|||
[[nodiscard]] utils::result<bool, utils::error> table_exists(const std::string &table_name) const;
|
||||
|
||||
private:
|
||||
sql::query_context build_add_constraint_context( const object::repository_node& node, const class object::restriction& cons ) const;
|
||||
sql::query_context build_drop_constraint_context( const object::repository_node& node, const class object::restriction& cons ) const;
|
||||
[[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_;
|
||||
};
|
||||
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
add_library(matador-orm STATIC
|
||||
../../include/matador/orm/error_code.hpp
|
||||
../../include/matador/orm/schema.hpp
|
||||
../../include/matador/orm/session.hpp
|
||||
../../include/matador/orm/session_query_builder.hpp
|
||||
../../include/matador/query/attribute_string_writer.hpp
|
||||
|
|
@ -58,6 +57,7 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/query/query_intermediates.hpp
|
||||
../../include/matador/query/query_part.hpp
|
||||
../../include/matador/query/query_utils.hpp
|
||||
../../include/matador/query/schema.hpp
|
||||
../../include/matador/query/table.hpp
|
||||
../../include/matador/query/value_extractor.hpp
|
||||
../../include/matador/sql/abstract_sql_logger.hpp
|
||||
|
|
@ -86,7 +86,6 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/sql/statement.hpp
|
||||
orm/error_code.cpp
|
||||
orm/query_builder_exception.cpp
|
||||
orm/schema.cpp
|
||||
orm/session.cpp
|
||||
orm/session_query_builder.cpp
|
||||
query/attribute_string_writer.cpp
|
||||
|
|
@ -139,6 +138,7 @@ add_library(matador-orm STATIC
|
|||
query/query_compiler.cpp
|
||||
query/query_part.cpp
|
||||
query/query_utils.cpp
|
||||
query/schema.cpp
|
||||
query/table.cpp
|
||||
query/value_extractor.cpp
|
||||
sql/backend_provider.cpp
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
#include "matador/orm/schema.hpp"
|
||||
|
||||
#include "matador/orm/error_code.hpp"
|
||||
#include "matador/orm/session.hpp"
|
||||
#include "matador/query/schema.hpp"
|
||||
|
||||
#include "matador/query/query.hpp"
|
||||
|
||||
#include "matador/sql/backend_provider.hpp"
|
||||
#include "matador/sql/connection_pool.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
#include "matador/sql/error_code.hpp"
|
||||
|
||||
namespace matador::orm {
|
||||
namespace matador::query {
|
||||
schema::schema(sql::connection_pool& pool)
|
||||
: repo_(sql::backend_provider::instance().connection_dialect(pool.info().type).default_schema_name())
|
||||
, pool_(pool) {
|
||||
|
|
@ -168,7 +166,7 @@ utils::result<void, utils::error> schema::drop_table(const std::string& table_na
|
|||
utils::result<std::vector<object::attribute>, utils::error> schema::describe_table(const std::string& table_name) const {
|
||||
const auto c = pool_.acquire();
|
||||
if (!c.valid()) {
|
||||
return utils::failure(make_error(error_code::NoConnectionAvailable, "Failed to acquire connection."));
|
||||
return utils::failure(utils::error(sql::error_code::FAILURE, "Failed to acquire connection."));
|
||||
}
|
||||
return utils::ok(c->describe(table_name).release());
|
||||
}
|
||||
|
|
@ -176,12 +174,12 @@ utils::result<std::vector<object::attribute>, utils::error> schema::describe_tab
|
|||
utils::result<bool, utils::error> schema::table_exists(const std::string& table_name) const {
|
||||
const auto c = pool_.acquire();
|
||||
if (!c.valid()) {
|
||||
return utils::failure(make_error(error_code::NoConnectionAvailable, "Failed to acquire connection."));
|
||||
return utils::failure(utils::error(sql::error_code::FAILURE, "Failed to acquire connection."));
|
||||
}
|
||||
return c->exists(repo_.name(), table_name);
|
||||
}
|
||||
|
||||
sql::query_context schema::build_add_constraint_context( const object::repository_node& node, const class object::restriction& cons ) const {
|
||||
sql::query_context schema::build_add_constraint_context( const object::repository_node& node, const object::restriction& cons ) const {
|
||||
if (cons.is_foreign_key_constraint()) {
|
||||
return query::query::alter()
|
||||
.table(node.name())
|
||||
|
|
@ -197,7 +195,7 @@ sql::query_context schema::build_add_constraint_context( const object::repositor
|
|||
return {};
|
||||
}
|
||||
|
||||
sql::query_context schema::build_drop_constraint_context( const object::repository_node& node, const class object::restriction& cons ) const {
|
||||
sql::query_context schema::build_drop_constraint_context( const object::repository_node& node, const object::restriction& cons ) const {
|
||||
return query::query::alter()
|
||||
.table(node.name())
|
||||
.drop_constraint(cons)
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
#include "matador/sql/backend_provider.hpp"
|
||||
#include "matador/sql/connection_pool.hpp"
|
||||
|
||||
#include "matador/orm/schema.hpp"
|
||||
#include "matador/query/schema.hpp"
|
||||
|
||||
#include "../models/department.hpp"
|
||||
#include "../models/recipe.hpp"
|
||||
|
|
@ -15,7 +15,7 @@ using namespace matador::test;
|
|||
|
||||
TEST_CASE_METHOD(SchemaFixture, "Test schema one-two-many", "[schema][one-to-many]") {
|
||||
using namespace matador::test;
|
||||
orm::schema repo(pool/*, "NoopSchema"*/);
|
||||
query::schema repo(pool/*, "NoopSchema"*/);
|
||||
|
||||
auto result = repo.attach<department>("departments")
|
||||
.and_then([&repo] { return repo.attach<employee>("employees"); });
|
||||
|
|
@ -38,7 +38,7 @@ TEST_CASE_METHOD(SchemaFixture, "Test schema one-two-many", "[schema][one-to-man
|
|||
|
||||
TEST_CASE_METHOD(SchemaFixture, "Test schema many-to-many", "[schema][many-to-many]") {
|
||||
using namespace matador::test;
|
||||
orm::schema repo(pool/*, "NoopSchema"*/);
|
||||
query::schema repo(pool/*, "NoopSchema"*/);
|
||||
|
||||
auto result = repo.attach<recipe>("recipes")
|
||||
.and_then([&repo] { return repo.attach<ingredient>("ingredients"); });
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ add_executable(CoreTests
|
|||
logger/LoggerTest.cpp
|
||||
object/ObjectTest.cpp
|
||||
object/PrimaryKeyResolverTest.cpp
|
||||
object/SchemaTest.cpp
|
||||
object/RepositoryTest.cpp
|
||||
utils/BasicTypeToVisitorTest.cpp
|
||||
utils/ConvertTest.cpp
|
||||
utils/DefaultTypeTraitsTest.cpp
|
||||
|
|
|
|||
Loading…
Reference in New Issue