11import '../objectbox.dart' ;
22
3- /// Entity annotation is used on a class to let ObjectBox know it should store
4- /// it - making the class a "persistable Entity".
5- ///
6- /// This annotation is matched by ObjectBox code generator when you call
7- /// `pub run_build_runner build` . The generator creates `objectbox.g.dart` with
8- /// all the binding code necessary to store the class in the database.
3+ /// See [Entity.new] .
94class Entity {
105 /// ObjectBox keeps track of entities and properties by assigning them unique
116 /// identifiers, UIDs, during the code-generation phase. All those UIDs are
@@ -32,21 +27,12 @@ class Entity {
3227 /// ```
3328 final Type ? realClass;
3429
35- /// Create an Entity annotation.
30+ /// Marks a class as an ObjectBox Entity. Allows to obtain a [Box] for this
31+ /// Entity from [Store] to persist instances (objects) of this class.
3632 const Entity ({this .uid, this .realClass});
3733}
3834
39- /// Use to (optionally) annotate a field to explicitly configure some details
40- /// about how a field is stored in the database.
41- ///
42- /// For example:
43- /// ```
44- /// // Store int as a byte (8-bit integer)
45- /// @Property(type: PropertyType.byte)
46- /// int? byteValue;
47- /// ```
48- /// See [the online docs] (https://docs.objectbox.io/advanced/custom-types) for
49- /// details.
35+ /// See [Property.new] .
5036class Property {
5137 /// ObjectBox keeps track of entities and properties by assigning them unique
5238 /// identifiers, UIDs, during the code-generation phase. All those UIDs are
@@ -83,7 +69,18 @@ class Property {
8369 /// executing queries or creating indexes. Defaults to `true` .
8470 final bool signed;
8571
86- /// See [Property] .
72+ /// Optionally configures how a field is stored in the database.
73+ ///
74+ /// For example:
75+ ///
76+ /// ```
77+ /// // Store int as a byte (8-bit integer)
78+ /// @Property(type: PropertyType.byte)
79+ /// int? byteValue;
80+ /// ```
81+ ///
82+ /// Learn more about customizing the database type of a property in the
83+ /// [online documentation] (https://docs.objectbox.io/advanced/custom-types).
8784 const Property ({this .type, this .uid, this .signed = true });
8885}
8986
@@ -179,8 +176,7 @@ enum PropertyType {
179176 // stringVector
180177}
181178
182- /// Annotation Id can be used to specify an entity ID property if it's named
183- /// anything else then "id" (case insensitive).
179+ /// See [Id.new] .
184180class Id {
185181 /// When you put a new object you don't assign an ID by default, it's assigned
186182 /// automatically by ObjectBox. If you need to assign IDs by yourself, use the
@@ -192,13 +188,17 @@ class Id {
192188 /// telling which objects are new and which are already saved.
193189 final bool assignable;
194190
195- /// Create an Id annotation.
191+ /// Marks the ID property of an [Entity] . The property must be of type [int] ,
192+ /// be non-final and have not-private visibility (or a not-private getter and
193+ /// setter method).
194+ ///
195+ /// ID properties are unique and indexed by default.
196196 const Id ({this .assignable = false });
197197}
198198
199- /// Transient annotation marks fields that should not be stored in the database .
199+ /// See [Transient.new] .
200200class Transient {
201- /// Create a Transient annotation .
201+ /// Marks that a field should not be stored in the database .
202202 const Transient ();
203203}
204204
@@ -208,19 +208,19 @@ class Transient {
208208// const Sync();
209209// }
210210
211- /// Specifies that the property should be indexed.
212- ///
213- /// It is highly recommended to index properties that are used in a Query to
214- /// improve query performance. To fine tune indexing of a property you can
215- /// override the default index type.
216- ///
217- /// Note: indexes are currently not supported for ByteVector, Float or Double
218- /// properties.
211+ /// See [Index.new] .
219212class Index {
220213 /// Index type.
221214 final IndexType ? type;
222215
223- /// Create an Index annotation.
216+ /// Specifies that the property should be indexed.
217+ ///
218+ /// It is highly recommended to index properties that are used in a Query to
219+ /// improve query performance. To fine tune indexing of a property you can
220+ /// override the default index type.
221+ ///
222+ /// Note: indexes are currently not supported for [PropertyType.byteVector] ,
223+ /// [PropertyType.float] or [PropertyType.double] properties.
224224 const Index ({this .type});
225225}
226226
@@ -250,21 +250,21 @@ enum IndexType {
250250 hash64,
251251}
252252
253- /// Enforces that the value of a property is unique among all objects in a box
254- /// before an object can be put.
255- ///
256- /// Trying to put an object with offending values will result in a
257- /// [UniqueViolationException] (see [ConflictStrategy.fail] ).
258- /// Set [onConflict] to change this strategy.
259- ///
260- /// Note: Unique properties are based on an [Index] , so the same restrictions
261- /// apply. It is supported to explicitly add the [Index] annotation to configure
262- /// the index.
253+ /// See [Unique.new] .
263254class Unique {
264255 /// The strategy to use when a conflict is detected when an object is put.
265256 final ConflictStrategy onConflict;
266257
267- /// Create a Unique annotation.
258+ /// Enforces that the value of a property is unique among all objects in a Box
259+ /// before an object can be put.
260+ ///
261+ /// Trying to put an object with offending values will result in a
262+ /// [UniqueViolationException] (see [ConflictStrategy.fail] ).
263+ /// Set [onConflict] to change this strategy.
264+ ///
265+ /// Note: Unique properties are based on an [Index] , so the same restrictions
266+ /// apply. It is supported to explicitly add the [Index] annotation to
267+ /// configure the index.
268268 const Unique ({this .onConflict = ConflictStrategy .fail});
269269}
270270
@@ -278,41 +278,50 @@ enum ConflictStrategy {
278278 replace,
279279}
280280
281- /// Backlink annotation specifies a link in a reverse direction of another
282- /// relation.
283- ///
284- /// This works as an "updatable view" of the original relation, and doesn't
285- /// cause any more data to be stored in the database. Changes made to the
286- /// backlink relation are reflected in the original direction.
287- ///
288- /// Example - backlink based on a [ToOne] relation:
289- /// ```dart
290- /// class Order {
291- /// final customer = ToOne<Customer>();
292- /// }
293- /// class Customer {
294- /// @Backlink()
295- /// final orders = ToMany<Customer>();
296- /// }
297- /// ```
298- ///
299- /// Example - backlink based on a [ToMany] relation:
300- /// ```dart
301- /// class Student {
302- /// final teachers = ToMany<Teacher>();
303- /// }
304- /// class Teacher {
305- /// @Backlink()
306- /// final students = ToMany<Student>();
307- /// }
308- /// ```
281+ /// See [Backlink.new] .
309282class Backlink {
310- /// Target entity to which this backlink points. It's the entity that contains
311- /// a [ToOne] or [ToMany] relation pointing to the current entity.
283+ /// Name of the relation the backlink should be based on (e.g. name of a
284+ /// [ToOne] or [ToMany] property in the target entity). Can be left empty if
285+ /// there is just a single relation from the target to the source entity.
312286 final String to;
313287
314- /// If there are multiple relations pointing to the current entity, specify
315- /// the field name of the desired source relation: Backlink('sourceField').
288+ /// Defines a backlink relation, which is based on another relation reversing
289+ /// the direction.
290+ ///
291+ /// Pass the name of the relation the backlink should be based on (e.g. name
292+ /// of a [ToOne] or [ToMany] property in the target entity). Can be left empty
293+ /// if there is just a single relation from the target to the source entity.
294+ ///
295+ /// This works as an "updatable view" of the original relation, and doesn't
296+ /// cause any more data to be stored in the database. Changes made to the
297+ /// backlink relation are reflected in the original direction.
298+ ///
299+ /// Example ([ToOne] relation): one "Order" references one "Customer".
300+ /// The backlink to this is a to-many in the reverse direction: one "Customer"
301+ /// has a number of "Order"s.
302+ ///
303+ /// ```dart
304+ /// class Order {
305+ /// final customer = ToOne<Customer>();
306+ /// }
307+ /// class Customer {
308+ /// @Backlink()
309+ /// final orders = ToMany<Customer>();
310+ /// }
311+ /// ```
312+ ///
313+ /// Example ([ToMany] relation): one "Student" references multiple "Teacher"s.
314+ /// The backlink to this: one "Teacher" has a number of "Student"s.
315+ ///
316+ /// ```dart
317+ /// class Student {
318+ /// final teachers = ToMany<Teacher>();
319+ /// }
320+ /// class Teacher {
321+ /// @Backlink()
322+ /// final students = ToMany<Student>();
323+ /// }
324+ /// ```
316325 const Backlink ([this .to = '' ]);
317326}
318327
0 commit comments