initial matador ng commit
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
#ifndef QUERY_AIRPLANE_HPP
|
||||
#define QUERY_AIRPLANE_HPP
|
||||
|
||||
#include "category.hpp"
|
||||
#include "supplier.hpp"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct airplane
|
||||
{
|
||||
airplane() = default;
|
||||
airplane(unsigned long id, std::string b, std::string m)
|
||||
: id(id)
|
||||
, brand(std::move(b))
|
||||
, model(std::move(m)) {}
|
||||
unsigned long id{};
|
||||
std::string brand;
|
||||
std::string model;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "brand", brand, 255);
|
||||
field::attribute(op, "model", model, 255);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //QUERY_AIRPLANE_HPP
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef QUERY_AUTHOR_HPP
|
||||
#define QUERY_AUTHOR_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct book;
|
||||
|
||||
struct author
|
||||
{
|
||||
unsigned long id{};
|
||||
std::string first_name;
|
||||
std::string last_name;
|
||||
std::string date_of_birth;
|
||||
unsigned short year_of_birth{};
|
||||
bool distinguished{false};
|
||||
std::vector<matador::sql::entity<book>> books;
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &op)
|
||||
{
|
||||
namespace field = matador::utils::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, "author_id", utils::fetch_type::LAZY);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //QUERY_AUTHOR_HPP
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef QUERY_BOOK_HPP
|
||||
#define QUERY_BOOK_HPP
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct author;
|
||||
|
||||
struct book
|
||||
{
|
||||
unsigned long id{};
|
||||
matador::sql::entity<author> book_author;
|
||||
std::string title;
|
||||
unsigned short published_in{};
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &op)
|
||||
{
|
||||
namespace field = matador::utils::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);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_BOOK_HPP
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef QUERY_CATEGORY_HPP
|
||||
#define QUERY_CATEGORY_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct category
|
||||
{
|
||||
unsigned long id{};
|
||||
std::string name;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_CATEGORY_HPP
|
||||
@@ -2,6 +2,7 @@
|
||||
#define QUERY_COORDINATE_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
namespace matador::test {
|
||||
struct coordinate
|
||||
@@ -13,10 +14,10 @@ struct coordinate
|
||||
|
||||
}
|
||||
|
||||
namespace matador::utils::access {
|
||||
namespace matador::access {
|
||||
|
||||
template<class Operator>
|
||||
void attribute(Operator &op, const char *id, test::coordinate &value, const field_attributes &attr = null_attributes) {
|
||||
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);
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef QUERY_FLIGHT_HPP
|
||||
#define QUERY_FLIGHT_HPP
|
||||
|
||||
#include "airplane.hpp"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
#include "matador/utils/fetch_type.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct flight
|
||||
{
|
||||
flight() = default;
|
||||
flight(unsigned long id, const sql::entity<airplane> &plane, std::string name)
|
||||
: id(id), airplane(plane), pilot_name(std::move(name)) {}
|
||||
|
||||
unsigned long id{};
|
||||
sql::entity<test::airplane> airplane;
|
||||
std::string pilot_name;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::has_one(op, "airplane_id", airplane, {utils::cascade_type::ALL, utils::fetch_type::EAGER});
|
||||
field::attribute(op, "pilot_name", pilot_name, 255);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //QUERY_FLIGHT_HPP
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "coordinate.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
enum class Color : uint8_t {
|
||||
@@ -21,7 +23,7 @@ struct location
|
||||
template < class Operator >
|
||||
void process(Operator &op)
|
||||
{
|
||||
namespace field = matador::utils::access;
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
field::attribute(op, "coordinate", coord);
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef QUERY_OPTIONAL_HPP
|
||||
#define QUERY_OPTIONAL_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct optional
|
||||
{
|
||||
unsigned long id{};
|
||||
std::optional<std::string> name;
|
||||
std::optional<unsigned int> age{};
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::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
|
||||
@@ -1,50 +0,0 @@
|
||||
#ifndef QUERY_ORDER_HPP
|
||||
#define QUERY_ORDER_HPP
|
||||
|
||||
#include "order_details.hpp"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct order
|
||||
{
|
||||
unsigned long 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<sql::entity<order_details>> order_details_;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::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_id", utils::fetch_type::EAGER);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_ORDER_HPP
|
||||
@@ -1,28 +0,0 @@
|
||||
#ifndef QUERY_ORDER_DETAILS_HPP
|
||||
#define QUERY_ORDER_DETAILS_HPP
|
||||
|
||||
#include "product.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct order;
|
||||
|
||||
struct order_details
|
||||
{
|
||||
unsigned long order_details_id;
|
||||
sql::entity<order> order_;
|
||||
sql::entity<product> product_;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::access;
|
||||
field::primary_key(op, "order_details_id", order_details_id);
|
||||
field::belongs_to(op, "order_id", order_, utils::default_foreign_attributes);
|
||||
field::has_one(op, "product_id", product_, utils::default_foreign_attributes);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_ORDER_DETAILS_HPP
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef QUERY_PERSON_HPP
|
||||
#define QUERY_PERSON_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/types.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct person
|
||||
{
|
||||
unsigned long id{};
|
||||
std::string name;
|
||||
unsigned int age{};
|
||||
utils::blob image;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::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
|
||||
@@ -1,46 +0,0 @@
|
||||
#ifndef QUERY_PRODUCT_HPP
|
||||
#define QUERY_PRODUCT_HPP
|
||||
|
||||
#include "category.hpp"
|
||||
#include "supplier.hpp"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct product
|
||||
{
|
||||
std::string product_name;
|
||||
sql::entity<test::supplier> supplier;
|
||||
sql::entity<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;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "product_name", product_name, 255);
|
||||
field::has_one(op, "supplier_id", supplier, utils::cascade_type::ALL);
|
||||
field::has_one(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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //QUERY_PRODUCT_HPP
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef QUERY_RECIPE_HPP
|
||||
#define QUERY_RECIPE_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
#include "matador/sql/has_many_to_many_relation.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct recipe;
|
||||
struct ingredient
|
||||
{
|
||||
unsigned long id{};
|
||||
std::string name;
|
||||
std::vector<matador::sql::entity<recipe>> recipes;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::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);
|
||||
}
|
||||
};
|
||||
|
||||
struct recipe
|
||||
{
|
||||
unsigned long id{};
|
||||
std::string name;
|
||||
std::vector<matador::sql::entity<ingredient>> ingredients;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::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);
|
||||
}
|
||||
};
|
||||
|
||||
class recipe_ingredient : public sql::has_many_to_many_relation<recipe, ingredient>
|
||||
{
|
||||
public:
|
||||
recipe_ingredient()
|
||||
: has_many_to_many_relation("recipe_id", "ingredient_id") {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //QUERY_RECIPE_HPP
|
||||
@@ -1,68 +0,0 @@
|
||||
#ifndef QUERY_STUDENT_HPP
|
||||
#define QUERY_STUDENT_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
#include "matador/sql/has_many_to_many_relation.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
class course;
|
||||
|
||||
struct student
|
||||
{
|
||||
unsigned long id{};
|
||||
std::string name;
|
||||
std::vector<matador::sql::entity<course>> courses;
|
||||
|
||||
student() = default;
|
||||
explicit student(unsigned long id, std::string name)
|
||||
: id(id)
|
||||
, name(std::move(name)) {}
|
||||
|
||||
template < class Operator >
|
||||
void process(Operator &op)
|
||||
{
|
||||
namespace field = matador::utils::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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct course
|
||||
{
|
||||
unsigned long id{};
|
||||
std::string title;
|
||||
std::vector<matador::sql::entity<student>> students;
|
||||
|
||||
course() = default;
|
||||
explicit course(unsigned long id, std::string title)
|
||||
: id(id)
|
||||
, title(std::move(title)) {}
|
||||
|
||||
template < class Operator >
|
||||
void process(Operator &op)
|
||||
{
|
||||
namespace field = matador::utils::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);
|
||||
}
|
||||
};
|
||||
|
||||
class student_course : public sql::has_many_to_many_relation<student, course>
|
||||
{
|
||||
public:
|
||||
student_course()
|
||||
: has_many_to_many_relation("student_id", "course_id") {}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_STUDENT_HPP
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef QUERY_SUPPLIER_HPP
|
||||
#define QUERY_SUPPLIER_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct supplier
|
||||
{
|
||||
unsigned long id{};
|
||||
std::string name;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 255);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_SUPPLIER_HPP
|
||||
@@ -0,0 +1,64 @@
|
||||
#ifndef QUERY_TYPES_HPP
|
||||
#define QUERY_TYPES_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/types.hpp"
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct types
|
||||
{
|
||||
enum { CSTR_LEN=255 };
|
||||
|
||||
unsigned long id_ = 0;
|
||||
char char_ = 'c';
|
||||
short short_ = -127;
|
||||
int int_ = -65000;
|
||||
long long_ = -128000;
|
||||
long long long64_ = -1234567890;
|
||||
unsigned char unsigned_char_ = 'H';
|
||||
unsigned short unsigned_short_ = 128;
|
||||
unsigned int unsigned_int_ = 65000;
|
||||
unsigned long unsigned_long_ = 128000;
|
||||
unsigned long long 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 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_);
|
||||
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", unsigned_long_);
|
||||
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
|
||||
Reference in New Issue
Block a user