#include "work/admin/CollectionCenter.hpp" #include "work/admin/InternalUserDirectory.hpp" #include "work/admin/LdapGroupSchemaSettings.hpp" #include "work/admin/LdapImportSettings.hpp" #include "work/admin/LdapUserDirectory.hpp" #include "work/admin/LdapUserSchemaSettings.hpp" #include "work/admin/LoginHistory.hpp" #include "work/admin/Scenario.hpp" #include "work/admin/User.hpp" #include "work/admin/UserDirectory.hpp" #include "work/admin/UserSession.hpp" #include "work/jobs/Job.hpp" #include "work/jobs/Task.hpp"" #include "work/jobs/Payload.hpp" #include "work/jobs/IdPayload.hpp" #include "work/jobs/IdListPayload.hpp" #include "matador/object/schema.hpp" #include "matador/sql/connection.hpp" #include "matador/orm/session.hpp" using namespace matador; using namespace work::models; // Proposal for polymorphic classes: // object_ptr::as does the following checks; // // 1. The requested type has super class // 2. Super class has discriminator column defined // 3. Super class has discriminator value defined // 4. Discriminator value is mapped to the requested type // // If all checks succeed, the requested is fetched from // the database. // schema.attach("payloads", make_polymorph("type")); // schema.attach("id_list_payloads", make_polymorph_type("IdPayload")); // schema.attach("id_payloads"make_polymorph_type("IdListPayload")); // object::object_ptr payload; // auto result = payload.as(); // if (result.is_ok()) { // const auto& is_payload = result.value(); // // Use requested type // id_payload->id = 1; // } // payload.is_polymorphic(); // payload.is_polymorphic_type(); int main() { object::schema schema("Administration"); auto result = schema.attach("collection_center") .and_then([&schema] { return schema.attach("internal_user_directories"); }) .and_then([&schema] { return schema.attach("ldap_group_schema_settings"); }) .and_then([&schema] { return schema.attach("ldap_import_settings"); }) .and_then([&schema] { return schema.attach("ldap_user_directories"); } ) .and_then([&schema] { return schema.attach("ldap_user_schema_settings"); }) .and_then([&schema] { return schema.attach("login_histories"); }) .and_then([&schema] { return schema.attach("scenarios"); }) .and_then([&schema] { return schema.attach("users"); }) .and_then([&schema] { return schema.attach("user_directories"); }) .and_then([&schema] { return schema.attach("user_sessions"); }) .and_then([&schema] { return schema.attach("jobs"); }) .and_then([&schema] { return schema.attach("payloads"); }) .and_then([&schema] { return schema.attach("id_list_payloads"); }) .and_then([&schema] { return schema.attach("id_payloads"); }) .and_then([&schema] { return schema.attach("tasks"); }); if (!result.is_ok()) { return 0; } const std::string dns{"sqlite://demo.db"}; sql::connection c(dns); result = c.open(); // orm::session s() if (!result.is_ok()) { return 0; } return 0; } // registering table 'collection_center' (pk field: 'id') // registering relation table 'collection_center_users' (first fk field: 'collection_center_id', second fk field: 'user_id') // registering table 'internal_user_directory' (pk field: 'id') //