|
- #pragma once
-
- #include "../classes/schema/schema.h"
-
- namespace cpphibernate {
- namespace mariadb {
-
- struct driver_t;
-
- /**
- * @brief Actual implementation of the mariadb driver.
- *
- * This class is used/owner by the mariadb driver class (as a member).
- * The public interface of this class will not be part of the cpphibernate context.
- */
- struct driver_impl_t
- {
- driver_t& owner;
- schema_ptr_u schema;
-
- /**
- * @brief Constructor.
-
- * @param[in] p_owner Object the driver implementation is owned by.
- * @param[in] p_schema Cpphibernate schema to use with the driver.
- */
- template<typename T_schema>
- inline driver_impl_t(driver_t& p_owner, T_schema&& p_schema);
-
- /**
- * @brief Initialize the schema in the database.
- *
- * @param[in] recreate Recreate the whole schema (this will drop all existing data).
- */
- inline void init(bool recreate) const;
-
- /**
- * @brief Create a new dataset in the database.
- * This will update the primary key field of the passed dataset.
- *
- * @param[in] dataset Dataset to create in database.
- */
- template<typename T_dataset>
- inline void create(T_dataset& dataset) const;
-
- /*
- }
-
- protected:
- inline void init_impl(bool recreate) const
- {
- transaction_lock trans(*_connection);
- _schema.init(init_context(_schema, *_connection, recreate));
- trans.commit();
- }
-
- template<typename T_dataset>
- inline void create_impl(T_dataset& dataset) const
- {
- create_update_impl_t<T_dataset>::apply(
- create_update_context(dataset, _schema, *_connection, _filter, false));
- }
-
- template<typename T_dataset, typename T_modifiers>
- inline void read_impl(T_dataset& dataset, T_modifiers&& modifiers) const
- {
- using dataset_type = mp::decay_t<T_dataset>;
- using real_dataset_type = misc::real_dataset_t<dataset_type>;
-
- auto dataset_id = misc::get_type_id(hana::type_c<real_dataset_type>);
- auto& table = _schema.table(dataset_id);
- auto context = make_read_context(dataset, _schema, *_connection, _filter);
- context.where = build_where(_schema, modifiers).query(*_connection);
- context.limit = build_limit(modifiers).query(*_connection);
- context.order_by = build_order_by(_schema, modifiers).query(*_connection);
-
- transaction_lock trans(*_connection);
- table.read(context);
- trans.commit();
- }
-
- template<typename T_dataset>
- inline void update_impl(T_dataset& dataset) const
- {
- create_update_impl_t<T_dataset>::apply(
- create_update_context(dataset, _schema, *_connection, _filter, true));
- }
-
- template<typename T_dataset>
- inline void destroy_impl(T_dataset& dataset) const
- {
- using dataset_type = mp::decay_t<T_dataset>;
- using real_dataset_type = misc::real_dataset_t<dataset_type>;
-
- auto dataset_id = misc::get_type_id(hana::type_c<real_dataset_type>);
- auto& table = _schema.table(dataset_id);
-
- destroy_context context(dataset, _schema, *_connection);
- context.where = table.get_where_primary_key(context);
-
- destroy_impl_t<T_dataset>::apply(context);
- }
- */
- };
-
- } }
|