1+ #pragma once
2+
3+ #ifndef SQLITE_ORM_IMPORT_STD_MODULE
4+ #include < initializer_list> // std::initializer_list
5+ #include < tuple> // std::tuple
6+ #include < utility> // std::move
7+ #include < vector> // std::vector
8+ #endif
9+
10+ #include " ../tags.h"
11+
12+ namespace sqlite_orm ::internal {
13+
14+ struct in_base {
15+ bool negative = false ; // used in not_in
16+ };
17+
18+ /* *
19+ * IN operator object.
20+ */
21+ template <class L , class A >
22+ struct dynamic_in_t : condition_t , in_base, negatable_t {
23+ using self = dynamic_in_t <L, A>;
24+
25+ L left; // left expression
26+ A argument; // in arg
27+
28+ dynamic_in_t (L left_, A argument_, bool negative_) :
29+ in_base{negative_}, left(std::move(left_)), argument(std::move(argument_)) {}
30+ };
31+
32+ template <class L , class ... Args>
33+ struct in_t : condition_t , in_base, negatable_t {
34+ L left;
35+ std::tuple<Args...> argument;
36+
37+ in_t (L left_, decltype (argument) argument_, bool negative_) :
38+ in_base{negative_}, left(std::move(left_)), argument(std::move(argument_)) {}
39+ };
40+
41+ }
42+
43+ SQLITE_ORM_EXPORT namespace sqlite_orm {
44+ /* *
45+ * IN operator with vector of values.
46+ * Example: in(&User::id, std::vector<int>{1, 2, 3})
47+ * @param left Left expression (column or value to check).
48+ * @param values Vector of values to check against.
49+ * @return dynamic_in_t instance representing IN clause.
50+ */
51+ template <class L , class E >
52+ internal::dynamic_in_t <L, std::vector<E>> in (L left, std::vector<E> values) {
53+ return {std::move (left), std::move (values), false };
54+ }
55+
56+ /* *
57+ * IN operator with initializer list.
58+ * Example: in(&User::id, {1, 2, 3})
59+ * @param left Left expression (column or value to check).
60+ * @param values Initializer list of values to check against.
61+ * @return dynamic_in_t instance representing IN clause.
62+ */
63+ template <class L , class E >
64+ internal::dynamic_in_t <L, std::vector<E>> in (L left, std::initializer_list<E> values) {
65+ return {std::move (left), std::move (values), false };
66+ }
67+
68+ /* *
69+ * IN operator with a subquery or custom argument.
70+ * Example: in(&User::id, select(&Employee::managerId))
71+ * @param left Left expression (column or value to check).
72+ * @param argument Subquery or container to check against.
73+ * @return dynamic_in_t instance representing IN clause.
74+ */
75+ template <class L , class A >
76+ internal::dynamic_in_t <L, A> in (L left, A argument) {
77+ return {std::move (left), std::move (argument), false };
78+ }
79+
80+ /* *
81+ * NOT IN operator with vector of values.
82+ * Example: not_in(&User::id, std::vector<int>{1, 2, 3})
83+ * @param left Left expression (column or value to check).
84+ * @param values Vector of values to check against.
85+ * @return dynamic_in_t instance representing NOT IN clause.
86+ */
87+ template <class L , class E >
88+ internal::dynamic_in_t <L, std::vector<E>> not_in (L left, std::vector<E> values) {
89+ return {std::move (left), std::move (values), true };
90+ }
91+
92+ /* *
93+ * NOT IN operator with initializer list.
94+ * Example: not_in(&User::id, {1, 2, 3})
95+ * @param left Left expression (column or value to check).
96+ * @param values Initializer list of values to check against.
97+ * @return dynamic_in_t instance representing NOT IN clause.
98+ */
99+ template <class L , class E >
100+ internal::dynamic_in_t <L, std::vector<E>> not_in (L left, std::initializer_list<E> values) {
101+ return {std::move (left), std::move (values), true };
102+ }
103+
104+ /* *
105+ * NOT IN operator with a subquery or custom argument.
106+ * Example: not_in(&User::id, select(&Employee::managerId))
107+ * @param left Left expression (column or value to check).
108+ * @param argument Subquery or container to check against.
109+ * @return dynamic_in_t instance representing NOT IN clause.
110+ */
111+ template <class L , class A >
112+ internal::dynamic_in_t <L, A> not_in (L left, A argument) {
113+ return {std::move (left), std::move (argument), true };
114+ }
115+ }
0 commit comments