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);
|
||||
// }
|
||||
}
|
||||
|
||||
+4
-4
@@ -70,13 +70,13 @@ using namespace work::models;
|
||||
// payload.is_polymorphic_type<jobs::IdPayload>();
|
||||
|
||||
int main() {
|
||||
logger::default_min_log_level(logger::log_level::LVL_DEBUG);
|
||||
logger::add_log_sink(logger::create_stdout_sink());
|
||||
// logger::default_min_log_level(logger::log_level::LVL_DEBUG);
|
||||
// logger::add_log_sink(logger::create_stdout_sink());
|
||||
|
||||
const object::schema schema("Administration");
|
||||
|
||||
sql::connection_pool<sql::connection> pool("postgres://news:news@127.0.0.1:15432/matador", 4);
|
||||
// sql::connection_pool<sql::connection> pool("postgres://test:test123!@127.0.0.1:5432/matador", 4);
|
||||
// sql::connection_pool<sql::connection> pool("postgres://news:news@127.0.0.1:15432/matador", 4);
|
||||
sql::connection_pool<sql::connection> pool("postgres://test:test123!@127.0.0.1:5432/matador", 4);
|
||||
|
||||
orm::session ses(pool);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ struct CollectionCenter : core::Model {
|
||||
field::attribute( op, "name", name, 511 );
|
||||
field::attribute( op, "symbol", symbol );
|
||||
field::attribute( op, "type", type );
|
||||
field::has_many( op, "collection_center_users", users, "collection_center_id", matador::utils::fetch_type::LAZY );
|
||||
field::has_many( op, "collection_center_users", users, "users_id", matador::utils::fetch_type::LAZY );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user