92 lines
3.8 KiB
C++
92 lines
3.8 KiB
C++
#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<Type> 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<jobs::Payload>("payloads", make_polymorph("type"));
|
|
// schema.attach<jobs::Payload, jobs::IdPayload>("id_list_payloads", make_polymorph_type("IdPayload"));
|
|
// schema.attach<jobs::Payload, jobs::IdListPayload>("id_payloads"make_polymorph_type("IdListPayload"));
|
|
// object::object_ptr<jobs::Payload> payload;
|
|
// auto result = payload.as<jobs::IdPayload>();
|
|
// if (result.is_ok()) {
|
|
// const auto& is_payload = result.value();
|
|
// // Use requested type
|
|
// id_payload->id = 1;
|
|
// }
|
|
// payload.is_polymorphic();
|
|
// payload.is_polymorphic_type<jobs::IdPayload>();
|
|
|
|
int main() {
|
|
object::schema schema("Administration");
|
|
|
|
auto result = schema.attach<admin::CollectionCenter>("collection_center")
|
|
.and_then([&schema] { return schema.attach<admin::UserDirectory>("user_directories"); })
|
|
.and_then([&schema] { return schema.attach<admin::LdapGroupSchemaSettings>("ldap_group_schema_settings"); })
|
|
.and_then([&schema] { return schema.attach<admin::LdapImportSettings>("ldap_import_settings"); })
|
|
.and_then([&schema] { return schema.attach<admin::LdapUserSchemaSettings>("ldap_user_schema_settings"); })
|
|
.and_then([&schema] { return schema.attach<admin::UserDirectory, admin::InternalUserDirectory>("internal_user_directories"); })
|
|
.and_then([&schema] { return schema.attach<admin::UserDirectory, admin::LdapUserDirectory>("ldap_user_directories"); } )
|
|
.and_then([&schema] { return schema.attach<admin::LoginHistory>("login_histories"); })
|
|
.and_then([&schema] { return schema.attach<admin::Scenario>("scenarios"); })
|
|
.and_then([&schema] { return schema.attach<admin::User>("users"); })
|
|
.and_then([&schema] { return schema.attach<admin::UserSession>("user_sessions"); })
|
|
.and_then([&schema] { return schema.attach<jobs::Job>("jobs"); })
|
|
.and_then([&schema] { return schema.attach<jobs::Payload>("payloads"); })
|
|
.and_then([&schema] { return schema.attach<jobs::Payload, jobs::IdPayload>("id_list_payloads"); })
|
|
.and_then([&schema] { return schema.attach<jobs::Payload, jobs::IdListPayload>("id_payloads"); })
|
|
.and_then([&schema] { return schema.attach<jobs::Task>("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')
|
|
//
|