// objectbox:entitybefore the type as an annotation for the code generator.
init(), and you're good to go:
Storebehaves much like a database connection: you keep the instance around to maintain an open connection to the data in a folder on disk. Usually for the lifetime of your app.
Boxinterface. For each object class, there is a matching
ObjectBox.Box<T>instance for its class from your
Store. Boxes are lightweight and can be discarded, but then you have to pass the
Storearound. You will almost always prefer to pass long-lived
Boxinstances around instead, for example in segues between
putto insert or update objects. When put succeeds, an ID will be assigned to the entity. There are
putvariants that support writing multiple objects at once, which is more efficient than writing each with its own call to
get. To get all objects of a type, use
removeAllto delete all objects and empty the box.
putAndReturnIDs()to get the ID a struct was written as:
put(struct:), which will automatically create a new copy of your struct with the ID filled out:
exampleEntity, you must use
newEntityfrom then on. If you called
put()on exampleEntity again, ObjectBox would not know that this object has already been saved, and would write a second copy of it to the database.
put(), just like above:
putruns an implicit transaction.
putvariant that takes an array of entities (like
put([person1, person2])) whenever possible to increase performance.
Storeexposes methods like
runInTransactionfor this purpose.