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);
}
+1 -1
View File
@@ -48,7 +48,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
auto ctx = query::create()
.table("person", {
make_pk_column<uint32_t>("id"),
make_column<std::string>("name", {255, constraints::UNIQUE}, null_option_type::NOT_NULL),
make_column<std::string>("name", {255, constraints::Unique}, null_option_type::NOT_NULL),
make_column<unsigned short>("age"),
make_fk_column<uint32_t>("address", "address", "id")
}).compile(*db);
+2 -2
View File
@@ -25,8 +25,8 @@ TEST_CASE("Test copy and move column", "[column]") {
"name",
basic_type::type_varchar,
2,
std::make_shared<attribute>("author", basic_type::type_uint32, "books", attribute_options{constraints::FOREIGN_KEY}),
{255, constraints::FOREIGN_KEY},
std::make_shared<attribute>("author", basic_type::type_uint32, "books", attribute_options{constraints::ForeignKey}),
{255, constraints::ForeignKey},
null_option_type::NOT_NULL
);
REQUIRE(c.name() == "name");
+1 -1
View File
@@ -37,7 +37,7 @@ TEST_CASE("Test field", "[field]") {
REQUIRE(bool_val.has_value());
REQUIRE(bool_val.value());
f = sql::field("name", utils::blob{ 7,8,6,5,4,3 }, utils::constraints::NONE, 0, 1);
f = sql::field("name", utils::blob{ 7,8,6,5,4,3 }, utils::constraints::None, 0, 1);
REQUIRE(f.index() == 1);
REQUIRE(!f.is_null());
REQUIRE(!f.is_integer());