model

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TaskBinding = task_EntityInfo{
	Entity: objectbox.Entity{
		Id: 1,
	},
	Uid: 1306759095002958910,
}
View Source
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:     3,
			Entity: &TaskBinding.Entity,
		},
	},
	DateFinished: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     4,
			Entity: &TaskBinding.Entity,
		},
	},
}

Task_ contains type-based Property helpers to facilitate some common operations such as Queries.

Functions

func ObjectBoxModel

func ObjectBoxModel() *objectbox.Model

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  int64
	DateFinished int64
}

type TaskBox

type TaskBox struct {
	*objectbox.Box
}

Box provides CRUD access to Task objects

func BoxForTask

func BoxForTask(ob *objectbox.ObjectBox) *TaskBox

BoxForTask opens a box of Task objects

func (*TaskBox) Get

func (box *TaskBox) Get(id uint64) (*Task, error)

Get reads a single object.

Returns nil (and no error) in case the object with the given ID doesn't exist.

func (*TaskBox) GetAll

func (box *TaskBox) GetAll() ([]*Task, error)

GetAll reads all stored objects

func (*TaskBox) GetMany added in v1.0.0

func (box *TaskBox) GetMany(ids ...uint64) ([]*Task, error)

GetMany reads multiple objects at once. If any of the objects doesn't exist, its position in the return slice is nil

func (*TaskBox) Put added in v0.7.0

func (box *TaskBox) Put(object *Task) (uint64, error)

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

func (box *TaskBox) PutAsync(object *Task) (uint64, error)

PutAsync asynchronously inserts/updates a single object. When inserting, the Task.Id property on the passed object will be assigned the new ID as well.

It's executed on a separate internal thread for better performance.

There are two main use cases:

1) "Put & Forget:" you gain faster puts 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, this method may be throttled (~1ms) or delayed (<1s). In the unlikely event that the object could not be enqueued after delaying, an error will be returned.

Note that this method does not give you hard durability guarantees like the synchronous Put provides. There is a small time window (typically 3 ms) in which the data may not have been committed durably yet.

func (*TaskBox) PutMany added in v1.0.0

func (box *TaskBox) PutMany(objects []*Task) ([]uint64, error)

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

func (box *TaskBox) Query(conditions ...objectbox.Condition) *TaskQuery

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

func (box *TaskBox) QueryOrError(conditions ...objectbox.Condition) (*TaskQuery, error)

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) Remove

func (box *TaskBox) Remove(object *Task) error

Remove deletes a single object

func (*TaskBox) RemoveMany added in v1.0.0

func (box *TaskBox) RemoveMany(objects ...*Task) (uint64, error)

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

type TaskQuery struct {
	*objectbox.Query
}

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()

func (*TaskQuery) Find added in v0.8.0

func (query *TaskQuery) Find() ([]*Task, error)

Find returns all objects matching the query

func (*TaskQuery) Limit added in v0.9.0

func (query *TaskQuery) Limit(limit uint64) *TaskQuery

Limit sets the number of elements to process by the query

func (*TaskQuery) Offset added in v0.9.0

func (query *TaskQuery) Offset(offset uint64) *TaskQuery

Offset defines the index of the first object to process (how many objects to skip)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL