Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

84 wiersze
2.7 KiB

  1. #pragma once
  2. beg_namespace_cpphibernate_driver_mariadb
  3. {
  4. /* order_by_builder */
  5. template<typename T_modifiers>
  6. struct order_by_builder
  7. {
  8. private:
  9. struct build_t
  10. {
  11. const schema_t& schema;
  12. const T_modifiers& modifiers;
  13. std::ostringstream os;
  14. inline build_t(const schema_t& p_schema, const T_modifiers& p_modifiers)
  15. : schema (p_schema)
  16. , modifiers (p_modifiers)
  17. { }
  18. inline void build(::cppmariadb::statement& statement)
  19. {
  20. size_t index = 0;
  21. hana::for_each(modifiers, [&](auto& modifier){
  22. using modifier_type = mp::decay_t<decltype(modifier)>;
  23. using is_order_by_type = modifier::is_order_by<modifier_type>;
  24. hana::eval_if(
  25. is_order_by_type { },
  26. [&](auto _){
  27. hana::for_each(_(modifier).fields, [&](auto& f){
  28. using field_type = mp::decay_t<decltype(f)>;
  29. using is_ascencing_type = modifier::is_ascending<field_type>;
  30. if (index++ == 0) os << "ORDER_BY ";
  31. else os << ", ";
  32. auto& field = schema.field(misc::get_type_id(f.wrapped_field));
  33. os << "`"
  34. << field.table_name
  35. << "`.`"
  36. << field.field_name
  37. << "` "
  38. << (is_ascencing_type::value
  39. ? "ASC"
  40. : "DESC");
  41. });
  42. },
  43. []{ });
  44. });
  45. statement.assign(os.str());
  46. }
  47. };
  48. private:
  49. const schema_t* _schema { nullptr };
  50. ::cppmariadb::statement _statement;
  51. public:
  52. inline ::cppmariadb::statement& assign(const schema_t& schema, const T_modifiers& modifiers)
  53. {
  54. if (_schema != &schema)
  55. {
  56. build_t(schema, modifiers).build(_statement);
  57. _schema = &schema;
  58. }
  59. return _statement;
  60. }
  61. };
  62. template<typename T_modifiers>
  63. inline decltype(auto) build_order_by(const schema_t& schema, const T_modifiers& modifiers)
  64. {
  65. static order_by_builder<T_modifiers> builder;
  66. return builder.assign(schema, modifiers);
  67. }
  68. }
  69. end_namespace_cpphibernate_driver_mariadb