object generator progress

This commit is contained in:
Sascha Kühl
2025-11-24 16:26:52 +01:00
parent e67c0f39a3
commit ede5a8c636
17 changed files with 329 additions and 134 deletions
+10 -9
View File
@@ -3,22 +3,23 @@ CPMAddPackage("gh:catchorg/Catch2@3.7.1")
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
add_executable(CoreTests
../backends/SchemaFixture.hpp
logger/LoggerTest.cpp
object/AttributeGeneratorTest.cpp
object/ObjectTest.cpp
object/PrimaryKeyResolverTest.cpp
object/SchemaTest.cpp
utils/BasicTypeToVisitorTest.cpp
utils/ConvertTest.cpp
utils/DefaultTypeTraitsTest.cpp
utils/DependencyInjectionTest.cpp
utils/IdentifierTest.cpp
utils/ResultTest.cpp
utils/FieldAttributeTest.cpp
utils/VersionTest.cpp
utils/ThreadPoolTest.cpp
utils/StringTest.cpp
object/AttributeDefinitionGeneratorTest.cpp
object/PrimaryKeyResolverTest.cpp
object/SchemaTest.cpp
utils/IdentifierTest.cpp
utils/MessageBusTest.cpp
../backends/SchemaFixture.hpp
utils/ResultTest.cpp
utils/StringTest.cpp
utils/ThreadPoolTest.cpp
utils/VersionTest.cpp
)
target_link_libraries(CoreTests matador-core Catch2::Catch2WithMain)
@@ -1,6 +1,7 @@
#include <catch2/catch_test_macros.hpp>
#include "matador/object/attribute_generator.hpp"
#include "matador/object/object.hpp"
#include "matador/object/repository.hpp"
#include "../test/models/product.hpp"
@@ -17,7 +18,8 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
.and_then([&repo] { return repo.attach<matador::test::category>("categories"); });
REQUIRE(result);
auto columns = attribute_generator::generate<matador::test::product>(repo);
object obj("products");
auto columns = attribute_generator::generate<matador::test::product>(repo, obj);
const std::vector expected_columns = {
attribute{"product_name", basic_type::type_varchar, constraints::PrimaryKey, null_option_type::NOT_NULL },
@@ -43,7 +45,8 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
TEST_CASE("Generate columns from object with nullable columns", "[column generator]") {
repository repo("main");
auto columns = attribute_generator::generate<matador::test::optional>(repo);
object obj("optionals");
auto columns = attribute_generator::generate<matador::test::optional>(repo, obj);
const std::vector expected_columns = {
attribute{"id", basic_type::type_uint32, constraints::PrimaryKey, null_option_type::NOT_NULL },
+20
View File
@@ -0,0 +1,20 @@
#include <catch2/catch_test_macros.hpp>
#include "matador/object/object.hpp"
#include "matador/object/repository.hpp"
#include "../test/models/author.hpp"
#include "../test/models/book.hpp"
TEST_CASE("Generate object from type", "[object][generate]") {
using namespace matador;
object::repository repo;
auto result = repo.attach<test::author>("authors");
REQUIRE(result);
const auto obj = object::object::generate<test::book>(repo, "books");
REQUIRE(obj->name() == "books");
REQUIRE(obj->alias().empty());
REQUIRE(obj->attributes().size() == 4);
REQUIRE(obj->constraints().size() == 2);
}