1313# limitations under the License.
1414
1515from enum import IntEnum
16+ from datetime import datetime
1617import flatbuffers .number_types
1718import numpy as np
1819from dataclasses import dataclass
1920
2021from objectbox .c import *
2122from objectbox .condition import PropertyQueryCondition , PropertyQueryConditionOp
2223
23-
2424class PropertyType (IntEnum ):
2525 bool = OBXPropertyType_Bool
2626 byte = OBXPropertyType_Byte
@@ -183,26 +183,49 @@ def _set_flags(self):
183183 if isinstance (self ._index , Index ): # Generic index
184184 self ._flags |= self ._index .type
185185
186- def equals (self , value , case_sensitive : bool = True ) -> PropertyQueryCondition :
187- args = {'value' : value , 'case_sensitive' : case_sensitive }
186+ def equals (self , value ) -> PropertyQueryCondition :
187+ args = {'value' : value , 'case_sensitive' : False }
188188 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .EQ , args )
189189
190- def not_equals (self , value , case_sensitive : bool = True ) -> PropertyQueryCondition :
191- args = {'value' : value , 'case_sensitive' : case_sensitive }
190+ def not_equals (self , value ) -> PropertyQueryCondition :
191+ args = {'value' : value , 'case_sensitive' : False }
192192 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .NOT_EQ , args )
193193
194- def contains (self , value : str , case_sensitive : bool = True ) -> PropertyQueryCondition :
195- args = {'value' : value , 'case_sensitive' : case_sensitive }
196- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .CONTAINS , args )
194+ # ID property (primary key)
195+ class Id (Property ):
196+ def __init__ (self , id : int = 0 , uid : int = 0 , py_type : type = int ):
197+ super (Id , self ).__init__ (py_type , id = id , uid = uid )
197198
199+ # Bool property
200+ class Bool (Property ):
201+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
202+ super (Bool , self ).__init__ (bool , type = PropertyType .bool , id = id , uid = uid , ** kwargs )
203+
204+ # String property with starts/ends_with
205+ class String (Property ):
206+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
207+ super (String , self ).__init__ (str , type = PropertyType .string , id = id , uid = uid , ** kwargs )
208+
198209 def starts_with (self , value : str , case_sensitive : bool = True ) -> PropertyQueryCondition :
199210 args = {'value' : value , 'case_sensitive' : case_sensitive }
200211 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .STARTS_WITH , args )
201212
202213 def ends_with (self , value : str , case_sensitive : bool = True ) -> PropertyQueryCondition :
203214 args = {'value' : value , 'case_sensitive' : case_sensitive }
204215 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .ENDS_WITH , args )
216+
217+ def equals (self , value , case_sensitive : bool = True ) -> PropertyQueryCondition :
218+ args = {'value' : value , 'case_sensitive' : case_sensitive }
219+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .EQ , args )
205220
221+ def not_equals (self , value , case_sensitive : bool = True ) -> PropertyQueryCondition :
222+ args = {'value' : value , 'case_sensitive' : case_sensitive }
223+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .NOT_EQ , args )
224+
225+ def contains (self , value : str , case_sensitive : bool = True ) -> PropertyQueryCondition :
226+ args = {'value' : value , 'case_sensitive' : case_sensitive }
227+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .CONTAINS , args )
228+
206229 def greater_than (self , value , case_sensitive : bool = True ) -> PropertyQueryCondition :
207230 args = {'value' : value , 'case_sensitive' : case_sensitive }
208231 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .GT , args )
@@ -218,21 +241,154 @@ def less_than(self, value, case_sensitive: bool = True) -> PropertyQueryConditio
218241 def less_or_equal (self , value , case_sensitive : bool = True ) -> PropertyQueryCondition :
219242 args = {'value' : value , 'case_sensitive' : case_sensitive }
220243 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .LTE , args )
244+
245+
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 , 'case_sensitive' : False }
253+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .EQ , args )
254+
255+ def not_equals (self , value ) -> PropertyQueryCondition :
256+ args = {'value' : value , 'case_sensitive' : False }
257+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .NOT_EQ , args )
258+
259+ def greater_than (self , value ) -> PropertyQueryCondition :
260+ args = {'value' : value , 'case_sensitive' : False }
261+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .GT , args )
262+
263+ def greater_or_equal (self , value ) -> PropertyQueryCondition :
264+ args = {'value' : value , 'case_sensitive' : False }
265+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .GTE , args )
266+
267+ def less_than (self , value ) -> PropertyQueryCondition :
268+ args = {'value' : value , 'case_sensitive' : False }
269+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .LT , args )
270+
271+ def less_or_equal (self , value ) -> PropertyQueryCondition :
272+ args = {'value' : value , 'case_sensitive' : False }
273+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .LTE , args )
221274
222275 def between (self , a , b ) -> PropertyQueryCondition :
223276 args = {'a' : a , 'b' : b }
224277 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .BETWEEN , args )
225278
226- def nearest_neighbor (self , query_vector , element_count : int ) -> PropertyQueryCondition :
227- args = {'query_vector' : query_vector , 'element_count' : element_count }
228- return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .NEAREST_NEIGHBOR , args )
229279
280+ # Signed Integer Numeric Properties
281+ class Int8 (_NumericProperty ):
282+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
283+ super (Int8 , self ).__init__ (int , type = PropertyType .byte , id = id , uid = uid , ** kwargs )
284+ class Int16 (_NumericProperty ):
285+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
286+ super (Int16 , self ).__init__ (int , type = PropertyType .short , id = id , uid = uid , ** kwargs )
287+ class Int32 (_NumericProperty ):
288+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
289+ super (Int32 , self ).__init__ (int , type = PropertyType .int , id = id , uid = uid , ** kwargs )
290+ class Int64 (_NumericProperty ):
291+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
292+ super (Int64 , self ).__init__ (int , type = PropertyType .long , id = id , uid = uid , ** kwargs )
293+
294+ # Floating-Point Numeric Properties
295+ class Float32 (_NumericProperty ):
296+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
297+ super (Float32 , self ).__init__ (float , type = PropertyType .float , id = id , uid = uid , ** kwargs )
298+
299+ class Float64 (_NumericProperty ):
300+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
301+ super (Float64 , self ).__init__ (float , type = PropertyType .double , id = id , uid = uid , ** kwargs )
302+
303+ # Date Properties
304+ class Date (_NumericProperty ):
305+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
306+ super (Date , self ).__init__ (int , type = PropertyType .date , id = id , uid = uid , ** kwargs )
307+
308+ class DateNano (_NumericProperty ):
309+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
310+ super (DateNano , self ).__init__ (int , type = PropertyType .dateNano , id = id , uid = uid , ** kwargs )
311+
312+ # Flex Property
313+ class Flex (Property ):
314+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
315+ super (Flex , self ).__init__ (Generic , type = PropertyType .flex , id = id , uid = uid , ** kwargs )
230316 def contains_key_value (self , key : str , value : str , case_sensitive : bool = True ) -> PropertyQueryCondition :
231317 args = {'key' : key , 'value' : value , 'case_sensitive' : case_sensitive }
232318 return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .CONTAINS_KEY_VALUE , args )
233319
234320
235- # ID property (primary key)
236- class Id (Property ):
237- def __init__ (self , py_type : type = int , id : int = 0 , uid : int = 0 ):
238- super (Id , self ).__init__ (py_type , id = id , uid = uid )
321+
322+ class _VectorProperty (Property ):
323+ def __init__ (self , py_type : Type , ** kwargs ):
324+ super (_VectorProperty , self ).__init__ (py_type , ** kwargs )
325+ def nearest_neighbor (self , query_vector , element_count : int ) -> PropertyQueryCondition :
326+ args = {'query_vector' : query_vector , 'element_count' : element_count }
327+ return PropertyQueryCondition (self ._id , PropertyQueryConditionOp .NEAREST_NEIGHBOR , args )
328+
329+ class BoolVector (_VectorProperty ):
330+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
331+ super (BoolVector , self ).__init__ (np .ndarray , type = PropertyType .boolVector , id = id , uid = uid , ** kwargs )
332+ class Int8Vector (_VectorProperty ):
333+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
334+ super (Int8Vector , self ).__init__ (bytes , type = PropertyType .byteVector , id = id , uid = uid , ** kwargs )
335+
336+ class Int16Vector (_VectorProperty ):
337+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
338+ super (Int16Vector , self ).__init__ (np .ndarray , type = PropertyType .shortVector , id = id , uid = uid , ** kwargs )
339+
340+ class CharVector (_VectorProperty ):
341+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
342+ super (CharVector , self ).__init__ (np .ndarray , type = PropertyType .charVector , id = id , uid = uid , ** kwargs )
343+
344+ class Int32Vector (_VectorProperty ):
345+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
346+ super (Int32Vector , self ).__init__ (np .ndarray , type = PropertyType .intVector , id = id , uid = uid , ** kwargs )
347+
348+ class Int64Vector (_VectorProperty ):
349+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
350+ super (Int64Vector , self ).__init__ (np .ndarray , type = PropertyType .longVector , id = id , uid = uid , ** kwargs )
351+
352+ class Float32Vector (_VectorProperty ):
353+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
354+ super (Float32Vector , self ).__init__ (np .ndarray , type = PropertyType .floatVector , id = id , uid = uid , ** kwargs )
355+
356+ class Float64Vector (_VectorProperty ):
357+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
358+ super (Float64Vector , self ).__init__ (np .ndarray , type = PropertyType .doubleVector , id = id , uid = uid , ** kwargs )
359+
360+ class _ListProperty (Property ):
361+ def __init__ (self , ** kwargs ):
362+ super (_ListProperty , self ).__init__ (list , ** kwargs )
363+
364+ class BoolList (_ListProperty ):
365+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
366+ super (BoolList , self ).__init__ (type = PropertyType .boolVector , id = id , uid = uid , ** kwargs )
367+
368+ class Int8List (_ListProperty ):
369+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
370+ super (Int8List , self ).__init__ (type = PropertyType .byteVector , id = id , uid = uid , ** kwargs )
371+
372+ class Int16List (_ListProperty ):
373+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
374+ super (Int16List , self ).__init__ (type = PropertyType .shortVector , id = id , uid = uid , ** kwargs )
375+
376+ class Int32List (_ListProperty ):
377+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
378+ super (Int32List , self ).__init__ (type = PropertyType .intVector , id = id , uid = uid , ** kwargs )
379+
380+ class Int64List (_ListProperty ):
381+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
382+ super (Int64List , self ).__init__ (type = PropertyType .longVector , id = id , uid = uid , ** kwargs )
383+
384+ class Float32List (_ListProperty ):
385+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
386+ super (Float32List , self ).__init__ (type = PropertyType .floatVector , id = id , uid = uid , ** kwargs )
387+
388+ class Float64List (_ListProperty ):
389+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
390+ super (Float64List , self ).__init__ (type = PropertyType .doubleVector , id = id , uid = uid , ** kwargs )
391+
392+ class CharList (_ListProperty ):
393+ def __init__ (self , id : int = 0 , uid : int = 0 , ** kwargs ):
394+ super (CharList , self ).__init__ (type = PropertyType .charVector , id = id , uid = uid , ** kwargs )
0 commit comments