some column interface refactorings

This commit is contained in:
Sascha Kühl
2025-12-08 16:27:00 +01:00
parent 3b0b9615ca
commit 263c202c69
14 changed files with 126 additions and 125 deletions
+47 -37
View File
@@ -46,12 +46,14 @@ TEST_CASE("Create sql query data for entity with eager has one", "[query][entity
REQUIRE(data.is_ok());
REQUIRE(data->root_table->name() == "flights");
REQUIRE(data->joins.size() == 1);
const auto flights = std::make_shared<table>("flights");
const auto airplanes = std::make_shared<table>("airplanes");
const std::vector<column> expected_columns {
{ "flights", "id", "c01" },
{ "airplanes", "id", "c02" },
{ "airplanes", "brand", "c03" },
{ "airplanes", "model", "c04" },
{ "flights", "pilot_name", "c05" },
{ flights, "id", "c01" },
{ airplanes, "id", "c02" },
{ airplanes, "brand", "c03" },
{ airplanes, "model", "c04" },
{ flights, "pilot_name", "c05" },
};
REQUIRE(data->columns.size() == expected_columns.size());
for (size_t i = 0; i != expected_columns.size(); ++i) {
@@ -92,16 +94,18 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
REQUIRE(data.is_ok());
REQUIRE(data->root_table->name() == "books");
REQUIRE(data->joins.size() == 1);
const auto books = std::make_shared<table>("books");
const auto authors = std::make_shared<table>("authors");
const std::vector<column> expected_columns {
{ "books", "id", "c01" },
{ "books", "title", "c02" },
{ "authors", "id", "c03" },
{ "authors", "first_name", "c04" },
{ "authors", "last_name", "c05" },
{ "authors", "date_of_birth", "c06" },
{ "authors", "year_of_birth", "c07" },
{ "authors", "distinguished", "c08" },
{ "books", "published_in", "c09" }
{ books, "id", "c01" },
{ books, "title", "c02" },
{ authors, "id", "c03" },
{ authors, "first_name", "c04" },
{ authors, "last_name", "c05" },
{ authors, "date_of_birth", "c06" },
{ authors, "year_of_birth", "c07" },
{ authors, "distinguished", "c08" },
{ books, "published_in", "c09" }
};
REQUIRE(data->columns.size() == expected_columns.size());
for (size_t i = 0; i != expected_columns.size(); ++i) {
@@ -156,22 +160,24 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
REQUIRE(data.is_ok());
REQUIRE(data->root_table->name() == "orders");
REQUIRE(data->joins.size() == 1);
const auto orders = std::make_shared<table>("orders");
const auto order_details = std::make_shared<table>("order_details");
const std::vector<column> expected_columns = {
{ "orders", "order_id", "c01" },
{ "orders", "order_date", "c02" },
{ "orders", "required_date", "c03" },
{ "orders", "shipped_date", "c04" },
{ "orders", "ship_via", "c05" },
{ "orders", "freight", "c06" },
{ "orders", "ship_name", "c07" },
{ "orders", "ship_address", "c08" },
{ "orders", "ship_city", "c09" },
{ "orders", "ship_region", "c10" },
{ "orders", "ship_postal_code", "c11" },
{ "orders", "ship_country", "c12" },
{ "order_details", "order_details_id", "c13" },
{ "order_details", "order_id", "c14" },
{ "order_details", "product_id", "c15" }
{ orders, "order_id", "c01" },
{ orders, "order_date", "c02" },
{ orders, "required_date", "c03" },
{ orders, "shipped_date", "c04" },
{ orders, "ship_via", "c05" },
{ orders, "freight", "c06" },
{ orders, "ship_name", "c07" },
{ orders, "ship_address", "c08" },
{ orders, "ship_city", "c09" },
{ orders, "ship_region", "c10" },
{ orders, "ship_postal_code", "c11" },
{ orders, "ship_country", "c12" },
{ order_details, "order_details_id", "c13" },
{ order_details, "order_id", "c14" },
{ order_details, "product_id", "c15" }
};
REQUIRE(data->columns.size() == expected_columns.size());
for (size_t i = 0; i != expected_columns.size(); ++i) {
@@ -212,11 +218,13 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
REQUIRE(data.is_ok());
REQUIRE(data->root_table->name() == "ingredients");
REQUIRE(data->joins.size() == 2);
const auto ingredients = std::make_shared<table>("ingredients");
const auto recipes = std::make_shared<table>("recipes");
const std::vector<column> expected_columns {
{ "ingredients", "id", "c01" },
{ "ingredients", "name", "c02" },
{ "recipes", "id", "c03" },
{ "recipes", "name", "c04" }
{ ingredients, "id", "c01" },
{ ingredients, "name", "c02" },
{ recipes, "id", "c03" },
{ recipes, "name", "c04" }
};
REQUIRE(data->columns.size() == expected_columns.size());
for (size_t i = 0; i != expected_columns.size(); ++i) {
@@ -258,11 +266,13 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
REQUIRE(data.is_ok());
REQUIRE(data->root_table->name() == "courses");
REQUIRE(data->joins.size() == 2);
const auto courses = std::make_shared<table>("courses");
const auto students = std::make_shared<table>("students");
const std::vector<column> expected_columns {
{ "courses", "id", "c01" },
{ "courses", "title", "c02" },
{ "students", "id", "c03" },
{ "students", "name", "c04" }
{ courses, "id", "c01" },
{ courses, "title", "c02" },
{ students, "id", "c03" },
{ students, "name", "c04" }
};
REQUIRE(data->columns.size() == expected_columns.size());
for (size_t i = 0; i != expected_columns.size(); ++i) {