Debian Codegraph @

beanie/odm/operators/find/comparison.py

raw
1 from beanie.odm.operators.find import BaseFindOperator
2
3
4 class BaseFindComparisonOperator(BaseFindOperator):
5 operator = ""
6
7 def __init__(
8 self,
9 field,
10 other,
11 ) -> None:
12 self.field = field
13 self.other = other
14
15 @property
16 def query(self):
17 return {self.field: {self.operator: self.other}}
18
19
20 class Eq(BaseFindComparisonOperator):
21 """
22 `equal` query operator
23
24 Example:
25
26 ```python
27 class Product(Document):
28 price: float
29
30 Eq(Product.price, 2)
31 ```
32
33 Will return query object like
34
35 ```python
36 {"price": 2}
37 ```
38
39 MongoDB doc:
40 <https://docs.mongodb.com/manual/reference/operator/query/eq/>
41 """
42
43 @property
44 def query(self):
45 return {self.field: self.other}
46
47
48 class GT(BaseFindComparisonOperator):
49 """
50 `$gt` query operator
51
52 Example:
53
54 ```python
55 class Product(Document):
56 price: float
57
58 GT(Product.price, 2)
59 ```
60
61 Will return query object like
62
63 ```python
64 {"price": {"$gt": 2}}
65 ```
66
67 MongoDB doc:
68 <https://docs.mongodb.com/manual/reference/operator/query/gt/>
69 """
70
71 operator = "$gt"
72
73
74 class GTE(BaseFindComparisonOperator):
75 """
76 `$gte` query operator
77
78 Example:
79
80 ```python
81 class Product(Document):
82 price: float
83
84 GTE(Product.price, 2)
85 ```
86
87 Will return query object like
88
89 ```python
90 {"price": {"$gte": 2}}
91 ```
92
93 MongoDB doc:
94 <https://docs.mongodb.com/manual/reference/operator/query/gte/>
95 """
96
97 operator = "$gte"
98
99
100 class In(BaseFindComparisonOperator):
101 """
102 `$in` query operator
103
104 Example:
105
106 ```python
107 class Product(Document):
108 price: float
109
110 In(Product.price, [2, 3, 4])
111 ```
112
113 Will return query object like
114
115 ```python
116 {"price": {"$in": [2, 3, 4]}}
117 ```
118
119 MongoDB doc:
120 <https://docs.mongodb.com/manual/reference/operator/query/in/>
121 """
122
123 operator = "$in"
124
125
126 class NotIn(BaseFindComparisonOperator):
127 """
128 `$nin` query operator
129
130 Example:
131
132 ```python
133 class Product(Document):
134 price: float
135
136 NotIn(Product.price, [2, 3, 4])
137 ```
138
139 Will return query object like
140
141 ```python
142 {"price": {"$nin": [2, 3, 4]}}
143 ```
144
145 MongoDB doc:
146 <https://docs.mongodb.com/manual/reference/operator/query/nin/>
147 """
148
149 operator = "$nin"
150
151
152 class LT(BaseFindComparisonOperator):
153 """
154 `$lt` query operator
155
156 Example:
157
158 ```python
159 class Product(Document):
160 price: float
161
162 LT(Product.price, 2)
163 ```
164
165 Will return query object like
166
167 ```python
168 {"price": {"$lt": 2}}
169 ```
170
171 MongoDB doc:
172 <https://docs.mongodb.com/manual/reference/operator/query/lt/>
173 """
174
175 operator = "$lt"
176
177
178 class LTE(BaseFindComparisonOperator):
179 """
180 `$lte` query operator
181
182 Example:
183
184 ```python
185 class Product(Document):
186 price: float
187
188 LTE(Product.price, 2)
189 ```
190
191 Will return query object like
192
193 ```python
194 {"price": {"$lte": 2}}
195 ```
196
197 MongoDB doc:
198 <https://docs.mongodb.com/manual/reference/operator/query/lte/>
199 """
200
201 operator = "$lte"
202
203
204 class NE(BaseFindComparisonOperator):
205 """
206 `$ne` query operator
207
208 Example:
209
210 ```python
211 class Product(Document):
212 price: float
213
214 NE(Product.price, 2)
215 ```
216
217 Will return query object like
218
219 ```python
220 {"price": {"$ne": 2}}
221 ```
222
223 MongoDB doc:
224 <https://docs.mongodb.com/manual/reference/operator/query/ne/>
225 """
226
227 operator = "$ne"