#pragma once #include #include beg_namespace_cpphibernate_driver_mariadb { /* simple_field_t */ template void simple_field_t ::update() { base_type::update(); id = misc::get_type_id(hana::type_c); dataset_id = misc::get_type_id(hana::type_c); real_dataset_id = misc::get_type_id(hana::type_c); value_id = misc::get_type_id(hana::type_c); real_value_id = misc::get_type_id(hana::type_c); value_is_nullable = misc::is_nullable::value; value_is_pointer = misc::is_pointer::value; value_is_container = misc::is_container::value; value_is_ordered = misc::is_ordered::value; } /* value_field_t */ template void value_field_t ::update() { base_type::update(); this->type = type_props::type(); } template value_t value_field_t ::get(const data_context& context) const { auto& dataset = context.get(); return type_props::convert_from(this->field.getter(dataset)); } template void value_field_t ::set(const data_context& context, const value_t& value) const { auto& dataset = context.get(); this->field.setter(dataset, type_props::convert_to(value)); } /* primary_key_field_t */ template bool primary_key_field_t ::is_default(const data_context& context) const { auto& dataset = context.get(); return key_props::is_default(this->field.getter(dataset)); } template std::string primary_key_field_t ::generate_value(::cppmariadb::connection& connection) const { auto ret = connection.execute_used(key_props::create_key_query); if (!ret || !ret->next()) throw misc::hibernate_exception("unable to generate key value!"); return ret->current()->at(0).template get(); } /* foreign_table_field_t */ template value_t foreign_table_field_t ::foreign_create_update(const create_update_context& context) const { auto& dataset = context.get(); auto& foreign = this->field.getter(dataset); auto next_context = change_context(context, foreign); using foreign_dataset_type = mp::decay_t; return create_update_impl_t::apply( next_context, false); } template read_context_ptr foreign_table_field_t ::foreign_read(const read_context& context, bool fake_context) const { if (!fake_context) { auto& dataset = context.get(); auto& member = this->field.getter(dataset); auto new_context = make_read_context(member, context.schema, context.connection, context.filter); using context_type = mp::decay_t; return std::make_unique(new_context); } else { auto new_context = make_fake_context(hana::type_c, context.schema, context.connection, context.filter); using context_type = mp::decay_t; return std::make_unique(new_context); } } namespace __impl { /* is_primary_key_field */ template struct is_primary_key_field : public mp::decay_t().attributes, schema::attribute::primary_key))> { }; /* is_foreign_table_field */ template struct is_foreign_table_field : public mp::decay_t().tables, schema::table::get_wrapped_dataset), hana::type_c>))> { }; /* field_type */ template struct field_type { using type = data_field_t; }; template struct field_type>> { using type = primary_key_field_t; }; template struct field_type>> { using type = foreign_table_field_t; }; template using field_type_t = typename field_type::type; /* make_field_impl */ template struct make_field_impl { template static constexpr decltype(auto) apply(T_args&&... args) { static_assert(sizeof...(args) == -1, "Invalid parameters for mariadb::make_field(...)!"); } }; template struct make_field_impl< mp::list, mp::enable_if_c< schema::is_schema>::value && schema::is_table >::value && schema::is_field >::value>> { static constexpr decltype(auto) apply(const T_schema& schema, const T_table& table, const T_field& field) { using schema_type = mp::decay_t; using field_type = mp::decay_t; using return_type = field_type_t; using primary_key_type = primary_key_field_t; return_type ret(field); ret.schema_name = schema.name; ret.table_name = table.name; ret.field_name = field.name; ret.attributes = make_attributes(field.attributes); hana::eval_if( hana::equal(hana::type_c, hana::type_c), [&ret](){ ret.field_name = ret.table_name + "_" + ret.field_name; }, [](){ }); return ret; } }; } } end_namespace_cpphibernate_driver_mariadb