You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 rivejä
3.1 KiB

  1. #pragma once
  2. #include <cpphibernate/config.h>
  3. namespace cpphibernate
  4. {
  5. /**
  6. * @brief Context class for cpphibernate.
  7. */
  8. template<typename T_driver, typename T_schema>
  9. struct context
  10. : public T_driver
  11. {
  12. public:
  13. using base_type = T_driver;
  14. using driver_type = T_driver;
  15. using schema_type = T_schema;
  16. private:
  17. const schema_type& _schema;
  18. public:
  19. /**
  20. * @brief Value constructor. Create a new context object.
  21. *
  22. * @param p_schema Database schema to use.
  23. * @param p_args Arguments to pass to underlying driver.
  24. */
  25. template<typename... T_args>
  26. constexpr context(const schema_type& p_schema, T_args&&... p_args);
  27. /**
  28. * @brief Nove constructor.
  29. */
  30. constexpr context(context&&) = default;
  31. /**
  32. * @brief Copy constrcutor.
  33. */
  34. constexpr context(const context&) = default;
  35. /**
  36. * @brief Initialize the database. This will create all non exsitsing tables.
  37. */
  38. template<typename... T_args>
  39. constexpr decltype(auto) init(T_args&&... args);
  40. /**
  41. * @brief Create the passed object in the database.
  42. */
  43. template<typename... T_args>
  44. constexpr decltype(auto) create(T_args&&... args);
  45. /**
  46. * @brief Read an object from the database.
  47. */
  48. template<typename... T_args>
  49. constexpr decltype(auto) read(T_args&&... args);
  50. /**
  51. * @brief Update the passed object in the database.
  52. */
  53. template<typename... T_args>
  54. constexpr decltype(auto) update(T_args&&... args);
  55. /**
  56. * @brief Destroy the passed object in the database.
  57. */
  58. template<typename... T_args>
  59. constexpr decltype(auto) destroy(T_args&&... args);
  60. };
  61. /**
  62. * @brief Create a new cpphibernate context.
  63. *
  64. * @tparam T_driver Hibernate driver to use.
  65. * @tparam T_schema Database schema to use.
  66. * @tparam T_args Arguments to pass to underlying driver implementation.
  67. *
  68. * @param schema Database schema to use.
  69. * @param args Arguments to pass to underlying driver implementation.
  70. *
  71. * @return Created hibernate context.
  72. */
  73. template<typename T_driver, typename T_schema, typename... T_args>
  74. constexpr decltype(auto) make_context(T_schema&& schema, T_args&&... args);
  75. /**
  76. * @brief Create a new cpphibernate context as a unique pointer.
  77. *
  78. * @tparam T_driver Hibernate driver to use.
  79. * @tparam T_schema Database schema to use.
  80. * @tparam T_args Arguments to pass to underlying driver implementation.
  81. *
  82. * @param schema Database schema to use.
  83. * @param args Arguments to pass to underlying driver implementation.
  84. *
  85. * @return Unique pointer of the created hibernate context.
  86. */
  87. template<typename T_driver, typename T_schema, typename... T_args>
  88. constexpr decltype(auto) make_context_ptr(T_schema&& schema, T_args&&... args);
  89. }