introduced field_attributes shortcuts and added method on_base() to all processor classes
This commit is contained in:
@@ -24,8 +24,8 @@ struct airplane {
|
||||
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);
|
||||
field::attribute(op, "brand", brand, UniqueVarChar255);
|
||||
field::attribute(op, "model", model, UniqueVarChar255);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -36,8 +36,8 @@ struct airplane {
|
||||
// namespace field = matador::access;
|
||||
// using namespace matador::utils;
|
||||
// field::primary_key(op, "id", object.id);
|
||||
// field::attribute(op, "brand", object.brand, 255);
|
||||
// field::attribute(op, "model", object.model, 255);
|
||||
// field::attribute(op, "brand", object.brand, UniqueVarChar255);
|
||||
// field::attribute(op, "model", object.model, UniqueVarChar255);
|
||||
// }
|
||||
// template<class Operator>
|
||||
// void process(Operator &op, const matador::test::airplane &object) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define QUERY_AUTHOR_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include "matador/object/object_ptr.hpp"
|
||||
#include "matador/object/collection.hpp"
|
||||
@@ -32,9 +33,9 @@ struct author {
|
||||
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, "first_name", first_name, VarChar63);
|
||||
field::attribute(op, "last_name", last_name, VarChar63);
|
||||
field::attribute(op, "date_of_birth", date_of_birth, VarChar63);
|
||||
field::attribute(op, "year_of_birth", year_of_birth);
|
||||
field::attribute(op, "distinguished", distinguished);
|
||||
field::has_many(op, "books", books, "author_id", utils::CascadeAllFetchLazy);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "matador/object/object_ptr.hpp"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
#include <string>
|
||||
@@ -13,7 +14,7 @@ struct author;
|
||||
|
||||
struct book {
|
||||
book() = default;
|
||||
book(const unsigned int id, std::string title, object::object_ptr<author> author, unsigned short published_in)
|
||||
book(const unsigned int id, std::string title, object::object_ptr<author> author, const unsigned short published_in)
|
||||
: id(id), title(std::move(title)), book_author(std::move(author)), published_in(published_in) {}
|
||||
unsigned int id{};
|
||||
std::string title;
|
||||
@@ -24,7 +25,7 @@ struct book {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "title", title, 511);
|
||||
field::attribute(op, "title", title, VarChar511);
|
||||
field::belongs_to(op, "author_id", book_author, utils::CascadeAllFetchEager);
|
||||
field::attribute(op, "published_in", published_in);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define QUERY_CATEGORY_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct category {
|
||||
namespace field = matador::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "name", name, UniqueVarChar255);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ struct coordinate {
|
||||
|
||||
namespace matador::access {
|
||||
template<class Operator>
|
||||
void attribute(Operator &op, const char *id, test::coordinate &value, const utils::field_attributes &attr = utils::NullAttributes) {
|
||||
void attribute(Operator &op, const char *id, test::coordinate &value, const utils::field_attributes &attr = NullAttributes) {
|
||||
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);
|
||||
|
||||
@@ -24,7 +24,7 @@ struct department {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 63);
|
||||
field::attribute(op, "name", name, UniqueVarChar63);
|
||||
field::has_many(op, "employees", employees, "dep_id", utils::CascadeAllFetchEager);
|
||||
// field::belongs_to(op, "manager_id", manager, utils::fetch_type::EAGER);
|
||||
}
|
||||
@@ -43,8 +43,8 @@ struct employee {
|
||||
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, "first_name", first_name, VarChar63);
|
||||
field::attribute(op, "last_name", last_name, VarChar63);
|
||||
field::belongs_to(op, "dep_id", dep, utils::CascadeAllFetchLazy);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ struct flight {
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::belongs_to(op, "airplane_id", plane, {utils::cascade_type::All, fetch_type::Eager});
|
||||
field::attribute(op, "pilot_name", pilot_name, 255);
|
||||
field::attribute(op, "pilot_name", pilot_name, VarChar255);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ struct location {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "name", name, UniqueVarChar63);
|
||||
field::attribute(op, "coordinate", coord);
|
||||
field::attribute(op, "color", color);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ struct optional {
|
||||
namespace field = matador::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "name", name, VarChar255);
|
||||
field::attribute(op, "age", age);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,17 +28,17 @@ struct order {
|
||||
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, "order_date", order_date, VarChar255);
|
||||
field::attribute(op, "required_date", required_date, VarChar255);
|
||||
field::attribute(op, "shipped_date", shipped_date, VarChar255);
|
||||
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::attribute(op, "ship_name", ship_name, VarChar255);
|
||||
field::attribute(op, "ship_address", ship_address, VarChar255);
|
||||
field::attribute(op, "ship_city", ship_city, VarChar255);
|
||||
field::attribute(op, "ship_region", ship_region, VarChar255);
|
||||
field::attribute(op, "ship_postal_code", ship_postal_code, VarChar255);
|
||||
field::attribute(op, "ship_country", ship_country, VarChar255);
|
||||
field::has_many(op, "order_details", order_details_, "order_id", utils::fetch_type::Eager);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ struct person {
|
||||
namespace field = matador::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "name", name, UniqueVarChar255);
|
||||
field::attribute(op, "age", age);
|
||||
field::attribute(op, "image", image);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ struct product {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "product_name", product_name, 255);
|
||||
field::primary_key(op, "product_name", product_name, ManualVarChar511);
|
||||
field::belongs_to(op, "supplier_id", seller, CascadeAllFetchLazy);
|
||||
field::belongs_to(op, "category_id", type, CascadeAllFetchLazy);
|
||||
field::attribute(op, "quantity_per_unit", quantity_per_unit, 255);
|
||||
field::attribute(op, "quantity_per_unit", quantity_per_unit, VarChar255);
|
||||
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);
|
||||
|
||||
@@ -29,7 +29,7 @@ struct ingredient {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "name", name, UniqueVarChar255);
|
||||
field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::CascadeAllFetchEager);
|
||||
}
|
||||
};
|
||||
@@ -53,15 +53,10 @@ struct recipe {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "name", name, UniqueVarChar255);
|
||||
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") {}
|
||||
// };
|
||||
}
|
||||
|
||||
#endif //QUERY_RECIPE_HPP
|
||||
|
||||
@@ -25,7 +25,7 @@ struct shipment {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "tracking_number", tracking_number, 255);
|
||||
field::attribute(op, "tracking_number", tracking_number, UniqueVarChar255);
|
||||
field::has_many(op, "packages", packages, "shipment_id", utils::CascadeAllFetchEager);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
#define QUERY_STUDENT_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
#include "matador/object/object_ptr.hpp"
|
||||
#include "matador/object/collection.hpp"
|
||||
#include "matador/object/many_to_many_relation.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -30,7 +30,7 @@ struct student {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "name", name, UniqueVarChar255);
|
||||
field::has_many_to_many(op, "student_courses", courses, "student_id", "course_id", utils::CascadeAllFetchLazy);
|
||||
}
|
||||
};
|
||||
@@ -51,15 +51,9 @@ struct course {
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "title", title, 255);
|
||||
field::attribute(op, "title", title, UniqueVarChar255);
|
||||
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") {
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif //QUERY_STUDENT_HPP
|
||||
|
||||
@@ -15,7 +15,7 @@ struct supplier {
|
||||
namespace field = matador::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "name", name, UniqueVarChar255);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
namespace matador::test {
|
||||
struct types {
|
||||
// enum { CSTR_LEN=255 };
|
||||
|
||||
unsigned int id_ = 0;
|
||||
int8_t char_ = 'c';
|
||||
short short_ = -127;
|
||||
@@ -20,7 +18,6 @@ struct types {
|
||||
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_;
|
||||
@@ -43,9 +40,8 @@ struct types {
|
||||
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_varchar", varchar_, VarChar63);
|
||||
// field::attribute(op, "val_date", date_);
|
||||
// field::attribute(op, "val_time", time_);
|
||||
field::attribute(op, "val_binary", binary_);
|
||||
|
||||
Reference in New Issue
Block a user