Skip to content

Commit ba8be8e

Browse files
committed
objectbox: added docstrings #52
- box/entity/store - properties: conditions and hnsw components - toplevel: - module docstring - added PropertyQueryCondition and HnswFlags - c: DebugFlags documentation #52 - PropertyQueryCondition: docstring improvements - VectorDistanceType: changed enum elements docstrings
1 parent 46cf0c6 commit ba8be8e

File tree

7 files changed

+166
-31
lines changed

7 files changed

+166
-31
lines changed

objectbox/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""ObjectBox Python Bindings Public API"""
1516

1617
from objectbox.store import Store
1718
from objectbox.box import Box
1819
from objectbox.model.entity import Entity
19-
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
20+
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
2021
from objectbox.model.model import Model
2122
from objectbox.c import NotFoundException, version_core, DebugFlags
2223
from objectbox.version import Version
24+
from objectbox.condition import PropertyQueryCondition
2325
from objectbox.builder import Builder
2426
from objectbox.objectbox import ObjectBox
2527

@@ -65,7 +67,9 @@
6567
'NotFoundException',
6668
'version',
6769
'version_info',
68-
'DebugFlags'
70+
'DebugFlags',
71+
'PropertyQueryCondition',
72+
'HnswFlags',
6973
]
7074

7175
# Python binding version

objectbox/box.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def __init__(self, store: Store, entity: _Entity):
3131
self._c_box = obx_box(store._c_store, entity._id)
3232

3333
def is_empty(self) -> bool:
34+
"""Returns true if box is empty (i.e. no objects of entity type are available)."""
3435
is_empty = ctypes.c_bool()
3536
obx_box_is_empty(self._c_box, ctypes.byref(is_empty))
3637
return bool(is_empty.value)
3738

3839
def count(self, limit: int = 0) -> int:
40+
"""Returns the count of existing objects."""
3941
count = ctypes.c_uint64()
4042
obx_box_count(self._c_box, limit, ctypes.byref(count))
4143
return int(count.value)
@@ -110,6 +112,7 @@ def _put_many(self, objects) -> None:
110112
self._entity._set_object_id(objects[k], ids[k])
111113

112114
def get(self, id: int):
115+
"""Get object by given Id or None if not found."""
113116
with self._store.read_tx():
114117
c_data = ctypes.c_void_p()
115118
c_size = ctypes.c_size_t()
@@ -123,6 +126,7 @@ def get(self, id: int):
123126
return self._entity._unmarshal(data)
124127

125128
def get_all(self) -> list:
129+
"""Get all objects."""
126130
with self._store.read_tx():
127131
# OBX_bytes_array*
128132
c_bytes_array_p = obx_box_get_all(self._c_box)
@@ -143,6 +147,7 @@ def get_all(self) -> list:
143147
obx_bytes_array_free(c_bytes_array_p)
144148

145149
def remove(self, id_or_object) -> bool:
150+
"""Remove object by id or object."""
146151
if isinstance(id_or_object, self._entity._user_type):
147152
id = self._entity._get_object_id(id_or_object)
148153
else:
@@ -155,6 +160,7 @@ def remove(self, id_or_object) -> bool:
155160
return True
156161

157162
def remove_all(self) -> int:
163+
"""Removes all objects and returns number of removed."""
158164
count = ctypes.c_uint64()
159165
obx_box_remove_all(self._c_box, ctypes.byref(count))
160166
return int(count.value)
@@ -166,7 +172,7 @@ def query(self, condition: Optional[QueryCondition] = None) -> QueryBuilder:
166172
If given, applies the given high-level condition to the new QueryBuilder object.
167173
Useful for a user-friendly API design; for example:
168174
169-
``box.query(name_property.equals("Johnny")).build()``
175+
``box.query(MyEntity.name.equals("Johnny")).build()``
170176
"""
171177
qb = QueryBuilder(self._store, self)
172178
if condition is not None:

objectbox/c.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,33 @@ def shlib_name(library: str) -> str:
8686
OBXBackupRestoreFlags = ctypes.c_int
8787

8888
class DebugFlags(IntEnum):
89+
"""Debug flags"""
90+
8991
NONE = 0,
92+
9093
LOG_TRANSACTIONS_READ = 1,
94+
""" Log read transactions """
95+
9196
LOG_TRANSACTIONS_WRITE = 2,
97+
""" Log write transactions """
98+
9299
LOG_QUERIES = 3,
100+
""" Log queries """
101+
93102
LOG_QUERY_PARAMETERS = 8,
103+
""" Log query parameters """
104+
94105
LOG_ASYNC_QUEUE = 16,
106+
""" Log async queue """
107+
95108
LOG_CACHE_HITS = 32,
109+
""" Log cache hits """
110+
96111
LOG_CACHE_ALL = 64,
112+
""" Log cache hits """
113+
97114
LOG_TREE = 128
115+
""" Log tree operations """
98116

99117

100118
class OBX_model(ctypes.Structure):

objectbox/condition.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
class QueryCondition:
1313
def and_(self, other: QueryCondition) -> QueryCondition:
14+
"""*and* logic condition or using ``&`` operator"""
1415
return LogicQueryCondition(self, other, LogicQueryConditionOp.AND)
1516
__and__ = and_
1617

1718
def or_(self, other: QueryCondition) -> QueryCondition:
19+
"""*or* logic condition or using ``|`` operator"""
1820
return LogicQueryCondition(self, other, LogicQueryConditionOp.OR)
1921
__or__ = or_
2022

@@ -74,7 +76,11 @@ class PropertyQueryConditionOp(Enum):
7476

7577

7678
class PropertyQueryCondition(QueryCondition):
77-
""" A QueryCondition describing an operation to be applied on a property (e.g. name == "John", age == 24) """
79+
"""
80+
Query condition
81+
82+
Query conditions describe operations to be applied on a property (e.g. name == "John", age == 24)
83+
"""
7884

7985
_OP_MAP: Dict[PropertyQueryConditionOp, str] = {
8086
PropertyQueryConditionOp.EQ: "_apply_eq",

objectbox/model/entity.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,15 @@ def Entity(uid: int = 0, model: str = "default") -> _Entity:
282282
"""
283283
Entity decorator for user classes using syntax ``@Entity([uid=])``
284284
285-
Wraps user classes and returns a ``_Entity`` wrapper.
286-
Use allow @Entity(id=, uid=); i.e. no class arguments.
285+
Example::
286+
287+
@Entity()
288+
class MyEntity:
289+
id = Id
290+
name = String(index=Index)
291+
292+
293+
Wraps the given user classes as an ``_Entity`` helper class.
287294
"""
288295

289296
def wrapper(class_) -> Callable[[Type], _Entity]:

0 commit comments

Comments
 (0)