@@ -45,7 +45,11 @@ class Box<T> {
45
45
}
46
46
}
47
47
48
- // if the respective ID property is given as null or 0, a newly assigned ID is returned, otherwise the existing ID is returned
48
+ /// Puts the given Object in the box (aka persisting it). If this is a new entity (its ID property is 0), a new ID
49
+ /// will be assigned to the entity (and returned). If the entity was already put in the box before, it will be
50
+ /// overwritten.
51
+ ///
52
+ /// Performance note: if you want to put several entities, consider [putMany] instead.
49
53
int put (T object, {_PutMode mode = _PutMode .Put }) {
50
54
var propVals = _entityReader (object);
51
55
if (propVals[_modelEntity.idPropName] == null || propVals[_modelEntity.idPropName] == 0 ) {
@@ -67,7 +71,8 @@ class Box<T> {
67
71
return propVals[_modelEntity.idPropName];
68
72
}
69
73
70
- // only instances whose ID property ot null or 0 will be given a new, valid number for that. A list of the final IDs is returned
74
+ /// Puts the given [objects] into this Box in a single transaction. Returns a list of all IDs of the inserted
75
+ /// Objects.
71
76
List <int > putMany (List <T > objects, {_PutMode mode = _PutMode .Put }) {
72
77
if (objects.isEmpty) return [];
73
78
@@ -129,6 +134,7 @@ class Box<T> {
129
134
return allPropVals.map ((p) => p[_modelEntity.idPropName] as int ).toList ();
130
135
}
131
136
137
+ /// Retrieves the stored object with the ID [id] from this box's database. Returns null if not found.
132
138
get (int id) {
133
139
final dataPtrPtr = allocate <Pointer <Uint8 >>();
134
140
final sizePtr = allocate <IntPtr >();
@@ -163,7 +169,8 @@ class Box<T> {
163
169
});
164
170
}
165
171
166
- // returns list of ids.length objects of type T, each corresponding to the location of its ID in the ids array. Non-existant IDs become null
172
+ /// Returns a list of [ids.length] Objects of type T, each corresponding to the location of its ID in [ids] .
173
+ /// Non-existant IDs become null.
167
174
List <T > getMany (List <int > ids) {
168
175
if (ids.isEmpty) return [];
169
176
@@ -174,14 +181,18 @@ class Box<T> {
174
181
() => checkObxPtr (bindings.obx_box_get_many (_cBox, ptr), "failed to get many objects from box" )));
175
182
}
176
183
184
+ /// Returns all stored objects in this Box.
177
185
List <T > getAll () {
178
186
const bool allowMissing = false ; // throw if null is encountered in the data found
179
187
return _getMany (
180
188
allowMissing, () => checkObxPtr (bindings.obx_box_get_all (_cBox), "failed to get all objects from box" ));
181
189
}
182
190
191
+ /// Returns a builder to create queries for Object matching supplied criteria.
183
192
QueryBuilder query (Condition qc) => QueryBuilder <T >(_store, _fbManager, _modelEntity.id.id, qc);
184
193
194
+ /// Returns the count of all stored Objects in this box or, if [limit] is not zero, the given [limit] , whichever
195
+ /// is lower.
185
196
int count ({int limit = 0 }) {
186
197
Pointer <Uint64 > count = allocate <Uint64 >();
187
198
try {
@@ -192,6 +203,7 @@ class Box<T> {
192
203
}
193
204
}
194
205
206
+ /// Returns true if no objects are in this box.
195
207
bool isEmpty () {
196
208
Pointer <Uint8 > isEmpty = allocate <Uint8 >();
197
209
try {
@@ -202,6 +214,7 @@ class Box<T> {
202
214
}
203
215
}
204
216
217
+ /// Returns true if this box contains an Object with the ID [id] .
205
218
bool contains (int id) {
206
219
Pointer <Uint8 > contains = allocate <Uint8 >();
207
220
try {
@@ -212,6 +225,7 @@ class Box<T> {
212
225
}
213
226
}
214
227
228
+ /// Returns true if this box contains objects with all of the given [ids] using a single transaction.
215
229
bool containsMany (List <int > ids) {
216
230
Pointer <Uint8 > contains = allocate <Uint8 >();
217
231
try {
@@ -224,13 +238,16 @@ class Box<T> {
224
238
}
225
239
}
226
240
241
+ /// Removes (deletes) the Object with the ID [id] . Returns true if an entity was actually removed and false if no
242
+ /// entity exists with the given ID.
227
243
bool remove (int id) {
228
244
final err = bindings.obx_box_remove (_cBox, id);
229
245
if (err == OBXError .OBX_NOT_FOUND ) return false ;
230
246
checkObx (err); // throws on other errors
231
247
return true ;
232
248
}
233
249
250
+ /// Removes (deletes) Objects by their ID in a single transaction. Returns a list of IDs of all removed Objects.
234
251
int removeMany (List <int > ids) {
235
252
Pointer <Uint64 > removedIds = allocate <Uint64 >();
236
253
try {
@@ -243,6 +260,7 @@ class Box<T> {
243
260
}
244
261
}
245
262
263
+ /// Removes (deletes) ALL Objects in a single transaction.
246
264
int removeAll () {
247
265
Pointer <Uint64 > removedItems = allocate <Uint64 >();
248
266
try {
@@ -253,5 +271,6 @@ class Box<T> {
253
271
}
254
272
}
255
273
274
+ /// The low-level pointer to this box.
256
275
get ptr => _cBox;
257
276
}
0 commit comments