#ifndef QUERY_AUTHOR_HPP #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" #include #include namespace matador::test { struct book; struct author { author() = default; author(const unsigned int id, std::string first_name, std::string last_name, std::string date_of_birth, const unsigned short year_of_birth, const bool distinguished) : id(id), first_name(std::move(first_name)) , last_name(std::move(last_name)) , date_of_birth(std::move(date_of_birth)) , year_of_birth(year_of_birth) , distinguished(distinguished) {} unsigned int id{}; std::string first_name; std::string last_name; std::string date_of_birth; unsigned short year_of_birth{}; bool distinguished{false}; object::collection > books; template void process(Operator &op) { namespace field = matador::access; field::primary_key(op, "id", id); 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); } }; template struct book_pk_generator; template struct author_pk_generator { unsigned int id{}; std::string name; object::collection>> books; author_pk_generator() = default; explicit author_pk_generator(std::string name) : name(std::move(name)) {} template void process(Operator &op) { namespace field = matador::access; field::primary_key(op, "id", id, PkAttribute); field::attribute(op, "name", name, VarChar63); field::has_many(op, "books", books, "author_id", utils::CascadeAllFetchLazy); } }; template struct book_pk_generator { unsigned int id{}; std::string title; object::object_ptr> book_author; unsigned short published_in{}; book_pk_generator() = default; book_pk_generator(std::string title, object::object_ptr> author, const unsigned short published_in) : title(std::move(title)), book_author(std::move(author)), published_in(published_in) {} template void process(Operator &op) { namespace field = matador::access; field::primary_key(op, "id", id, PkAttribute); field::attribute(op, "title", title, VarChar511); field::belongs_to(op, "author_id", book_author, utils::CascadeAllFetchEager); field::attribute(op, "published_in", published_in); } }; using author_identity = author_pk_generator; using author_sequence = author_pk_generator; using author_table = author_pk_generator; using book_identity = book_pk_generator; using book_sequence = book_pk_generator; using book_table = book_pk_generator; } #endif //QUERY_AUTHOR_HPP