@@ -2865,29 +2865,6 @@ namespace sqlite_orm {
28652865 is_not_null_t(T t_) : t(std::move(t_)) {}
28662866 };
28672867
2868- struct where_string {
2869- operator std::string() const {
2870- return "WHERE";
2871- }
2872- };
2873-
2874- /**
2875- * WHERE argument holder.
2876- * C is conditions type. Can be any condition like: is_equal_t, is_null_t, exists_t etc
2877- */
2878- template<class C>
2879- struct where_t : where_string {
2880- C c;
2881-
2882- where_t(C c_) : c(std::move(c_)) {}
2883- };
2884-
2885- template<class T>
2886- struct is_where : std::false_type {};
2887-
2888- template<class T>
2889- struct is_where<where_t<T>> : std::true_type {};
2890-
28912868 struct order_by_base {
28922869 int asc_desc = 0; // 1: asc, -1: desc
28932870 std::string _collate_argument;
@@ -3705,11 +3682,6 @@ namespace sqlite_orm {
37053682 return {std::move(l), std::move(r)};
37063683 }
37073684
3708- template<class C>
3709- internal::where_t<C> where(C c) {
3710- return {std::move(c)};
3711- }
3712-
37133685 /**
37143686 * ORDER BY column
37153687 * Example: storage.select(&User::name, order_by(&User::id))
@@ -4087,9 +4059,6 @@ namespace sqlite_orm {
40874059#include <type_traits> // std::forward, std::is_base_of, std::enable_if
40884060#include <memory> // std::unique_ptr
40894061#include <vector> // std::vector
4090- #ifdef SQLITE_ORM_STRING_VIEW_SUPPORTED
4091- #include <string_view>
4092- #endif
40934062
40944063// #include "conditions.h"
40954064
@@ -4134,17 +4103,30 @@ namespace sqlite_orm {
41344103 }
41354104}
41364105
4137- namespace sqlite_orm {
4106+ // #include "serialize_result_type.h"
41384107
4139- using int64 = sqlite_int64;
4140- using uint64 = sqlite_uint64;
4108+ #ifdef SQLITE_ORM_STRING_VIEW_SUPPORTED
4109+ #include <string_view> // string_view
4110+ #else
4111+ #include <string> // std::string
4112+ #endif
41414113
4114+ namespace sqlite_orm {
41424115 namespace internal {
41434116#ifdef SQLITE_ORM_STRING_VIEW_SUPPORTED
41444117 using serialize_result_type = std::string_view;
41454118#else
41464119 using serialize_result_type = std::string;
41474120#endif
4121+ }
4122+ }
4123+
4124+ namespace sqlite_orm {
4125+
4126+ using int64 = sqlite_int64;
4127+ using uint64 = sqlite_uint64;
4128+
4129+ namespace internal {
41484130
41494131 template<class T>
41504132 struct is_into;
@@ -6163,6 +6145,71 @@ namespace sqlite_orm {
61636145
61646146// #include "optional_container.h"
61656147
6148+ // #include "ast/where.h"
6149+
6150+ // #include "../serialize_result_type.h"
6151+
6152+ #ifdef SQLITE_ORM_STRING_VIEW_SUPPORTED
6153+ #include <string_view> // string_view
6154+ #else
6155+ #include <string> // std::string
6156+ #endif
6157+
6158+ namespace sqlite_orm {
6159+ namespace internal {
6160+ #ifdef SQLITE_ORM_STRING_VIEW_SUPPORTED
6161+ using serialize_result_type = std::string_view;
6162+ #else
6163+ using serialize_result_type = std::string;
6164+ #endif
6165+ }
6166+ }
6167+
6168+ namespace sqlite_orm {
6169+ namespace internal {
6170+
6171+ struct where_string {
6172+ serialize_result_type serialize() const {
6173+ return "WHERE";
6174+ }
6175+ };
6176+
6177+ /**
6178+ * WHERE argument holder.
6179+ * C is expression type. Can be any expression like: is_equal_t, is_null_t, exists_t etc
6180+ * Don't construct it manually. Call `where(...)` function instead.
6181+ */
6182+ template<class C>
6183+ struct where_t : where_string {
6184+ using expression_type = C;
6185+
6186+ expression_type expression;
6187+
6188+ where_t(expression_type expression_) : expression(std::move(expression_)) {}
6189+ };
6190+
6191+ template<class T>
6192+ struct is_where : std::false_type {};
6193+
6194+ template<class T>
6195+ struct is_where<where_t<T>> : std::true_type {};
6196+ }
6197+
6198+ /**
6199+ * WHERE clause. Use it to add WHERE conditions wherever you like.
6200+ * C is expression type. Can be any expression like: is_equal_t, is_null_t, exists_t etc
6201+ * @example
6202+ * // SELECT name
6203+ * // FROM letters
6204+ * // WHERE id > 3
6205+ * auto rows = storage.select(&Letter::name, where(greater_than(&Letter::id, 3)));
6206+ */
6207+ template<class C>
6208+ internal::where_t<C> where(C expression) {
6209+ return {std::move(expression)};
6210+ }
6211+ }
6212+
61666213namespace sqlite_orm {
61676214
61686215 namespace internal {
@@ -10526,6 +10573,8 @@ namespace sqlite_orm {
1052610573 }
1052710574}
1052810575
10576+ // #include "ast/where.h"
10577+
1052910578namespace sqlite_orm {
1053010579
1053110580 namespace internal {
@@ -10608,8 +10657,8 @@ namespace sqlite_orm {
1060810657 using node_type = where_t<C>;
1060910658
1061010659 template<class L>
10611- void operator()(const node_type& where , const L& l ) const {
10612- iterate_ast(where.c, l );
10660+ void operator()(const node_type& expression , const L& lambda ) const {
10661+ iterate_ast(expression.expression, lambda );
1061310662 }
1061410663 };
1061510664
@@ -14678,8 +14727,8 @@ namespace sqlite_orm {
1467814727 template<class C>
1467914728 std::string operator()(const statement_type& statement, const C& context) const {
1468014729 std::stringstream ss;
14681- ss << static_cast<std::string>( statement) << " ";
14682- auto whereString = serialize(statement.c , context);
14730+ ss << statement.serialize( ) << " ";
14731+ auto whereString = serialize(statement.expression , context);
1468314732 ss << "( " << whereString << ") ";
1468414733 return ss.str();
1468514734 }
@@ -16667,6 +16716,8 @@ __pragma(pop_macro("min"))
1666716716
1666816717 // #include "ast/upsert_clause.h"
1666916718
16719+ // #include "ast/where.h"
16720+
1667016721 namespace sqlite_orm {
1667116722
1667216723 namespace internal {
0 commit comments