progress on query compiler

This commit is contained in:
Sascha Kühl
2026-01-22 16:14:42 +01:00
parent b331ef6923
commit 686b1ddb7a
19 changed files with 241 additions and 175 deletions
+2
View File
@@ -15,5 +15,7 @@ META_TABLE(departments, DEPARTMENT, id, name)
META_TABLE(employees, EMPLOYEE, id, first_name, last_name, dep_id)
META_TABLE(authors, AUTHOR, id, first_name, last_name, date_of_birth, year_of_birth, distinguished)
META_TABLE(books, BOOK, id, title, author_id, published_in)
META_TABLE(orders, ORDER, order_id, order_date, required_date, shipped_date, ship_via, freight, ship_name, ship_address, ship_city, ship_region, ship_postal_code, ship_country)
META_TABLE(courses, COURSE, id, title)
#endif //MATADOR_MODEL_METAS_HPP
+7 -5
View File
@@ -24,12 +24,14 @@
#include "../../models/recipe.hpp"
#include "../../models/order.hpp"
#include "../../models/student.hpp"
#include "../../models/model_metas.hpp"
using namespace matador::object;
using namespace matador::query;
using namespace matador::utils;
using namespace matador::sql;
using namespace matador::test;
using namespace matador::query::meta;
TEST_CASE("Create sql query data for entity with eager has one", "[query][entity][builder]") {
using namespace matador::test;
@@ -46,7 +48,7 @@ TEST_CASE("Create sql query data for entity with eager has one", "[query][entity
const auto it = scm.find(typeid(flight));
REQUIRE(it != scm.end());
const auto* col = it->second.table()["id"];
const auto* col = it->second.table()[FLIGHT.id];
REQUIRE(col);
auto data = eqb.build<flight>(*col == _);
@@ -100,7 +102,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
const auto it = scm.find(typeid(book));
REQUIRE(it != scm.end());
const auto* col = it->second.table()["id"];
const auto* col = it->second.table()[BOOK.id];
REQUIRE(col);
auto data = eqb.build<book>(*col == _);
@@ -172,7 +174,7 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
const auto it = scm.find(typeid(order));
REQUIRE(it != scm.end());
const auto* col = it->second.table()["order_id"];
const auto* col = it->second.table()[ORDER.order_id];
REQUIRE(col);
auto data = eqb.build<order>(*col == _);
@@ -236,7 +238,7 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
const auto it = scm.find(typeid(ingredient));
REQUIRE(it != scm.end());
const auto* col = it->second.table()["id"];
const auto* col = it->second.table()[INGREDIENT.id];
REQUIRE(col);
auto data = eqb.build<ingredient>(*col == _);
@@ -290,7 +292,7 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
const auto it = scm.find(typeid(course));
REQUIRE(it != scm.end());
const auto* col = it->second.table()["id"];
const auto* col = it->second.table()[COURSE.id];
REQUIRE(col);
auto data = eqb.build<course>(*col == _);
+1 -1
View File
@@ -47,7 +47,7 @@ TEST_CASE("Generate columns from object", "[column][generator]") {
REQUIRE(columns.size() == expected_columns.size());
for (size_t i = 0; i != expected_columns.size(); ++i) {
REQUIRE(expected_columns[i] == columns[i].name());
REQUIRE(expected_columns[i] == columns[i].column_name());
}
}
+8 -6
View File
@@ -2,9 +2,9 @@
#include "matador/query/criteria.hpp"
#include "matador/query/criteria_evaluator.hpp"
#include "matador/query/query.hpp"
#include "matador/sql/dialect_builder.hpp"
#include "matador/sql/query_context.hpp"
#include "matador/utils/placeholder.hpp"
@@ -79,7 +79,9 @@ TEST_CASE_METHOD(CriteriaFixture, "Test in query criteria", "[criteria][in query
query_context sub_ctx;
sub_ctx.sql = R"(SELECT "name" FROM "test")";
auto clause = age_col != 7 && in(name_col, std::move(sub_ctx));
auto q = query::select({name_col}).from("test");
auto clause = age_col != 7 && in(name_col, std::move(q));
}
TEST_CASE_METHOD(CriteriaFixture, "Test out criteria", "[criteria][out]") {
const auto age_col = "age"_col;
@@ -88,12 +90,12 @@ TEST_CASE_METHOD(CriteriaFixture, "Test out criteria", "[criteria][out]") {
criteria_evaluator evaluator(dlc, ctx);
auto str = evaluator.evaluate(*clause);
REQUIRE(str == "(\"age\" <> 7 AND \"age\" NOT IN (7, 5, 5, 8))");
REQUIRE(str == R"(("age" <> 7 AND "age" NOT IN (7, 5, 5, 8)))");
clause = age_col != 7 && out(age_col, {_, _, _});
str = evaluator.evaluate(*clause);
REQUIRE(str == "(\"age\" <> 7 AND \"age\" NOT IN (?, ?, ?))");
REQUIRE(str == R"(("age" <> 7 AND "age" NOT IN (?, ?, ?)))");
}
TEST_CASE_METHOD(CriteriaFixture, "Test between criteria", "[criteria][between]") {
@@ -103,12 +105,12 @@ TEST_CASE_METHOD(CriteriaFixture, "Test between criteria", "[criteria][between]"
criteria_evaluator evaluator(dlc, ctx);
auto str = evaluator.evaluate(*clause);
REQUIRE(str == "(\"age\" <> 7 OR \"age\" BETWEEN 21 AND 30)");
REQUIRE(str == R"(("age" <> 7 OR "age" BETWEEN 21 AND 30))");
clause = age_col != 7 || between(age_col, _, _);
str = evaluator.evaluate(*clause);
REQUIRE(str == "(\"age\" <> 7 OR \"age\" BETWEEN ? AND ?)");
REQUIRE(str == R"(("age" <> 7 OR "age" BETWEEN ? AND ?))");
}
TEST_CASE_METHOD(CriteriaFixture, "Test like criteria", "[criteria][like]") {
+1 -1
View File
@@ -7,7 +7,7 @@
using namespace matador::query;
using namespace matador::test;
TEST_CASE("Test schema with belongs-to to has-many relation" "[schema][relation][belongs_to]") {
TEST_CASE("Test schema with belongs-to to has-many relation" "[schema][relation][belongsto]") {
schema repo;
auto result = repo.attach<package>("packages")
.and_then( [&repo] { return repo.attach<shipment>("shipments"); } );