@@ -32,22 +32,60 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232#include < sqlpp23/core/reader.h>
3333
3434namespace sqlpp {
35+
36+ template <typename L>
37+ struct sort_order_with_nulls_expression {
38+ constexpr sort_order_with_nulls_expression (sort_order_expression<L> lhs, nulls_pos rhs)
39+ : _lhs(std::move(lhs)), _rhs(std::move(rhs)) {}
40+ sort_order_with_nulls_expression (const sort_order_with_nulls_expression&) = default ;
41+ sort_order_with_nulls_expression (sort_order_with_nulls_expression&&) = default ;
42+ sort_order_with_nulls_expression& operator =(const sort_order_with_nulls_expression&) = default ;
43+ sort_order_with_nulls_expression& operator =(sort_order_with_nulls_expression&&) = default ;
44+ ~sort_order_with_nulls_expression () = default ;
45+
46+ private:
47+ friend reader_t ;
48+ const sort_order_expression<L> _lhs;
49+ const nulls_pos _rhs;
50+ };
51+
3552template <typename L>
3653struct sort_order_expression {
37- constexpr sort_order_expression (L l , sort_type r )
38- : _lhs(std::move(l )), _rhs(std::move(r )) {}
54+ constexpr sort_order_expression (L lhs , sort_type rhs )
55+ : _lhs(std::move(lhs )), _rhs(std::move(rhs )) {}
3956 sort_order_expression (const sort_order_expression&) = default ;
4057 sort_order_expression (sort_order_expression&&) = default ;
4158 sort_order_expression& operator =(const sort_order_expression&) = default ;
4259 sort_order_expression& operator =(sort_order_expression&&) = default ;
4360 ~sort_order_expression () = default ;
4461
62+ constexpr auto nulls_first () -> sort_order_with_nulls_expression<L>;
63+ constexpr auto nulls_last () -> sort_order_with_nulls_expression<L>;
64+ constexpr auto nulls_order (::sqlpp::nulls_pos t) -> sort_order_with_nulls_expression<L>;
65+
4566 private:
4667 friend reader_t ;
4768 L _lhs;
4869 sort_type _rhs;
4970};
5071
72+
73+
74+ template <typename L>
75+ constexpr auto sort_order_expression<L>::nulls_first() -> sort_order_with_nulls_expression<L> {
76+ return {std::move (_lhs), ::sqlpp::nulls_pos::first};
77+ }
78+
79+ template <typename L>
80+ constexpr auto sort_order_expression<L>::nulls_last() -> sort_order_with_nulls_expression<L> {
81+ return {std::move (_lhs), ::sqlpp::nulls_pos::last};
82+ };
83+
84+ template <typename L>
85+ constexpr auto sort_order_expression<L>::nulls_order(::sqlpp::nulls_pos t) -> sort_order_with_nulls_expression<L> {
86+ return {std::move (_lhs), std::move (t)};
87+ }
88+
5189template <typename L>
5290struct nodes_of <sort_order_expression<L>> {
5391 using type = detail::type_vector<L>;
@@ -64,6 +102,20 @@ auto to_sql_string(Context&, const sort_type& t) -> std::string {
64102 return " DESC" ;
65103}
66104
105+ template <typename Context>
106+ auto to_sql_string (Context&, const nulls_pos& t) -> std::string {
107+ if (t == nulls_pos::first) {
108+ return " NULLS FIRST" ;
109+ }
110+ return " NULLS LAST" ;
111+ }
112+
113+ template <typename Context>
114+ auto to_sql_string (Context& context, const sort_order& t)
115+ -> std::string {
116+ return to_sql_string (context, read.lhs (t)) + to_sql_string (context, read.rhs (t));
117+ }
118+
67119template <typename Context, typename L>
68120auto to_sql_string (Context& context, const sort_order_expression<L>& t)
69121 -> std::string {
0 commit comments