Skip to content

Commit 27df654

Browse files
author
Ivan Dlugos
committed
documentation and minor cleanups
1 parent 2fd4c94 commit 27df654

File tree

17 files changed

+185
-28
lines changed

17 files changed

+185
-28
lines changed

objectbox/lib/internal.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ library objectbox_internal;
44

55
export 'src/model.dart';
66
export 'src/modelinfo/index.dart';
7-
export 'src/query/query.dart';
7+
export 'src/query/query.dart'
8+
// don't export the same things as objectbox.dart to avoid docs conflicts
9+
hide
10+
Query,
11+
QueryBuilder,
12+
Order,
13+
Condition,
14+
PropertyQuery,
15+
IntegerPropertyQuery,
16+
DoublePropertyQuery,
17+
StringPropertyQuery;
818
export 'src/relations/info.dart';
9-
export 'src/relations/to_many.dart';
10-
export 'src/relations/to_one.dart';
19+
export 'src/relations/to_many.dart'
20+
show InternalToManyAccess, InternalToManyTestAccess;
21+
export 'src/relations/to_one.dart' show InternalToOneAccess;
22+
export 'src/sync.dart' show InternaSyncTestAccess;

objectbox/lib/objectbox.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ export 'src/query/query.dart'
2222
export 'src/relations/to_many.dart' show ToMany;
2323
export 'src/relations/to_one.dart' show ToOne;
2424
export 'src/store.dart' show Store;
25-
export 'src/sync.dart';
25+
export 'src/sync.dart'
26+
show Sync, SyncClient, SyncCredentials, SyncRequestUpdatesMode, SyncState;
2627
export 'src/transaction.dart' show TxMode;

objectbox/lib/src/annotations.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Entity {
1717
/// Entity instead of creating a new one.
1818
final int /*?*/ uid;
1919

20+
/// Create an Entity annotation.
2021
const Entity({this.uid});
2122
}
2223

@@ -46,6 +47,7 @@ class Property {
4647
/// The defaults are e.g. Int -> Int64, double -> Float64, bool -> Bool.
4748
final PropertyType /*?*/ type;
4849

50+
/// Create an Property annotation.
4951
const Property({this.type, this.uid});
5052
}
5153

@@ -105,11 +107,13 @@ enum PropertyType {
105107
/// Annotation Id can be used to specify an entity ID property if it's named
106108
/// anything else then "id" (case insensitive).
107109
class Id {
110+
/// Create an Id annotation.
108111
const Id();
109112
}
110113

111114
/// Transient annotation marks properties that should not be stored in the DB.
112115
class Transient {
116+
/// Create a Transient annotation.
113117
const Transient();
114118
}
115119

@@ -128,8 +132,10 @@ class Transient {
128132
/// Note: indexes are currently not supported for ByteVector, Float or Double
129133
/// properties.
130134
class Index {
135+
/// Index type.
131136
final IndexType /*?*/ type;
132137

138+
/// Create an Index annotaion.
133139
const Index({this.type});
134140
}
135141

@@ -169,6 +175,7 @@ enum IndexType {
169175
/// It is supported to explicitly add the [Index] annotation to configure the
170176
/// index type.
171177
class Unique {
178+
/// Create a Unique annotation.
172179
const Unique();
173180
}
174181

@@ -201,6 +208,8 @@ class Unique {
201208
/// }
202209
/// ```
203210
class Backlink {
211+
/// Target entity to which this backlink points. It's the entity that contains
212+
/// a [ToOne] or [ToMany] relation pointing to the current entity.
204213
final String to;
205214

206215
/// If there are multiple relations pointing to the current entity, specify

objectbox/lib/src/box.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ import 'relations/to_one.dart';
1414
import 'store.dart';
1515
import 'transaction.dart';
1616

17+
/// Box put (write) mode.
1718
enum PutMode {
19+
/// Insert (if given object's ID is zero) or update an existing object.
1820
put,
21+
22+
/// Insert a new object.
1923
insert,
24+
25+
/// Update an existing object, fails if the given ID doesn't exist.
2026
update,
2127
}
2228

@@ -37,6 +43,7 @@ class Box<T> {
3743
final bool _hasToManyRelations;
3844
final _builder = BuilderWithCBuffer();
3945

46+
/// Create a box for an Entity.
4047
factory Box(Store store) => store.box();
4148

4249
Box._(this._store, this._entity)
@@ -305,11 +312,14 @@ class Box<T> {
305312
}
306313
}
307314

315+
/// Internal only.
308316
// TODO enable annotation once meta:1.3.0 is out
309317
// @internal
310318
class InternalBoxAccess {
319+
/// Create a box in the store for the given entity.
311320
static Box<T> create<T>(Store store, EntityDefinition<T> entity) =>
312321
Box._(store, entity);
313322

323+
/// Close the box, freeing resources.
314324
static void close(Box box) => box._builder.clear();
315325
}

objectbox/lib/src/common.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import 'bindings/bindings.dart';
77
// TODO use pub_semver?
88
/// Wrapper for a semantic version information.
99
class Version {
10+
/// Major version number.
1011
final int major;
12+
13+
/// Minor version number.
1114
final int minor;
15+
16+
/// Patch version number.
1217
final int patch;
1318

19+
/// Create a version identifier.
1420
const Version(this.major, this.minor, this.patch);
1521

1622
@override
@@ -35,10 +41,16 @@ Version nativeLibraryVersion() {
3541

3642
/// ObjectBox native exception wrapper.
3743
class ObjectBoxException implements Exception {
44+
/// Dart message related to this native error.
3845
final String /*?*/ dartMsg;
46+
47+
/// Native error code.
3948
final int nativeCode;
49+
50+
/// Native error message.
4051
final String /*?*/ nativeMsg;
4152

53+
/// Create a native exception.
4254
ObjectBoxException({this.dartMsg, this.nativeCode = 0, this.nativeMsg});
4355

4456
@override

objectbox/lib/src/observable.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ extension Streamable<T> on Query<T> {
7979
};
8080
}
8181

82+
/// Create a stream, executing [Query.find()] whenever there's a change to the
83+
/// underlying Entity.
8284
Stream<List<T>> findStream(
8385
{@Deprecated('Use offset() instead') int offset = 0,
8486
@Deprecated('Use limit() instead') int limit = 0}) {

objectbox/lib/src/query/builder.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
part of query;
22

3-
// Construct a tree from the first condition object
3+
/// Query builder allows creating reusable queries.
44
class QueryBuilder<T> extends _QueryBuilder<T> {
5+
/// Start creating a query.
56
QueryBuilder(Store store, EntityDefinition<T> entity, Condition /*?*/ qc)
67
: super(
78
store, entity, qc, C.query_builder(store.ptr, entity.model.id.id));
89

10+
/// Finish building a [Query]. Call [Query.close()] after you're done with it
11+
/// to free resources.
912
Query<T> build() {
1013
_applyCondition();
1114

@@ -16,6 +19,8 @@ class QueryBuilder<T> extends _QueryBuilder<T> {
1619
}
1720
}
1821

22+
/// Configure how the results are ordered.
23+
/// Pass a combination of [Order] flags.
1924
QueryBuilder<T> order(QueryProperty p, {int flags = 0}) {
2025
_throwIfOtherEntity(p._entityId);
2126
checkObx(C.qb_order(_cBuilder, p._propertyId, flags));

objectbox/lib/src/query/property.dart

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
part of query;
22

3+
/// Property query base
34
abstract class PropertyQuery<T> {
45
final Pointer<OBX_query_prop> _cProp;
56
final int _type;
67
bool _distinct = false;
78

8-
PropertyQuery(Pointer<OBX_query> cQuery, int propertyId, this._type)
9+
PropertyQuery._(Pointer<OBX_query> cQuery, int propertyId, this._type)
910
: _cProp =
1011
checkObxPtr(C.query_prop(cQuery, propertyId), 'property query');
1112

@@ -15,10 +16,12 @@ abstract class PropertyQuery<T> {
1516
/// Set [replaceNullWith] to return null values as that value.
1617
List<T> find({T /*?*/ replaceNullWith});
1718

19+
/// Close the property query, freeing its resources
1820
void close() {
1921
checkObx(C.query_prop_close(_cProp));
2022
}
2123

24+
/// Get the status of "distinct-values" configuration.
2225
bool get distinct => _distinct;
2326

2427
/// Set to only return distinct values.
@@ -62,6 +65,7 @@ abstract class PropertyQuery<T> {
6265

6366
/// shared implementation, hence mixin
6467
mixin _CommonNumeric<T> on PropertyQuery<T> {
68+
/// Average value of the property over all objects matching the query.
6569
double average() {
6670
final ptr = allocate<Double>();
6771
try {
@@ -73,9 +77,10 @@ mixin _CommonNumeric<T> on PropertyQuery<T> {
7377
}
7478
}
7579

80+
/// "Property query" for an integer field. Created by [Query.property()].
7681
class IntegerPropertyQuery extends PropertyQuery<int> with _CommonNumeric {
77-
IntegerPropertyQuery(Pointer<OBX_query> query, int propertyId, int obxType)
78-
: super(query, propertyId, obxType);
82+
IntegerPropertyQuery._(Pointer<OBX_query> query, int propertyId, int obxType)
83+
: super._(query, propertyId, obxType);
7984

8085
int _op(
8186
int Function(Pointer<OBX_query_prop>, Pointer<Int64>, Pointer<Int64>)
@@ -89,10 +94,13 @@ class IntegerPropertyQuery extends PropertyQuery<int> with _CommonNumeric {
8994
}
9095
}
9196

97+
/// Minimum value of the property over all objects matching the query.
9298
int min() => _op(C.query_prop_min_int);
9399

100+
/// Maximum value of the property over all objects matching the query.
94101
int max() => _op(C.query_prop_max_int);
95102

103+
/// Sum of all property values over objects matching the query.
96104
int sum() => _op(C.query_prop_sum_int);
97105

98106
@override
@@ -143,9 +151,10 @@ class IntegerPropertyQuery extends PropertyQuery<int> with _CommonNumeric {
143151
}
144152
}
145153

154+
/// "Property query" for a double field. Created by [Query.property()].
146155
class DoublePropertyQuery extends PropertyQuery<double> with _CommonNumeric {
147-
DoublePropertyQuery(Pointer<OBX_query> query, int propertyId, int obxType)
148-
: super(query, propertyId, obxType);
156+
DoublePropertyQuery._(Pointer<OBX_query> query, int propertyId, int obxType)
157+
: super._(query, propertyId, obxType);
149158

150159
double _op(
151160
int Function(Pointer<OBX_query_prop>, Pointer<Double>, Pointer<Int64>)
@@ -159,10 +168,13 @@ class DoublePropertyQuery extends PropertyQuery<double> with _CommonNumeric {
159168
}
160169
}
161170

171+
/// Minimum value of the property over all objects matching the query.
162172
double min() => _op(C.query_prop_min);
163173

174+
/// Maximum value of the property over all objects matching the query.
164175
double max() => _op(C.query_prop_max);
165176

177+
/// Sum of all property values over objects matching the query.
166178
double sum() => _op(C.query_prop_sum);
167179

168180
@override
@@ -193,11 +205,12 @@ class DoublePropertyQuery extends PropertyQuery<double> with _CommonNumeric {
193205
}
194206
}
195207

208+
/// "Property query" for a string field. Created by [Query.property()].
196209
class StringPropertyQuery extends PropertyQuery<String> {
197210
bool _caseSensitive = false;
198211

199-
StringPropertyQuery(Pointer<OBX_query> query, int propertyId, int obxType)
200-
: super(query, propertyId, obxType);
212+
StringPropertyQuery._(Pointer<OBX_query> query, int propertyId, int obxType)
213+
: super._(query, propertyId, obxType);
201214

202215
/// Set to return case sensitive distinct values.
203216
///
@@ -207,6 +220,7 @@ class StringPropertyQuery extends PropertyQuery<String> {
207220
checkObx(C.query_prop_distinct_case(_cProp, _distinct, _caseSensitive));
208221
}
209222

223+
/// Get status of the case-sensitive configuration.
210224
bool get caseSensitive => _caseSensitive;
211225

212226
@override

objectbox/lib/src/query/query.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import '../store.dart';
1515
import '../transaction.dart';
1616

1717
part 'builder.dart';
18-
1918
part 'property.dart';
2019

20+
// ignore_for_file: public_member_api_docs
21+
22+
/// Groups query order flags.
2123
class Order {
2224
/// Reverts the order from ascending (default) to descending.
2325
static final descending = 1;
@@ -64,7 +66,7 @@ class QueryStringProperty extends QueryProperty {
6466
_StringCondition(cop, this, p, null, caseSensitive: caseSensitive);
6567

6668
Condition _opList(List<String> list, _ConditionOp cop,
67-
{/*required*/ bool caseSensitive}) =>
69+
{/*required*/ bool caseSensitive}) =>
6870
_StringListCondition(cop, this, list, caseSensitive: caseSensitive);
6971

7072
Condition equals(String p, {bool caseSensitive = false}) =>
@@ -382,7 +384,7 @@ class _StringListCondition extends _PropertyCondition<List<String>> {
382384
final bool _caseSensitive;
383385

384386
_StringListCondition(_ConditionOp op, QueryProperty prop, List<String> value,
385-
{/*required*/ bool caseSensitive})
387+
{/*required*/ bool caseSensitive})
386388
: _caseSensitive = caseSensitive,
387389
super(op, prop, value);
388390

@@ -612,7 +614,7 @@ class _ConditionGroupAll extends _ConditionGroup {
612614

613615
/// A repeatable Query returning the latest matching Objects.
614616
///
615-
/// Use [find] or related methods to fetch the latest results from the BoxStore.
617+
/// Use [find] or related methods to fetch the latest results from the Box.
616618
///
617619
/// Use [property] to only return values or an aggregate of a single Property.
618620
class Query<T> {
@@ -755,12 +757,12 @@ class Query<T> {
755757
/// ```
756758
PQ property<PQ extends PropertyQuery<dynamic>>(QueryProperty qp) {
757759
if (OBXPropertyType.Bool <= qp._type && qp._type <= OBXPropertyType.Long) {
758-
return IntegerPropertyQuery(_cQuery, qp._propertyId, qp._type) as PQ;
760+
return IntegerPropertyQuery._(_cQuery, qp._propertyId, qp._type) as PQ;
759761
} else if (OBXPropertyType.Float == qp._type ||
760762
qp._type == OBXPropertyType.Double) {
761-
return DoublePropertyQuery(_cQuery, qp._propertyId, qp._type) as PQ;
763+
return DoublePropertyQuery._(_cQuery, qp._propertyId, qp._type) as PQ;
762764
} else if (OBXPropertyType.String == qp._type) {
763-
return StringPropertyQuery(_cQuery, qp._propertyId, qp._type) as PQ;
765+
return StringPropertyQuery._(_cQuery, qp._propertyId, qp._type) as PQ;
764766
} else {
765767
throw Exception(
766768
'Property query: unsupported type (OBXPropertyType: ${qp._type})');

0 commit comments

Comments
 (0)