Skip to content

Commit 1ba8f16

Browse files
author
Shubham
committed
Allow adding entity flags for Sync
1 parent 8d6023c commit 1ba8f16

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

objectbox/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from objectbox.store import Store
1818
from objectbox.box import Box
19-
from objectbox.model.entity import Entity
19+
from objectbox.model.entity import Entity, SyncEntity
2020
from objectbox.model.properties import Id, String, Index, Bool, Int8, Int16, Int32, Int64, Float32, Float64, Bytes, BoolVector, Int8Vector, Int16Vector, Int32Vector, Int64Vector, Float32Vector, Float64Vector, CharVector, BoolList, Int8List, Int16List, Int32List, Int64List, Float32List, Float64List, CharList, Date, DateNano, Flex, HnswIndex, VectorDistanceType, HnswFlags
2121
from objectbox.model.model import Model
2222
from objectbox.c import version_core, DebugFlags
@@ -74,7 +74,8 @@
7474
'PropertyQueryCondition',
7575
'HnswFlags',
7676
'Query',
77-
'QueryBuilder'
77+
'QueryBuilder',
78+
'SyncEntity'
7879
]
7980

8081
# Python binding version

objectbox/c.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ class DbErrorCode(IntEnum):
414414
OBX_ERROR_TREE_OTHER = 10699
415415

416416

417+
class OBXEntityFlags(IntEnum):
418+
SYNC_ENABLED = 2
419+
SHARED_GLOBAL_IDS = 4
420+
421+
417422
def check_obx_err(code: obx_err, func, args) -> obx_err:
418423
""" Raises an exception if obx_err is not successful. """
419424
if code != DbErrorCode.OBX_SUCCESS:
@@ -535,6 +540,9 @@ def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
535540
obx_model_entity = c_fn_rc('obx_model_entity', [
536541
OBX_model_p, ctypes.c_char_p, obx_schema_id, obx_uid])
537542

543+
# obx_err obx_model_entity_flags(OBX_model* model, uint32_t flags);
544+
obx_model_entity_flags = c_fn_rc('obx_model_entity_flags', [OBX_model_p, ctypes.c_uint32])
545+
538546
# obx_err (OBX_model* model, const char* name, OBXPropertyType type, obx_schema_id property_id, obx_uid property_uid);
539547
obx_model_property = c_fn_rc('obx_model_property',
540548
[OBX_model_p, ctypes.c_char_p, OBXPropertyType, obx_schema_id, obx_uid])

objectbox/model/entity.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, user_type, uid: int = 0):
3838
self._id_property = None
3939
self._fill_properties()
4040
self._tl = threading.local()
41+
self._flags = 0
4142

4243
@property
4344
def _id(self) -> int:
@@ -320,3 +321,9 @@ def wrapper(class_) -> Callable[[Type], _Entity]:
320321
return entity_type
321322

322323
return wrapper
324+
325+
326+
def SyncEntity(cls):
327+
entity: _Entity = obx_models_by_name["default"][-1] # get the last added entity
328+
entity._flags |= OBXEntityFlags.SYNC_ENABLED
329+
return cls

objectbox/model/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def _create_property(self, prop: Property):
102102

103103
def _create_entity(self, entity: _Entity):
104104
obx_model_entity(self._c_model, c_str(entity._name), entity._id, entity._uid)
105+
obx_model_entity_flags(self._c_model, entity._flags)
105106
for prop in entity._properties:
106107
self._create_property(prop)
107108
obx_model_entity_last_property_id(self._c_model, entity._last_property_iduid.id, entity._last_property_iduid.uid)

0 commit comments

Comments
 (0)