preparations for object_generator (generating objects with attributes and constraints)

This commit is contained in:
2025-11-23 15:58:14 +01:00
parent 19b0adf737
commit e67c0f39a3
23 changed files with 468 additions and 69 deletions
@@ -20,9 +20,9 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
auto columns = attribute_generator::generate<matador::test::product>(repo);
const std::vector expected_columns = {
attribute{"product_name", basic_type::type_varchar, constraints::PRIMARY_KEY, null_option_type::NOT_NULL },
attribute{"supplier_id", basic_type::type_uint32, constraints::FOREIGN_KEY, null_option_type::NOT_NULL },
attribute{"category_id", basic_type::type_uint32, constraints::FOREIGN_KEY, null_option_type::NOT_NULL },
attribute{"product_name", basic_type::type_varchar, constraints::PrimaryKey, null_option_type::NOT_NULL },
attribute{"supplier_id", basic_type::type_uint32, constraints::ForeignKey, null_option_type::NOT_NULL },
attribute{"category_id", basic_type::type_uint32, constraints::ForeignKey, null_option_type::NOT_NULL },
attribute{"quantity_per_unit", basic_type::type_varchar, null_attributes, null_option_type::NOT_NULL },
attribute{"unit_price", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL },
attribute{"units_in_stock", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL },
@@ -46,7 +46,7 @@ TEST_CASE("Generate columns from object with nullable columns", "[column generat
auto columns = attribute_generator::generate<matador::test::optional>(repo);
const std::vector expected_columns = {
attribute{"id", basic_type::type_uint32, constraints::PRIMARY_KEY, null_option_type::NOT_NULL },
attribute{"id", basic_type::type_uint32, constraints::PrimaryKey, null_option_type::NOT_NULL },
attribute{"name", basic_type::type_varchar, null_attributes, null_option_type::NOT_NULL },
attribute{"age", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL }
};
+9 -9
View File
@@ -8,25 +8,25 @@ TEST_CASE("Test field attribute", "[field-attribute]") {
field_attributes attr;
REQUIRE(attr.size() == 0);
REQUIRE(attr.options() == constraints::NONE);
REQUIRE(attr.options() == constraints::None);
attr = 255;
REQUIRE(attr.size() == 255);
REQUIRE(attr.options() == constraints::NONE);
REQUIRE(attr.options() == constraints::None);
attr = constraints::INDEX;
attr = constraints::Index;
REQUIRE(attr.size() == 0);
REQUIRE(attr.options() == constraints::INDEX);
REQUIRE(attr.options() == constraints::Index);
attr = { 255, constraints::DEFAULT };
attr = { 255, constraints::Default };
REQUIRE(attr.size() == 255);
REQUIRE(attr.options() == constraints::DEFAULT);
REQUIRE(attr.options() == constraints::Default);
field_attributes attr2{255};
REQUIRE(attr2.size() == 255);
REQUIRE(attr2.options() == constraints::NONE);
REQUIRE(attr2.options() == constraints::None);
field_attributes attr3{constraints::UNIQUE};
field_attributes attr3{constraints::Unique};
REQUIRE(attr3.size() == 0);
REQUIRE(attr3.options() == constraints::UNIQUE);
REQUIRE(attr3.options() == constraints::Unique);
}