@@ -43,7 +43,7 @@ class OBX_store_options(ctypes.Structure):
4343 ]
4444
4545 def p (self ) -> 'ctypes.POINTER(OBX_store_options)' :
46- return ctypes .pointer (self )
46+ return ctypes .byref (self )
4747
4848
4949OBX_store_options_p = ctypes .POINTER (OBX_store_options )
@@ -118,7 +118,7 @@ class OBX_query(ctypes.Structure):
118118C .obx_last_error_code .restype = obx_err
119119
120120
121- class CError (Exception ):
121+ class CoreException (Exception ):
122122 codes = {
123123 0 : "SUCCESS" ,
124124 404 : "NOT_FOUND" ,
@@ -150,19 +150,25 @@ class CError(Exception):
150150 def __init__ (self , code ):
151151 self .code = code
152152 self .message = py_str (C .obx_last_error_message ())
153- super (CError , self ).__init__ ("%d (%s) - %s" % (code , self .codes [code ], self .message ))
153+ super (CoreException , self ).__init__ ("%d (%s) - %s" % (code , self .codes [code ], self .message ))
154154
155155
156- # check obx_err and raise an error
156+ class NotFoundException (CoreException ):
157+ pass
158+
159+
160+ # assert the the returned obx_err is empty
157161def check_obx_err (code : obx_err , func , args ):
158- if code != 0 :
159- raise CError (code )
162+ if code == 404 :
163+ raise NotFoundException (code )
164+ elif code != 0 :
165+ raise CoreException (code )
160166
161167
162- # check if the returned pointer is null and raise an error
163- def check_ptr_result (result , func , args ):
168+ # assert that the returned pointer/int is non-empty
169+ def check_result (result , func , args ):
164170 if not result :
165- raise CError (C .obx_last_error_code ())
171+ raise CoreException (C .obx_last_error_code ())
166172 return result
167173
168174
@@ -173,7 +179,7 @@ def fn(name: str, restype: type, argtypes):
173179 if restype is obx_err :
174180 func .errcheck = check_obx_err
175181 elif restype is not None :
176- func .errcheck = check_ptr_result
182+ func .errcheck = check_result
177183 func .restype = restype
178184
179185 func .argtypes = argtypes
@@ -220,6 +226,28 @@ def c_str(string: str) -> ctypes.c_char_p:
220226# obx_err (OBX_store* store);
221227obx_store_close = fn ('obx_store_close' , obx_err , [OBX_store_p ])
222228
229+ # OBX_box* (OBX_store* store, obx_schema_id entity_id);
230+ obx_box = fn ('obx_box' , OBX_box_p , [OBX_store_p , obx_schema_id ])
231+
232+ # obx_err (OBX_box* box, obx_id id, void** data, size_t* size);
233+ obx_box_get = fn ('obx_box_get' , obx_err ,
234+ [OBX_box_p , obx_id , ctypes .POINTER (ctypes .c_void_p ), ctypes .POINTER (ctypes .c_size_t )])
235+
236+ # obx_id (OBX_box* box, obx_id id_or_zero);
237+ obx_box_id_for_put = fn ('obx_box_id_for_put' , obx_id , [OBX_box_p , obx_id ])
238+
239+ # obx_err (OBX_box* box, obx_id id, const void* data, size_t size, OBXPutMode mode);
240+ obx_box_put = fn ('obx_box_put' , obx_err , [OBX_box_p , obx_id , ctypes .c_void_p , ctypes .c_size_t , OBXPutMode ])
241+
242+ # obx_err (OBX_box* box, obx_id id);
243+ obx_box_remove = fn ('obx_box_remove' , obx_err , [OBX_box_p , obx_id ])
244+
245+ # obx_err (OBX_box* box, bool* out_is_empty);
246+ obx_box_is_empty = fn ('obx_box_is_empty' , obx_err , [OBX_box_p , ctypes .POINTER (ctypes .c_bool )])
247+
248+ # obx_err obx_box_count(OBX_box* box, uint64_t limit, uint64_t* out_count);
249+ obx_box_count = fn ('obx_box_count' , obx_err , [OBX_box_p , ctypes .c_uint64 , ctypes .POINTER (ctypes .c_uint64 )])
250+
223251OBXPropertyType_Bool = 1
224252OBXPropertyType_Byte = 2
225253OBXPropertyType_Short = 3
@@ -249,38 +277,38 @@ def c_str(string: str) -> ctypes.c_char_p:
249277OBXPropertyFlags_INDEX_HASH64 = 4096
250278OBXPropertyFlags_UNSIGNED = 8192
251279
252- OBXDebugFlags_LOG_TRANSACTIONS_READ = 1 ,
253- OBXDebugFlags_LOG_TRANSACTIONS_WRITE = 2 ,
254- OBXDebugFlags_LOG_QUERIES = 4 ,
255- OBXDebugFlags_LOG_QUERY_PARAMETERS = 8 ,
256- OBXDebugFlags_LOG_ASYNC_QUEUE = 16 ,
280+ OBXDebugFlags_LOG_TRANSACTIONS_READ = 1
281+ OBXDebugFlags_LOG_TRANSACTIONS_WRITE = 2
282+ OBXDebugFlags_LOG_QUERIES = 4
283+ OBXDebugFlags_LOG_QUERY_PARAMETERS = 8
284+ OBXDebugFlags_LOG_ASYNC_QUEUE = 16
257285
258286# Standard put ("insert or update")
259- OBXPutMode_PUT = 1 ,
287+ OBXPutMode_PUT = 1
260288
261289# Put succeeds only if the entity does not exist yet.
262- OBXPutMode_INSERT = 2 ,
290+ OBXPutMode_INSERT = 2
263291
264292# Put succeeds only if the entity already exist.
265- OBXPutMode_UPDATE = 3 ,
293+ OBXPutMode_UPDATE = 3
266294
267295# The given ID (non-zero) is guaranteed to be new; don't use unless you know exactly what you are doing!
268296# This is primarily used internally. Wrong usage leads to inconsistent data (e.g. index data not updated)!
269297OBXPutMode_PUT_ID_GUARANTEED_TO_BE_NEW = 4
270298
271299# Reverts the order from ascending (default) to descending.
272- OBXOrderFlags_DESCENDING = 1 ,
300+ OBXOrderFlags_DESCENDING = 1
273301
274302# Makes upper case letters (e.g. "Z") be sorted before lower case letters (e.g. "a").
275303# If not specified, the default is case insensitive for ASCII characters.
276- OBXOrderFlags_CASE_SENSITIVE = 2 ,
304+ OBXOrderFlags_CASE_SENSITIVE = 2
277305
278306# For scalars only: changes the comparison to unsigned (default is signed).
279- OBXOrderFlags_UNSIGNED = 4 ,
307+ OBXOrderFlags_UNSIGNED = 4
280308
281309# null values will be put last.
282310# If not specified, by default null values will be put first.
283- OBXOrderFlags_NULLS_LAST = 8 ,
311+ OBXOrderFlags_NULLS_LAST = 8
284312
285313# null values should be treated equal to zero (scalars only).
286- OBXOrderFlags_NULLS_ZERO = 16 ,
314+ OBXOrderFlags_NULLS_ZERO = 16
0 commit comments