added belongs-to-eager test

This commit is contained in:
2026-01-10 18:54:18 +01:00
parent b9f5819be5
commit db8e137c11
20 changed files with 403 additions and 278 deletions
+10 -9
View File
@@ -6,27 +6,28 @@
#include <string>
namespace matador::test {
struct airplane {
airplane() = default;
airplane(const unsigned int id, std::string b, std::string m)
: id(id)
, brand(std::move(b))
, model(std::move(m)) {}
, brand(std::move(b))
, model(std::move(m)) {
}
unsigned int id{};
std::string brand;
std::string model;
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "brand", brand, 255);
field::attribute(op, "model", model, 255);
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "brand", brand, 255);
field::attribute(op, "model", model, 255);
}
};
}
// namespace matador::access {
+18 -20
View File
@@ -9,31 +9,29 @@
#include <vector>
namespace matador::test {
struct book;
struct author {
unsigned int id{};
std::string first_name;
std::string last_name;
std::string date_of_birth;
unsigned short year_of_birth{};
bool distinguished{false};
std::vector<object::object_ptr<book>> books;
unsigned int id{};
std::string first_name;
std::string last_name;
std::string date_of_birth;
unsigned short year_of_birth{};
bool distinguished{false};
std::vector<object::object_ptr<book> > books;
template<typename Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "first_name", first_name, 63);
field::attribute(op, "last_name", last_name, 63);
field::attribute(op, "date_of_birth", date_of_birth, 31);
field::attribute(op, "year_of_birth", year_of_birth);
field::attribute(op, "distinguished", distinguished);
field::has_many(op, "books", books, "author_id", utils::fetch_type::Lazy);
}
template<typename Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "first_name", first_name, 63);
field::attribute(op, "last_name", last_name, 63);
field::attribute(op, "date_of_birth", date_of_birth, 31);
field::attribute(op, "year_of_birth", year_of_birth);
field::attribute(op, "distinguished", distinguished);
field::has_many(op, "books", books, "author_id", utils::CascadeAllFetchLazy);
}
};
}
#endif //QUERY_AUTHOR_HPP
+12 -14
View File
@@ -9,24 +9,22 @@
#include <string>
namespace matador::test {
struct author;
struct book {
unsigned int id{};
std::string title;
object::object_ptr<author> book_author;
unsigned short published_in{};
unsigned int id{};
std::string title;
object::object_ptr<author> book_author;
unsigned short published_in{};
template<typename Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "title", title, 511);
field::belongs_to(op, "author_id", book_author, utils::fetch_type::Eager);
field::attribute(op, "published_in", published_in);
}
template<typename Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "title", title, 511);
field::belongs_to(op, "author_id", book_author, utils::CascadeAllFetchEager);
field::attribute(op, "published_in", published_in);
}
};
}
#endif //QUERY_BOOK_HPP
+9 -11
View File
@@ -6,19 +6,17 @@
#include <string>
namespace matador::test {
struct category {
unsigned int id{};
std::string name;
unsigned int id{};
std::string name;
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
}
};
}
#endif //QUERY_CATEGORY_HPP
+1 -5
View File
@@ -5,24 +5,20 @@
#include "matador/utils/field_attributes.hpp"
namespace matador::test {
struct coordinate
{
struct coordinate {
int x{};
int y{};
int z{};
};
}
namespace matador::access {
template<class Operator>
void attribute(Operator &op, const char *id, test::coordinate &value, const utils::field_attributes &attr = utils::null_attributes) {
attribute(op, (std::string(id) + "_x").c_str(), value.x, attr);
attribute(op, (std::string(id) + "_y").c_str(), value.y, attr);
attribute(op, (std::string(id) + "_z").c_str(), value.z, attr);
}
}
#endif //QUERY_COORDINATE_HPP
+1 -1
View File
@@ -13,7 +13,7 @@ struct employee;
struct department {
unsigned int id{};
std::string name;
std::vector<object::object_ptr<employee>> employees;
std::vector<object::object_ptr<employee>> employees{};
// object::object_ptr<employee> manager;
template<typename Operator>
+3 -3
View File
@@ -13,11 +13,12 @@
#include <utility>
namespace matador::test {
struct flight {
flight() = default;
flight(const unsigned int id, const object::object_ptr<airplane> &plane, std::string name)
: id(id), plane(plane), pilot_name(std::move(name)) {}
: id(id), plane(plane), pilot_name(std::move(name)) {
}
unsigned int id{};
object::object_ptr<airplane> plane;
@@ -32,7 +33,6 @@ struct flight {
field::attribute(op, "pilot_name", pilot_name, 255);
}
};
}
#endif //QUERY_FLIGHT_HPP
+3 -7
View File
@@ -8,21 +8,18 @@
#include <cstdint>
namespace matador::test {
enum class Color : uint8_t {
Green, Red, Blue, Yellow, Black, White, Brown
};
struct location
{
struct location {
unsigned int id{};
std::string name;
coordinate coord;
Color color{Color::Green};
template < class Operator >
void process(Operator &op)
{
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
@@ -30,7 +27,6 @@ struct location
field::attribute(op, "color", color);
}
};
}
#endif //QUERY_LOCATION_HPP
+4
View File
@@ -11,5 +11,9 @@ META_TABLE(flights, FLIGHT, id, airplane_id, pilot_name);
META_TABLE(shipments, SHIPMENT, id, tracking_number)
META_TABLE(packages, PACKAGE, id, weight, shipment_id)
META_TABLE(persons, PERSON, id, name, age, image)
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)
#endif //MATADOR_MODEL_METAS_HPP
+12 -15
View File
@@ -8,23 +8,20 @@
#include <string>
namespace matador::test {
struct optional {
unsigned int id{};
std::optional<std::string> name;
std::optional<unsigned int> age{};
struct optional
{
unsigned int id{};
std::optional<std::string> name;
std::optional<unsigned int> age{};
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::attribute(op, "age", age);
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::attribute(op, "age", age);
}
};
}
#endif //QUERY_OPTIONAL_HPP
+31 -34
View File
@@ -10,41 +10,38 @@
#include <vector>
namespace matador::test {
struct order {
unsigned int order_id{};
std::string order_date;
std::string required_date;
std::string shipped_date;
unsigned int ship_via{};
unsigned int freight{};
std::string ship_name;
std::string ship_address;
std::string ship_city;
std::string ship_region;
std::string ship_postal_code;
std::string ship_country;
std::vector<object::object_ptr<order_details> > order_details_;
struct order
{
unsigned int order_id{};
std::string order_date;
std::string required_date;
std::string shipped_date;
unsigned int ship_via{};
unsigned int freight{};
std::string ship_name;
std::string ship_address;
std::string ship_city;
std::string ship_region;
std::string ship_postal_code;
std::string ship_country;
std::vector<object::object_ptr<order_details>> order_details_;
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "order_id", order_id);
field::attribute(op, "order_date", order_date, 255);
field::attribute(op, "required_date", required_date, 255);
field::attribute(op, "shipped_date", shipped_date, 255);
field::attribute(op, "ship_via", ship_via);
field::attribute(op, "freight", freight);
field::attribute(op, "ship_name", ship_name, 255);
field::attribute(op, "ship_address", ship_address, 255);
field::attribute(op, "ship_city", ship_city, 255);
field::attribute(op, "ship_region", ship_region, 255);
field::attribute(op, "ship_postal_code", ship_postal_code, 255);
field::attribute(op, "ship_country", ship_country, 255);
field::has_many(op, "order_details", order_details_, "order_id", utils::fetch_type::Eager);
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "order_id", order_id);
field::attribute(op, "order_date", order_date, 255);
field::attribute(op, "required_date", required_date, 255);
field::attribute(op, "shipped_date", shipped_date, 255);
field::attribute(op, "ship_via", ship_via);
field::attribute(op, "freight", freight);
field::attribute(op, "ship_name", ship_name, 255);
field::attribute(op, "ship_address", ship_address, 255);
field::attribute(op, "ship_city", ship_city, 255);
field::attribute(op, "ship_region", ship_region, 255);
field::attribute(op, "ship_postal_code", ship_postal_code, 255);
field::attribute(op, "ship_country", ship_country, 255);
field::has_many(op, "order_details", order_details_, "order_id", utils::fetch_type::Eager);
}
};
}
#endif //QUERY_ORDER_HPP
+11 -14
View File
@@ -8,23 +8,20 @@
#include "matador/utils/foreign_attributes.hpp"
namespace matador::test {
struct order;
struct order_details
{
unsigned int order_details_id;
matador::object::object_ptr<order> order_;
matador::object::object_ptr<product> product_;
struct order_details {
unsigned int order_details_id;
object::object_ptr<order> order_;
object::object_ptr<product> product_;
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "order_details_id", order_details_id);
field::belongs_to(op, "order_id", order_, utils::CascadeNoneFetchLazy);
field::has_one(op, "product_id", product_, utils::CascadeNoneFetchLazy);
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "order_details_id", order_details_id);
field::belongs_to(op, "order_id", order_, utils::CascadeNoneFetchLazy);
field::has_one(op, "product_id", product_, utils::CascadeNoneFetchLazy);
}
};
}
#endif //QUERY_ORDER_DETAILS_HPP
+13 -15
View File
@@ -8,23 +8,21 @@
#include <string>
namespace matador::test {
struct person {
unsigned int id{};
std::string name;
unsigned int age{};
utils::blob_type_t image{};
unsigned int id{};
std::string name;
unsigned int age{};
utils::blob_type_t image{};
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::attribute(op, "age", age);
field::attribute(op, "image", image);
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::attribute(op, "age", age);
field::attribute(op, "image", image);
}
};
}
#endif //QUERY_PERSON_HPP
+23 -25
View File
@@ -6,39 +6,37 @@
#include "matador/utils/access.hpp"
#include "matador/utils/cascade_type.hpp"
#include "matador/utils/field_attributes.hpp"
#include "matador/object/object_ptr.hpp"
#include <string>
namespace matador::test {
struct product {
std::string product_name;
object::object_ptr<test::supplier> supplier;
object::object_ptr<test::category> category;
std::string quantity_per_unit;
unsigned int unit_price;
unsigned int units_in_stock;
unsigned int units_in_order;
unsigned int reorder_level;
bool discontinued;
std::string product_name;
object::object_ptr<supplier> supplier;
object::object_ptr<category> category;
std::string quantity_per_unit;
unsigned int unit_price;
unsigned int units_in_stock;
unsigned int units_in_order;
unsigned int reorder_level;
bool discontinued;
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "product_name", product_name, 255);
field::belongs_to(op, "supplier_id", supplier, utils::cascade_type::ALL);
field::belongs_to(op, "category_id", category, utils::cascade_type::ALL);
field::attribute(op, "quantity_per_unit", quantity_per_unit, 255);
field::attribute(op, "unit_price", unit_price);
field::attribute(op, "units_in_stock", units_in_stock);
field::attribute(op, "units_in_order", units_in_order);
field::attribute(op, "reorder_level", reorder_level);
field::attribute(op, "discontinued", discontinued);
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "product_name", product_name, 255);
field::belongs_to(op, "supplier_id", supplier, CascadeAllFetchLazy);
field::belongs_to(op, "category_id", category, CascadeAllFetchLazy);
field::attribute(op, "quantity_per_unit", quantity_per_unit, 255);
field::attribute(op, "unit_price", unit_price);
field::attribute(op, "units_in_stock", units_in_stock);
field::attribute(op, "units_in_order", units_in_order);
field::attribute(op, "reorder_level", reorder_level);
field::attribute(op, "discontinued", discontinued);
}
};
}
+16 -15
View File
@@ -10,51 +10,52 @@
#include <string>
namespace matador::test {
struct recipe;
struct ingredient
{
struct ingredient {
unsigned int id{};
std::string name;
std::vector<object::object_ptr<recipe>> recipes{};
std::vector<object::object_ptr<recipe> > recipes{};
ingredient() = default;
ingredient()= default;
ingredient(const unsigned int id, std::string name)
: id(id), name(std::move(name)) {}
: id(id), name(std::move(name)) {
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::fetch_type::Eager);
field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::CascadeAllFetchEager);
}
};
struct recipe
{
struct recipe {
unsigned int id{};
std::string name;
std::vector<object::object_ptr<ingredient>> ingredients{};
std::vector<object::object_ptr<ingredient> > ingredients{};
recipe() = default;
recipe()= default;
recipe(const unsigned int id, std::string name)
: id(id), name(std::move(name)) {}
: id(id), name(std::move(name)) {
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::fetch_type::Lazy);
field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::CascadeAllFetchLazy);
}
};
// class recipe_ingredient : public object::many_to_many_relation<recipe, ingredient> {
// public:
// recipe_ingredient() : many_to_many_relation("recipe_id", "ingredient_id") {}
// recipe_ingredient() : many_to_many_relation("recipe_id", "ingredient_id") {}
// };
}
#endif //QUERY_RECIPE_HPP
+2 -1
View File
@@ -11,10 +11,11 @@
namespace matador::test {
struct package;
struct shipment {
long id{};
std::string tracking_number;
object::collection<object::object_ptr<package>> packages{};
object::collection<object::object_ptr<package> > packages{};
template<typename Operator>
void process(Operator &op) {
+33 -31
View File
@@ -11,52 +11,54 @@
#include <vector>
namespace matador::test {
struct course;
struct student {
unsigned int id{};
std::string name;
std::vector<object::object_ptr<course>> courses;
unsigned int id{};
std::string name;
std::vector<object::object_ptr<course> > courses;
student() = default;
explicit student(unsigned int id, std::string name)
: id(id)
, name(std::move(name)) {}
student() = default;
template < class Operator >
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "student_courses", courses, "student_id", "course_id", utils::fetch_type::Lazy);
}
explicit student(unsigned int id, std::string name)
: id(id)
, name(std::move(name)) {
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "student_courses", courses, "student_id", "course_id", utils::CascadeAllFetchLazy);
}
};
struct course {
unsigned int id{};
std::string title;
std::vector<object::object_ptr<student>> students;
unsigned int id{};
std::string title;
std::vector<object::object_ptr<student> > students;
course() = default;
explicit course(unsigned int id, std::string title)
: id(id)
, title(std::move(title)) {}
course() = default;
template < class Operator >
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "title", title, 255);
field::has_many_to_many(op, "student_courses", students, utils::fetch_type::Eager);
}
explicit course(unsigned int id, std::string title)
: id(id)
, title(std::move(title)) {
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "title", title, 255);
field::has_many_to_many(op, "student_courses", students, utils::CascadeAllFetchEager);
}
};
class student_course : public object::many_to_many_relation<student, course> {
public:
student_course() : many_to_many_relation("student_id", "course_id") {}
student_course() : many_to_many_relation("student_id", "course_id") {
}
};
}
#endif //QUERY_STUDENT_HPP
+9 -11
View File
@@ -6,19 +6,17 @@
#include <string>
namespace matador::test {
struct supplier {
unsigned int id{};
std::string name;
unsigned int id{};
std::string name;
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
}
};
}
#endif //QUERY_SUPPLIER_HPP
+43 -47
View File
@@ -5,56 +5,52 @@
#include "matador/utils/types.hpp"
namespace matador::test {
struct types {
// enum { CSTR_LEN=255 };
struct types
{
// enum { CSTR_LEN=255 };
unsigned int id_ = 0;
int8_t char_ = 'c';
short short_ = -127;
int int_ = -65000;
int64_t long64_ = -1234567890;
unsigned char unsigned_char_ = 'H';
unsigned short unsigned_short_ = 128;
unsigned int unsigned_int_ = 65000;
uint64_t unsigned_long64_ = 1234567890;
float float_ = 3.1415f;
double double_ = 1.1414;
bool bool_ = true;
// char cstr_[CSTR_LEN]{};
std::string string_ = "Welt";
std::string varchar_ = "Erde";
// matador::date date_;
// matador::time time_;
utils::blob_type_t binary_{1, 2, 3, 4};
unsigned int id_ = 0;
int8_t char_ = 'c';
short short_ = -127;
int int_ = -65000;
int64_t long64_ = -1234567890;
unsigned char unsigned_char_ = 'H';
unsigned short unsigned_short_ = 128;
unsigned int unsigned_int_ = 65000;
uint64_t unsigned_long64_ = 1234567890;
float float_ = 3.1415f;
double double_ = 1.1414;
bool bool_ = true;
// char cstr_[CSTR_LEN]{};
std::string string_ = "Welt";
std::string varchar_ = "Erde";
// matador::date date_;
// matador::time time_;
utils::blob_type_t binary_{ 1, 2, 3, 4 };
template < class Operator >
void process(Operator &op)
{
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id_);
field::attribute(op, "val_char", char_);
field::attribute(op, "val_float", float_);
field::attribute(op, "val_double", double_);
field::attribute(op, "val_short", short_);
field::attribute(op, "val_int", int_);
field::attribute(op, "val_long_long", long64_);
field::attribute(op, "val_unsigned_char", unsigned_char_);
field::attribute(op, "val_unsigned_short", unsigned_short_);
field::attribute(op, "val_unsigned_int", unsigned_int_);
field::attribute(op, "val_unsigned_long_long", unsigned_long64_);
field::attribute(op, "val_bool", bool_);
// field::attribute(op, "val_cstr", cstr_, CSTR_LEN);
field::attribute(op, "val_string", string_);
field::attribute(op, "val_varchar", varchar_, 63);
// field::attribute(op, "val_date", date_);
// field::attribute(op, "val_time", time_);
field::attribute(op, "val_binary", binary_);
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id_);
field::attribute(op, "val_char", char_);
field::attribute(op, "val_float", float_);
field::attribute(op, "val_double", double_);
field::attribute(op, "val_short", short_);
field::attribute(op, "val_int", int_);
field::attribute(op, "val_long_long", long64_);
field::attribute(op, "val_unsigned_char", unsigned_char_);
field::attribute(op, "val_unsigned_short", unsigned_short_);
field::attribute(op, "val_unsigned_int", unsigned_int_);
field::attribute(op, "val_unsigned_long_long", unsigned_long64_);
field::attribute(op, "val_bool", bool_);
// field::attribute(op, "val_cstr", cstr_, CSTR_LEN);
field::attribute(op, "val_string", string_);
field::attribute(op, "val_varchar", varchar_, 63);
// field::attribute(op, "val_date", date_);
// field::attribute(op, "val_time", time_);
field::attribute(op, "val_binary", binary_);
}
};
}
#endif // QUERY_TYPES_HPP