schema creation progress
This commit is contained in:
@@ -14,47 +14,47 @@ using namespace matador;
|
||||
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"*/);
|
||||
using namespace matador::test;
|
||||
orm::schema repo(pool/*, "NoopSchema"*/);
|
||||
|
||||
auto result = repo.attach<department>("departments")
|
||||
.and_then( [&repo] { return repo.attach<employee>("employees"); } );
|
||||
REQUIRE(result);
|
||||
auto result = repo.attach<department>("departments")
|
||||
.and_then([&repo] { return repo.attach<employee>("employees"); });
|
||||
REQUIRE(result);
|
||||
|
||||
result = repo.create();
|
||||
REQUIRE(result);
|
||||
result = repo.create();
|
||||
REQUIRE(result);
|
||||
|
||||
auto exists_result = repo.table_exists("departments");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(exists_result.value());
|
||||
auto exists_result = repo.table_exists("departments");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(exists_result.value());
|
||||
|
||||
result = repo.drop();
|
||||
REQUIRE(result);
|
||||
result = repo.drop();
|
||||
REQUIRE(result);
|
||||
|
||||
exists_result = repo.table_exists("departments");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(!exists_result.value());
|
||||
exists_result = repo.table_exists("departments");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(!exists_result.value());
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SchemaFixture, "Test schema many-to-many", "[schema][many-to-many]") {
|
||||
using namespace matador::test;
|
||||
orm::schema repo(pool/*, "NoopSchema"*/);
|
||||
using namespace matador::test;
|
||||
orm::schema repo(pool/*, "NoopSchema"*/);
|
||||
|
||||
auto result = repo.attach<recipe>("recipes")
|
||||
.and_then( [&repo] { return repo.attach<ingredient>("ingredients"); } );
|
||||
REQUIRE(result);
|
||||
auto result = repo.attach<recipe>("recipes")
|
||||
.and_then([&repo] { return repo.attach<ingredient>("ingredients"); });
|
||||
REQUIRE(result);
|
||||
|
||||
result = repo.create();
|
||||
REQUIRE(result);
|
||||
result = repo.create();
|
||||
REQUIRE(result);
|
||||
|
||||
auto exists_result = repo.table_exists("recipes");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(exists_result.value());
|
||||
auto exists_result = repo.table_exists("recipes");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(exists_result.value());
|
||||
|
||||
result = repo.drop();
|
||||
REQUIRE(result);
|
||||
result = repo.drop();
|
||||
REQUIRE(result);
|
||||
|
||||
exists_result = repo.table_exists("recipes");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(!exists_result.value());
|
||||
}
|
||||
exists_result = repo.table_exists("recipes");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(!exists_result.value());
|
||||
}
|
||||
|
||||
@@ -5,18 +5,24 @@
|
||||
#include "../../models/department.hpp"
|
||||
#include "../../models/recipe.hpp"
|
||||
|
||||
struct node {};
|
||||
struct node {
|
||||
};
|
||||
|
||||
using namespace matador;
|
||||
|
||||
struct person {
|
||||
virtual ~person() = default;
|
||||
template < typename Operator >
|
||||
void process(Operator &/*op*/) {}
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &/*op*/) {
|
||||
}
|
||||
};
|
||||
|
||||
struct student final : person {};
|
||||
struct teacher final : person {};
|
||||
struct student final : person {
|
||||
};
|
||||
|
||||
struct teacher final : person {
|
||||
};
|
||||
|
||||
struct names {
|
||||
unsigned int id{};
|
||||
@@ -33,68 +39,81 @@ struct names {
|
||||
TEST_CASE("Test empty prototype tree", "[schema_node][empty]") {
|
||||
const object::repository repo;
|
||||
|
||||
REQUIRE( repo.empty() );
|
||||
REQUIRE(repo.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( repo.empty() );
|
||||
REQUIRE(repo.empty());
|
||||
|
||||
auto res = repo.attach<person>("person");
|
||||
REQUIRE( res.is_ok() );
|
||||
REQUIRE(res.is_ok());
|
||||
res = repo.attach<student, person>("student");
|
||||
REQUIRE( res.is_ok() );
|
||||
REQUIRE(res.is_ok());
|
||||
res = repo.attach<teacher, person>("teacher");
|
||||
REQUIRE( res.is_ok() );
|
||||
REQUIRE(res.is_ok());
|
||||
|
||||
REQUIRE( !repo.empty() );
|
||||
REQUIRE( repo.size() == 3 );
|
||||
REQUIRE(!repo.empty());
|
||||
REQUIRE(repo.size() == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous]") {
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( repo.empty() );
|
||||
REQUIRE(repo.empty());
|
||||
|
||||
auto res = repo.attach<person>("person");
|
||||
REQUIRE( res.is_ok() );
|
||||
REQUIRE(res.is_ok());
|
||||
|
||||
REQUIRE( repo.size() == 1 );
|
||||
REQUIRE(repo.size() == 1);
|
||||
|
||||
auto it = repo.begin();
|
||||
REQUIRE( it->name() == "person" );
|
||||
REQUIRE( (--it)->name() == "person" );
|
||||
REQUIRE( ++it == repo.end() );
|
||||
REQUIRE(it->name() == "person");
|
||||
REQUIRE((--it)->name() == "person");
|
||||
REQUIRE(++it == repo.end());
|
||||
}
|
||||
|
||||
TEST_CASE("Test automatic creating of a relation table with foreign key", "[schema][relation_table][foreign_key]") {
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( repo.empty() );
|
||||
REQUIRE(repo.empty());
|
||||
|
||||
auto res = repo.attach<test::department>("department");
|
||||
REQUIRE( res.is_ok() );
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(repo.size() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Test automatic creating of a relation table with values", "[schema][relation_table][values]") {
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( repo.empty() );
|
||||
REQUIRE(repo.empty());
|
||||
|
||||
auto res = repo.attach<names>("names");
|
||||
REQUIRE( res.is_ok() );
|
||||
REQUIRE(res.is_ok());
|
||||
}
|
||||
|
||||
TEST_CASE("Test one to many", "[relation][one-to-many]") {
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( repo.empty() );
|
||||
REQUIRE(repo.empty());
|
||||
|
||||
auto res = repo.attach<test::department>("departments")
|
||||
.and_then( [&repo] { return repo.attach<test::employee>("employees"); } );
|
||||
REQUIRE( res.is_ok() );
|
||||
.and_then([&repo] { return repo.attach<test::employee>("employees"); });
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(repo.size() == 2);
|
||||
REQUIRE(repo.contains("departments"));
|
||||
REQUIRE(repo.contains("employees"));
|
||||
}
|
||||
|
||||
TEST_CASE("Test one to many reverse", "[relation][one-to-many][reverse]") {
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE(repo.empty());
|
||||
|
||||
auto res = repo.attach<test::employee>("employees")
|
||||
.and_then([&repo] { return repo.attach<test::department>("departments"); });
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(repo.size() == 2);
|
||||
REQUIRE(repo.contains("departments"));
|
||||
REQUIRE(repo.contains("employees"));
|
||||
@@ -106,11 +125,13 @@ TEST_CASE("Test many to many relation", "[relation][many-to-many]") {
|
||||
REQUIRE(repo.empty());
|
||||
|
||||
auto result = repo.attach<test::recipe>("recipes")
|
||||
.and_then( [&repo] { return repo.attach<test::ingredient>("ingredients"); } );
|
||||
.and_then([&repo] { return repo.attach<test::ingredient>("ingredients"); });
|
||||
REQUIRE(result);
|
||||
|
||||
REQUIRE(repo.size() == 3);
|
||||
REQUIRE(repo.contains("ingredients"));
|
||||
REQUIRE(repo.contains("recipes"));
|
||||
REQUIRE(repo.contains("recipe_ingredients"));
|
||||
}
|
||||
|
||||
auto info = repo.basic_info("ingredients");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user