creating tables progress
This commit is contained in:
+92
-50
@@ -98,6 +98,30 @@ struct user {
|
||||
field::has_one(op, "profile_id", profile, matador::utils::default_foreign_attributes );
|
||||
}
|
||||
};
|
||||
|
||||
struct person {
|
||||
unsigned int id{};
|
||||
std::string name;
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key( op, "id", id );
|
||||
field::attribute( op, "name", name, 255 );
|
||||
}
|
||||
};
|
||||
|
||||
struct person_repo {
|
||||
unsigned int id{};
|
||||
matador::object::collection<matador::object::object_ptr<person>> person_list;
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key( op, "id", id );
|
||||
field::has_many( op, "person_list", person_list, "person_id", matador::utils::default_foreign_attributes );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
using namespace demo;
|
||||
@@ -107,66 +131,84 @@ int main() {
|
||||
// logger::default_min_log_level(logger::log_level::LVL_DEBUG);
|
||||
// logger::add_log_sink(logger::create_stdout_sink());
|
||||
|
||||
// {
|
||||
// // has_many with builtin-type
|
||||
// object::schema schema;
|
||||
//
|
||||
// auto result = schema.attach<names>("names");
|
||||
//
|
||||
// schema.dump(std::cout);
|
||||
// }
|
||||
{
|
||||
// has_many with builtin-type
|
||||
// has_many with foreign without belongs_to
|
||||
object::schema schema;
|
||||
|
||||
auto result = schema.attach<names>("names");
|
||||
auto result = schema.attach<person_repo>("person_repo")
|
||||
.and_then([&schema] { return schema.attach<person>("persons"); });
|
||||
|
||||
schema.dump(std::cout);
|
||||
}
|
||||
{
|
||||
// has_many to belongs_to
|
||||
// has_many with foreign without belongs_to
|
||||
object::schema schema;
|
||||
|
||||
auto result = schema.attach<author>("authors")
|
||||
.and_then([&schema] { return schema.attach<book>("books"); });
|
||||
|
||||
schema.dump(std::cout);
|
||||
}
|
||||
{
|
||||
// belongs_to to has_many
|
||||
object::schema schema;
|
||||
|
||||
auto result = schema.attach<book>("books")
|
||||
.and_then([&schema] { return schema.attach<author>("authors"); });
|
||||
|
||||
schema.dump(std::cout);
|
||||
}
|
||||
{
|
||||
// has_many_to_many (with join columns first)
|
||||
object::schema schema;
|
||||
|
||||
auto result = schema.attach<demo::ingredient>("ingredients")
|
||||
.and_then([&schema] { return schema.attach<recipe>("recipes"); });
|
||||
|
||||
schema.dump(std::cout);
|
||||
}
|
||||
{
|
||||
// has_many_to_many (with join columns last)
|
||||
object::schema schema;
|
||||
|
||||
auto result = schema.attach<demo::recipe>("recipes")
|
||||
.and_then([&schema] { return schema.attach<ingredient>("ingredients"); });
|
||||
|
||||
schema.dump(std::cout);
|
||||
}
|
||||
{
|
||||
// belongs_to to has_one
|
||||
object::schema schema;
|
||||
|
||||
auto result = schema.attach<profile>("profiles")
|
||||
.and_then([&schema] { return schema.attach<user>("users"); });
|
||||
|
||||
schema.dump(std::cout);
|
||||
}
|
||||
{
|
||||
// has_one to belongs_to
|
||||
object::schema schema;
|
||||
|
||||
auto result = schema.attach<user>("users")
|
||||
.and_then([&schema] { return schema.attach<profile>("profiles"); });
|
||||
auto result = schema.attach<person>("persons")
|
||||
.and_then([&schema] { return schema.attach<person_repo>("person_repo"); });
|
||||
|
||||
schema.dump(std::cout);
|
||||
}
|
||||
// {
|
||||
// // has_many to belongs_to
|
||||
// object::schema schema;
|
||||
//
|
||||
// auto result = schema.attach<author>("authors")
|
||||
// .and_then([&schema] { return schema.attach<book>("books"); });
|
||||
//
|
||||
// schema.dump(std::cout);
|
||||
// }
|
||||
// {
|
||||
// // belongs_to to has_many
|
||||
// object::schema schema;
|
||||
//
|
||||
// auto result = schema.attach<book>("books")
|
||||
// .and_then([&schema] { return schema.attach<author>("authors"); });
|
||||
//
|
||||
// schema.dump(std::cout);
|
||||
// }
|
||||
// {
|
||||
// // has_many_to_many (with join columns first)
|
||||
// object::schema schema;
|
||||
//
|
||||
// auto result = schema.attach<demo::ingredient>("ingredients")
|
||||
// .and_then([&schema] { return schema.attach<recipe>("recipes"); });
|
||||
//
|
||||
// schema.dump(std::cout);
|
||||
// }
|
||||
// {
|
||||
// // has_many_to_many (with join columns last)
|
||||
// object::schema schema;
|
||||
//
|
||||
// auto result = schema.attach<demo::recipe>("recipes")
|
||||
// .and_then([&schema] { return schema.attach<ingredient>("ingredients"); });
|
||||
//
|
||||
// schema.dump(std::cout);
|
||||
// }
|
||||
// {
|
||||
// // belongs_to to has_one
|
||||
// object::schema schema;
|
||||
//
|
||||
// auto result = schema.attach<profile>("profiles")
|
||||
// .and_then([&schema] { return schema.attach<user>("users"); });
|
||||
//
|
||||
// schema.dump(std::cout);
|
||||
// }
|
||||
// {
|
||||
// // has_one to belongs_to
|
||||
// object::schema schema;
|
||||
//
|
||||
// auto result = schema.attach<user>("users")
|
||||
// .and_then([&schema] { return schema.attach<profile>("profiles"); });
|
||||
//
|
||||
// schema.dump(std::cout);
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user