@@ -183,6 +183,40 @@ def _set_flags(self):
183183 if isinstance (self ._index , Index ): # Generic index
184184 self ._flags |= self ._index .type
185185
186+ class _NumericProperty (Property ):
187+ """Common class for numeric conditions.
188+ Implicitly no support for equals/not_equals, see also _IntProperty below.
189+ """
190+ def __init__ (self , py_type : Type , ** kwargs ):
191+ super (_NumericProperty , self ).__init__ (py_type , ** kwargs )
192+
193+ def greater_than (self , value ) -> PropertyQueryCondition :
194+ args = {'value' : value }
195+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .GT , args )
196+
197+ def greater_or_equal (self , value ) -> PropertyQueryCondition :
198+ args = {'value' : value }
199+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .GTE , args )
200+
201+ def less_than (self , value ) -> PropertyQueryCondition :
202+ args = {'value' : value }
203+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .LT , args )
204+
205+ def less_or_equal (self , value ) -> PropertyQueryCondition :
206+ args = {'value' : value }
207+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .LTE , args )
208+
209+ def between (self , a , b ) -> PropertyQueryCondition :
210+ args = {'a' : a , 'b' : b }
211+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .BETWEEN , args )
212+
213+ class _IntProperty (_NumericProperty ):
214+ """Integer-based conditions.
215+ Adds support for equals/not_equals.
216+ """
217+ def __init__ (self , py_type : Type , ** kwargs ):
218+ super (_IntProperty , self ).__init__ (py_type , ** kwargs )
219+
186220 def equals (self , value ) -> PropertyQueryCondition :
187221 args = {'value' : value }
188222 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .EQ , args )
@@ -191,13 +225,14 @@ def not_equals(self, value) -> PropertyQueryCondition:
191225 args = {'value' : value }
192226 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .NOT_EQ , args )
193227
228+
194229# ID property (primary key)
195- class Id (Property ):
230+ class Id (_IntProperty ):
196231 def __init__ (self , id : int = 0 , uid : int = 0 , py_type : type = int ):
197232 super (Id , self ).__init__ (py_type , id = id , uid = uid )
198233
199234# Bool property
200- class Bool (Property ):
235+ class Bool (_IntProperty ):
201236 def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
202237 super (Bool , self ).__init__ (bool , type = PropertyType .bool , id = id , uid = uid , ** kwargs )
203238
@@ -243,51 +278,18 @@ def less_or_equal(self, value, case_sensitive: bool = True) -> PropertyQueryCond
243278 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .LTE , args )
244279
245280
246- # Numeric Properties
247- class _NumericProperty (Property ):
248- def __init__ (self , py_type : Type , ** kwargs ):
249- super (_NumericProperty , self ).__init__ (py_type , ** kwargs )
250-
251- def equals (self , value ) -> PropertyQueryCondition :
252- args = {'value' : value }
253- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .EQ , args )
254-
255- def not_equals (self , value ) -> PropertyQueryCondition :
256- args = {'value' : value }
257- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .NOT_EQ , args )
258-
259- def greater_than (self , value ) -> PropertyQueryCondition :
260- args = {'value' : value }
261- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .GT , args )
262-
263- def greater_or_equal (self , value ) -> PropertyQueryCondition :
264- args = {'value' : value }
265- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .GTE , args )
266-
267- def less_than (self , value ) -> PropertyQueryCondition :
268- args = {'value' : value }
269- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .LT , args )
270-
271- def less_or_equal (self , value ) -> PropertyQueryCondition :
272- args = {'value' : value }
273- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .LTE , args )
274-
275- def between (self , a , b ) -> PropertyQueryCondition :
276- args = {'a' : a , 'b' : b }
277- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .BETWEEN , args )
278-
279-
281+
280282# Signed Integer Numeric Properties
281- class Int8 (_NumericProperty ):
283+ class Int8 (_IntProperty ):
282284 def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
283285 super (Int8 , self ).__init__ (int , type = PropertyType .byte , id = id , uid = uid , ** kwargs )
284- class Int16 (_NumericProperty ):
286+ class Int16 (_IntProperty ):
285287 def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
286288 super (Int16 , self ).__init__ (int , type = PropertyType .short , id = id , uid = uid , ** kwargs )
287- class Int32 (_NumericProperty ):
289+ class Int32 (_IntProperty ):
288290 def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
289291 super (Int32 , self ).__init__ (int , type = PropertyType .int , id = id , uid = uid , ** kwargs )
290- class Int64 (_NumericProperty ):
292+ class Int64 (_IntProperty ):
291293 def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
292294 super (Int64 , self ).__init__ (int , type = PropertyType .long , id = id , uid = uid , ** kwargs )
293295
@@ -301,11 +303,11 @@ def __init__(self, id : int = 0, uid : int = 0, **kwargs):
301303 super (Float64 , self ).__init__ (float , type = PropertyType .double , id = id , uid = uid , ** kwargs )
302304
303305# Date Properties
304- class Date (_NumericProperty ):
306+ class Date (_IntProperty ):
305307 def __init__ (self , py_type = datetime , id : int = 0 , uid : int = 0 , ** kwargs ):
306308 super (Date , self ).__init__ (py_type , type = PropertyType .date , id = id , uid = uid , ** kwargs )
307309
308- class DateNano (_NumericProperty ):
310+ class DateNano (_IntProperty ):
309311 def __init__ (self , py_type = datetime , id : int = 0 , uid : int = 0 , ** kwargs ):
310312 super (DateNano , self ).__init__ (py_type , type = PropertyType .dateNano , id = id , uid = uid , ** kwargs )
311313
0 commit comments