Documentation ¶
Index ¶
- Variables
- func ObjectBoxModel() *objectbox.Model
- type Task
- type TaskAsyncBox
- type TaskBox
- func (box *TaskBox) Async() *TaskAsyncBox
- func (box *TaskBox) Get(id uint64) (*Task, error)
- func (box *TaskBox) GetAll() ([]*Task, error)
- func (box *TaskBox) GetMany(ids ...uint64) ([]*Task, error)
- func (box *TaskBox) GetManyExisting(ids ...uint64) ([]*Task, error)
- func (box *TaskBox) Insert(object *Task) (uint64, error)
- func (box *TaskBox) Put(object *Task) (uint64, error)
- func (box *TaskBox) PutAsync(object *Task) (uint64, error)
- func (box *TaskBox) PutMany(objects []*Task) ([]uint64, error)
- func (box *TaskBox) Query(conditions ...objectbox.Condition) *TaskQuery
- func (box *TaskBox) QueryOrError(conditions ...objectbox.Condition) (*TaskQuery, error)
- func (box *TaskBox) Remove(object *Task) error
- func (box *TaskBox) RemoveMany(objects ...*Task) (uint64, error)
- func (box *TaskBox) Update(object *Task) error
- type TaskQuery
Constants ¶
This section is empty.
Variables ¶
var TaskBinding = task_EntityInfo{ Entity: objectbox.Entity{ Id: 1, }, Uid: 6645479796472661392, }
var Task_ = struct { Id *objectbox.PropertyUint64 Text *objectbox.PropertyString DateCreated *objectbox.PropertyInt64 DateFinished *objectbox.PropertyInt64 }{ Id: &objectbox.PropertyUint64{ BaseProperty: &objectbox.BaseProperty{ Id: 1, Entity: &TaskBinding.Entity, }, }, Text: &objectbox.PropertyString{ BaseProperty: &objectbox.BaseProperty{ Id: 2, Entity: &TaskBinding.Entity, }, }, DateCreated: &objectbox.PropertyInt64{ BaseProperty: &objectbox.BaseProperty{ Id: 4, Entity: &TaskBinding.Entity, }, }, DateFinished: &objectbox.PropertyInt64{ BaseProperty: &objectbox.BaseProperty{ Id: 5, Entity: &TaskBinding.Entity, }, }, }
Task_ contains type-based Property helpers to facilitate some common operations such as Queries.
Functions ¶
func ObjectBoxModel ¶
ObjectBoxModel declares and builds the model from all the entities in the package. It is usually used when setting-up ObjectBox as an argument to the Builder.Model() function.
Types ¶
type Task ¶
type Task struct { Id uint64 Text string DateCreated time.Time `objectbox:"date"` // DateFinished is initially set to unix epoch (value 0 in ObjectBox DB) to tag the task as "unfinished" DateFinished time.Time `objectbox:"date"` }
Put this on a new line to enable sync: // `objectbox:"sync"`
type TaskAsyncBox ¶ added in v1.1.0
TaskAsyncBox provides asynchronous operations on Task objects.
Asynchronous operations are executed on a separate internal thread for better performance.
There are two main use cases:
1) "execute & forget:" you gain faster put/remove operations as you don't have to wait for the transaction to finish.
2) Many small transactions: if your write load is typically a lot of individual puts that happen in parallel, this will merge small transactions into bigger ones. This results in a significant gain in overall throughput.
In situations with (extremely) high async load, an async method may be throttled (~1ms) or delayed up to 1 second. In the unlikely event that the object could still not be enqueued (full queue), an error will be returned.
Note that async methods do not give you hard durability guarantees like the synchronous Box provides. There is a small time window in which the data may not have been committed durably yet.
func AsyncBoxForTask ¶ added in v1.1.0
func AsyncBoxForTask(ob *objectbox.ObjectBox, timeoutMs uint64) *TaskAsyncBox
AsyncBoxForTask creates a new async box with the given operation timeout in case an async queue is full. The returned struct must be freed explicitly using the Close() method. It's usually preferable to use TaskBox::Async() which takes care of resource management and doesn't require closing.
func (*TaskAsyncBox) Insert ¶ added in v1.1.0
func (asyncBox *TaskAsyncBox) Insert(object *Task) (id uint64, err error)
Insert a single object asynchronously. The Id property on the passed object will be assigned the new ID the entity would hold if the insert is ultimately successful. The newly assigned ID may not become valid if the insert fails. Fails silently if an object with the same ID already exists (this error is not returned).
func (*TaskAsyncBox) Put ¶ added in v1.1.0
func (asyncBox *TaskAsyncBox) Put(object *Task) (uint64, error)
Put inserts/updates a single object asynchronously. When inserting a new object, the Id property on the passed object will be assigned the new ID the entity would hold if the insert is ultimately successful. The newly assigned ID may not become valid if the insert fails.
func (*TaskAsyncBox) Remove ¶ added in v1.1.0
func (asyncBox *TaskAsyncBox) Remove(object *Task) error
Remove deletes a single object asynchronously.
func (*TaskAsyncBox) Update ¶ added in v1.1.0
func (asyncBox *TaskAsyncBox) Update(object *Task) error
Update a single object asynchronously. The object must already exists or the update fails silently (without an error returned).
type TaskBox ¶
Box provides CRUD access to Task objects
func BoxForTask ¶
BoxForTask opens a box of Task objects
func (*TaskBox) Async ¶ added in v1.1.0
func (box *TaskBox) Async() *TaskAsyncBox
Async provides access to the default Async Box for asynchronous operations. See TaskAsyncBox for more information.
func (*TaskBox) Get ¶
Get reads a single object.
Returns nil (and no error) in case the object with the given ID doesn't exist.
func (*TaskBox) GetMany ¶ added in v1.0.0
GetMany reads multiple objects at once. If any of the objects doesn't exist, its position in the return slice is nil
func (*TaskBox) GetManyExisting ¶ added in v1.1.0
GetManyExisting reads multiple objects at once, skipping those that do not exist.
func (*TaskBox) Insert ¶ added in v1.1.0
Insert synchronously inserts a single object. As opposed to Put, Insert will fail if given an ID that already exists. In case the Id is not specified, it would be assigned automatically (auto-increment). When inserting, the Task.Id property on the passed object will be assigned the new ID as well.
func (*TaskBox) Put ¶ added in v0.7.0
Put synchronously inserts/updates a single object. In case the Id is not specified, it would be assigned automatically (auto-increment). When inserting, the Task.Id property on the passed object will be assigned the new ID as well.
func (*TaskBox) PutAsync ¶ added in v0.7.0
PutAsync asynchronously inserts/updates a single object. Deprecated: use box.Async().Put() instead
func (*TaskBox) PutMany ¶ added in v1.0.0
PutMany inserts multiple objects in single transaction. In case Ids are not set on the objects, they would be assigned automatically (auto-increment).
Returns: IDs of the put objects (in the same order). When inserting, the Task.Id property on the objects in the slice will be assigned the new IDs as well.
Note: In case an error occurs during the transaction, some of the objects may already have the Task.Id assigned even though the transaction has been rolled back and the objects are not stored under those IDs.
Note: The slice may be empty or even nil; in both cases, an empty IDs slice and no error is returned.
func (*TaskBox) Query ¶ added in v0.8.0
Creates a query with the given conditions. Use the fields of the Task_ struct to create conditions. Keep the *TaskQuery if you intend to execute the query multiple times. Note: this function panics if you try to create illegal queries; e.g. use properties of an alien type. This is typically a programming error. Use QueryOrError instead if you want the explicit error check.
func (*TaskBox) QueryOrError ¶ added in v0.8.0
Creates a query with the given conditions. Use the fields of the Task_ struct to create conditions. Keep the *TaskQuery if you intend to execute the query multiple times.
func (*TaskBox) RemoveMany ¶ added in v1.0.0
RemoveMany deletes multiple objects at once. Returns the number of deleted object or error on failure. Note that this method will not fail if an object is not found (e.g. already removed). In case you need to strictly check whether all of the objects exist before removing them, you can execute multiple box.Contains() and box.Remove() inside a single write transaction.
type TaskQuery ¶ added in v0.8.0
Query provides a way to search stored objects
For example, you can find all Task which Id is either 42 or 47:
box.Query(Task_.Id.In(42, 47)).Find()