progress on combining foreign_node_completer and relation_completer

This commit is contained in:
Sascha Kühl
2025-12-05 15:38:35 +01:00
parent 98da0884f1
commit 2e354b435c
20 changed files with 195 additions and 108 deletions
+48 -18
View File
@@ -3,6 +3,7 @@
#include "matador/object/repository.hpp"
#include "../../models/department.hpp"
#include "../../models/recipe.hpp"
struct node {};
@@ -30,50 +31,51 @@ struct names {
};
TEST_CASE("Test empty prototype tree", "[schema_node][empty]") {
const object::repository tree;
const object::repository repo;
REQUIRE( tree.empty() );
REQUIRE( repo.empty() );
}
TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
object::repository tree;
object::repository repo;
REQUIRE( tree.empty() );
REQUIRE( repo.empty() );
auto res = tree.attach<person>("person");
auto res = repo.attach<person>("person");
REQUIRE( res.is_ok() );
res = tree.attach<student, person>("student");
res = repo.attach<student, person>("student");
REQUIRE( res.is_ok() );
res = tree.attach<teacher, person>("teacher");
res = repo.attach<teacher, person>("teacher");
REQUIRE( res.is_ok() );
REQUIRE( !tree.empty() );
REQUIRE( tree.size() == 3 );
REQUIRE( !repo.empty() );
REQUIRE( repo.size() == 3 );
}
TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous]") {
object::repository tree;
object::repository repo;
REQUIRE( tree.empty() );
REQUIRE( repo.empty() );
auto res = tree.attach<person>("person");
auto res = repo.attach<person>("person");
REQUIRE( res.is_ok() );
REQUIRE( tree.size() == 1 );
REQUIRE( repo.size() == 1 );
auto it = tree.begin();
auto it = repo.begin();
REQUIRE( it->name() == "person" );
REQUIRE( (--it)->name() == "person" );
REQUIRE( ++it == tree.end() );
REQUIRE( ++it == repo.end() );
}
TEST_CASE("Test automatic creating of a relation table with foreign key", "[schema][relation_table][foreign_key]") {
object::repository tree;
object::repository repo;
REQUIRE( tree.empty() );
REQUIRE( repo.empty() );
auto res = tree.attach<test::department>("department");
auto res = repo.attach<test::department>("department");
REQUIRE( res.is_ok() );
REQUIRE(repo.size() == 2);
}
TEST_CASE("Test automatic creating of a relation table with values", "[schema][relation_table][values]") {
@@ -83,4 +85,32 @@ TEST_CASE("Test automatic creating of a relation table with values", "[schema][r
auto res = repo.attach<names>("names");
REQUIRE( res.is_ok() );
}
TEST_CASE("Test one to many", "[relation][one-to-many]") {
object::repository repo;
REQUIRE( repo.empty() );
auto res = repo.attach<test::department>("departments")
.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 many to many relation", "[relation][many-to-many]") {
object::repository repo;
REQUIRE(repo.empty());
auto result = repo.attach<test::recipe>("recipes")
.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"));
}