renamed column to table_column and constraint to table_constraint.

This commit is contained in:
2025-12-31 13:01:54 +01:00
parent ab2d39407c
commit b9d35cbd4e
62 changed files with 424 additions and 423 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
#include "matador/query/builder.hpp"
#include "matador/query/criteria.hpp"
#include "matador/query/query.hpp"
#include "matador/query/column.hpp"
#include "matador/query/table_column.hpp"
#include "matador/utils/types.hpp"
#include "matador/utils/string.hpp"
+1 -1
View File
@@ -4,7 +4,7 @@
#include "matador/query/criteria.hpp"
#include "matador/query/query.hpp"
#include "matador/query/column.hpp"
#include "matador/query/table_column.hpp"
#include "models/person.hpp"
+25 -21
View File
@@ -156,7 +156,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
.and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok());
auto obj = object_generator::generate<airplane>(repo, "airplane");
auto obj = object_generator::generate<airplane>(repo.repo(), "airplane");
auto res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -168,7 +168,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
REQUIRE(db.exists("airplane"));
tables_to_drop.emplace("airplane");
obj = object_generator::generate<flight>(repo, "flight");
obj = object_generator::generate<flight>(repo.repo(), "flight");
res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -225,7 +225,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
.and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok());
auto obj = object_generator::generate<airplane>(repo, "airplane");
auto obj = object_generator::generate<airplane>(repo.repo(), "airplane");
auto res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -237,7 +237,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
REQUIRE(db.exists("airplane"));
tables_to_drop.emplace("airplane");
obj = object_generator::generate<flight>(repo, "flight");
obj = object_generator::generate<flight>(repo.repo(), "flight");
res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -295,8 +295,8 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
REQUIRE(f.value()->at(2).as<std::string>() == "hans");
auto select_result = query::select({"f.id", "ap.brand", "ap.model", "f.pilot_name"})
.from({"flight", "f"})
.join_left({"airplane", "ap"})
.from("flight"_tab.as("f"))
.join_left("airplane"_tab.as("ap"))
.on("f.airplane_id"_col == "ap.id"_col)
.order_by("f.id").asc()
.fetch_all(db);
@@ -321,7 +321,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
.and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok());
auto obj = object_generator::generate<airplane>(repo, "airplane");
auto obj = object_generator::generate<airplane>(repo.repo(), "airplane");
auto res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -333,7 +333,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
REQUIRE(db.exists("airplane"));
tables_to_drop.emplace("airplane");
obj = object_generator::generate<flight>(repo, "flight");
obj = object_generator::generate<flight>(repo.repo(), "flight");
res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -393,8 +393,8 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
REQUIRE(f.value()->at(2).as<std::string>() == "hans");
auto select_result = query::select({"f.id", "f.airplane_id", "ap.brand", "ap.model", "f.pilot_name"})
.from({"flight", "f"})
.join_left({"airplane", "ap"})
.from("flight"_tab.as("f"))
.join_left("airplane"_tab.as("ap"))
.on("f.airplane_id"_col == "ap.id"_col)
.where("f.id"_col == 4)
.fetch_one<flight>(db);
@@ -416,7 +416,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
auto result = repo.attach<recipe>("recipes")
.and_then( [this] { return repo.attach<ingredient>("ingredients"); } );
auto obj = object_generator::generate<recipe>(repo, "recipes");
auto obj = object_generator::generate<recipe>(repo.repo(), "recipes");
auto res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -428,7 +428,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
REQUIRE(db.exists("recipes"));
tables_to_drop.emplace("recipes");
obj = object_generator::generate<ingredient>(repo, "ingredients");
obj = object_generator::generate<ingredient>(repo.repo(), "ingredients");
res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -440,7 +440,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
REQUIRE(db.exists("ingredients"));
tables_to_drop.emplace("ingredients");
obj = object_generator::generate<recipe_ingredient>(repo, "recipe_ingredients");
obj = object_generator::generate<recipe_ingredient>(repo.repo(), "recipe_ingredients");
res = query::create()
.table(obj->name())
.columns(obj->attributes())
@@ -507,8 +507,8 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
}
auto select_result = query::select({"r.id", "r.name", "ri.ingredient_id"})
.from({"recipes", "r"})
.join_left({"recipe_ingredients", "ri"})
.from("recipes"_tab.as("r"))
.join_left("recipe_ingredients"_tab.as("ri"))
.on("r.id"_col == "ri.recipe_id"_col)
.fetch_all(db);
REQUIRE(select_result.is_ok());
@@ -533,9 +533,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
}
select_result = query::select({"r.id", "r.name", "ri.ingredient_id", "i.name"})
.from({"recipes", "r"})
.join_left({"recipe_ingredients", "ri"}).on("r.id"_col == "ri.recipe_id"_col)
.join_left({"ingredients", "i"}).on("ri.ingredient_id"_col == "i.id"_col)
.from("recipes"_tab.as("r"))
.join_left("recipe_ingredients"_tab.as("ri"))
.on("r.id"_col == "ri.recipe_id"_col)
.join_left("ingredients"_tab.as("i"))
.on("ri.ingredient_id"_col == "i.id"_col)
.fetch_all(db);
REQUIRE(result.is_ok());
@@ -560,9 +562,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
}
select_result = query::select({"r.id", "r.name", "ri.ingredient_id", "i.name"})
.from({"recipes", "r"})
.join_left({"recipe_ingredients", "ri"}).on("r.id"_col == "ri.recipe_id"_col)
.join_left({"ingredients", "i"}).on("ri.ingredient_id"_col == "i.id"_col)
.from("recipes"_tab.as("r"))
.join_left("recipe_ingredients"_tab.as("ri"))
.on("r.id"_col == "ri.recipe_id"_col)
.join_left("ingredients"_tab.as("i"))
.on("ri.ingredient_id"_col == "i.id"_col)
.where("r.id"_col == 8)
.fetch_all(db);
REQUIRE(result.is_ok());
+10 -10
View File
@@ -8,7 +8,7 @@
#include "matador/query/criteria_evaluator.hpp"
#include "matador/query/query.hpp"
#include "matador/query/column.hpp"
#include "matador/query/table_column.hpp"
#include "matador/query/table.hpp"
#include "matador/query/schema.hpp"
@@ -59,9 +59,9 @@ public:
, author_id(*column_by_name(*this, "author_id")) {
}
const column& id;
const column& title;
const column& author_id;
const table_column& id;
const table_column& title;
const table_column& author_id;
};
book_table BOOK;
@@ -92,7 +92,7 @@ TEST_CASE("Create sql query data for entity with eager has one", "[query][entity
REQUIRE(data->joins.size() == 1);
const auto flights = table("flights").as("t01");
const auto airplanes = table("airplanes").as("t02");
const std::vector<column> expected_columns {
const std::vector<table_column> expected_columns {
{ &flights, "id", "c01" },
{ &airplanes, "id", "c02" },
{ &airplanes, "brand", "c03" },
@@ -146,7 +146,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
REQUIRE(data->joins.size() == 1);
const auto books = table("books").as("t01");
const auto authors = table("authors").as("t02");
const std::vector<column> expected_columns {
const std::vector<table_column> expected_columns {
{ &books, "id", "c01" },
{ &books, "title", "c02" },
{ &authors, "id", "c03" },
@@ -218,7 +218,7 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
REQUIRE(data->joins.size() == 1);
const auto orders = table("orders").as("t01");
const auto order_details = table("order_details").as("t02");
const std::vector<column> expected_columns = {
const std::vector<table_column> expected_columns = {
{ &orders, "order_id", "c01" },
{ &orders, "order_date", "c02" },
{ &orders, "required_date", "c03" },
@@ -282,7 +282,7 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
REQUIRE(data->joins.size() == 2);
const auto ingredients = table("ingredients").as("t01");
const auto recipes = table("recipes").as("t03");
const std::vector<column> expected_columns {
const std::vector<table_column> expected_columns {
{ &ingredients, "id", "c01" },
{ &ingredients, "name", "c02" },
{ &recipes, "id", "c03" },
@@ -336,7 +336,7 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
REQUIRE(data->joins.size() == 2);
const auto courses = table("courses").as("t01");
const auto students = table("students").as("t03");
const std::vector<column> expected_columns {
const std::vector<table_column> expected_columns {
{ &courses, "id", "c01" },
{ &courses, "title", "c02" },
{ &students, "id", "c03" },
@@ -386,7 +386,7 @@ TEST_CASE("Test eager relationship", "[session][eager]") {
.from(*data->root_table)
.join_left(data->joins)
.where(std::move(data->where_clause))
.order_by(column{data->root_table, data->pk_column_name})
.order_by(table_column{data->root_table, data->pk_column_name})
.asc()
.str(db);
+1 -1
View File
@@ -1,7 +1,7 @@
#include <catch2/catch_test_macros.hpp>
#include "matador/query/generator.hpp"
#include "matador/query/column.hpp"
#include "matador/query/table_column.hpp"
#include "../../models/airplane.hpp"
#include "../../models/flight.hpp"
+3 -3
View File
@@ -5,7 +5,7 @@
#include <matador/query/criteria.hpp>
#include <matador/query/query.hpp>
#include "matador/query/table.hpp"
#include "matador/query/column.hpp"
#include "matador/query/table_column.hpp"
#include "matador/query/builder.hpp"
#include "matador/sql/connection.hpp"
@@ -249,8 +249,8 @@ TEST_CASE_METHOD(QueryFixture, "Test create, insert and select a blob column", "
TEST_CASE_METHOD(QueryFixture, "Test select statement with join_left", "[query][statement][join_left]") {
const auto ap = table("airplane").as("ap");
const auto f = table("flight").as("f");
const class matador::query::column col1 = {&f, "airplane_id"};
const class matador::query::column col2 = {&ap, "id"};
const class matador::query::table_column col1 = {&f, "airplane_id"};
const class matador::query::table_column col2 = {&ap, "id"};
const auto result = query::select({"f.id", "ap.brand", "f.pilot_name"})
.from(table{"flight"}.as("f"))
.join_left(table{"airplane"}.as("ap"))
+2 -2
View File
@@ -68,7 +68,7 @@ TEST_CASE("Generate columns for object with has many relation", "[column][genera
const auto order_table = table("order");
const auto order_details_table = table("order_details");
const std::vector<column> expected_columns = {
const std::vector<table_column> expected_columns = {
{ &order_table, "order_id", "c01" },
{ &order_table, "order_date", "c02" },
{ &order_table, "required_date", "c03" },
@@ -106,7 +106,7 @@ TEST_CASE("Generate columns for object with eager foreign key relation", "[colum
const auto books_table = table("books");
const auto authors_table = table("authors");
const std::vector<column> expected_columns {
const std::vector<table_column> expected_columns {
{ &books_table, "id", "c01" },
{ &books_table, "title", "c02" },
{ &authors_table, "id", "c03" },