model

package
v0.0.0-...-2c67603 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DailyBinding = daily_EntityInfo{
	Entity: objectbox.Entity{
		Id: 2,
	},
	Uid: 5404728982931877369,
}
View Source
var Daily_ = struct {
	Id             *objectbox.PropertyInt64
	Date           *objectbox.PropertyInt64
	ProductionkWh  *objectbox.PropertyFloat64
	ConsumptionkWh *objectbox.PropertyFloat64
}{
	Id: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     1,
			Entity: &DailyBinding.Entity,
		},
	},
	Date: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     2,
			Entity: &DailyBinding.Entity,
		},
	},
	ProductionkWh: &objectbox.PropertyFloat64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     3,
			Entity: &DailyBinding.Entity,
		},
	},
	ConsumptionkWh: &objectbox.PropertyFloat64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     4,
			Entity: &DailyBinding.Entity,
		},
	},
}

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

View Source
var SampleBinding = sample_EntityInfo{
	Entity: objectbox.Entity{
		Id: 1,
	},
	Uid: 2567227502353939271,
}
View Source
var Sample_ = struct {
	Id           *objectbox.PropertyInt64
	Date         *objectbox.PropertyInt64
	ProductionW  *objectbox.PropertyFloat64
	ConsumptionW *objectbox.PropertyFloat64
	NetW         *objectbox.PropertyFloat64
}{
	Id: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     1,
			Entity: &SampleBinding.Entity,
		},
	},
	Date: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     2,
			Entity: &SampleBinding.Entity,
		},
	},
	ProductionW: &objectbox.PropertyFloat64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     3,
			Entity: &SampleBinding.Entity,
		},
	},
	ConsumptionW: &objectbox.PropertyFloat64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     4,
			Entity: &SampleBinding.Entity,
		},
	},
	NetW: &objectbox.PropertyFloat64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     5,
			Entity: &SampleBinding.Entity,
		},
	},
}

Sample_ 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 Daily

type Daily struct {
	Id             int64     `objectbox:"id(assignable)","unique"`
	Date           time.Time `objectbox:"date"`
	ProductionkWh  float64
	ConsumptionkWh float64
}

type DailyAsyncBox

type DailyAsyncBox struct {
	*objectbox.AsyncBox
}

DailyAsyncBox provides asynchronous operations on Daily 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 AsyncBoxForDaily

func AsyncBoxForDaily(ob *objectbox.ObjectBox, timeoutMs uint64) *DailyAsyncBox

AsyncBoxForDaily 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 DailyBox::Async() which takes care of resource management and doesn't require closing.

func (*DailyAsyncBox) Insert

func (asyncBox *DailyAsyncBox) Insert(object *Daily) (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 (*DailyAsyncBox) Put

func (asyncBox *DailyAsyncBox) Put(object *Daily) (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 (*DailyAsyncBox) Remove

func (asyncBox *DailyAsyncBox) Remove(object *Daily) error

Remove deletes a single object asynchronously.

func (*DailyAsyncBox) Update

func (asyncBox *DailyAsyncBox) Update(object *Daily) error

Update a single object asynchronously. The object must already exists or the update fails silently (without an error returned).

type DailyBox

type DailyBox struct {
	*objectbox.Box
}

Box provides CRUD access to Daily objects

func BoxForDaily

func BoxForDaily(ob *objectbox.ObjectBox) *DailyBox

BoxForDaily opens a box of Daily objects

func (*DailyBox) Async

func (box *DailyBox) Async() *DailyAsyncBox

Async provides access to the default Async Box for asynchronous operations. See DailyAsyncBox for more information.

func (*DailyBox) Get

func (box *DailyBox) Get(id uint64) (*Daily, error)

Get reads a single object.

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

func (*DailyBox) GetAll

func (box *DailyBox) GetAll() ([]*Daily, error)

GetAll reads all stored objects

func (*DailyBox) GetMany

func (box *DailyBox) GetMany(ids ...uint64) ([]*Daily, error)

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

func (*DailyBox) GetManyExisting

func (box *DailyBox) GetManyExisting(ids ...uint64) ([]*Daily, error)

GetManyExisting reads multiple objects at once, skipping those that do not exist.

func (*DailyBox) Insert

func (box *DailyBox) Insert(object *Daily) (uint64, error)

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 Daily.Id property on the passed object will be assigned the new ID as well.

func (*DailyBox) Put

func (box *DailyBox) Put(object *Daily) (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 Daily.Id property on the passed object will be assigned the new ID as well.

func (*DailyBox) PutAsync

func (box *DailyBox) PutAsync(object *Daily) (uint64, error)

PutAsync asynchronously inserts/updates a single object. Deprecated: use box.Async().Put() instead

func (*DailyBox) PutMany

func (box *DailyBox) PutMany(objects []*Daily) ([]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 Daily.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 Daily.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 (*DailyBox) Query

func (box *DailyBox) Query(conditions ...objectbox.Condition) *DailyQuery

Creates a query with the given conditions. Use the fields of the Daily_ struct to create conditions. Keep the *DailyQuery 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 (*DailyBox) QueryOrError

func (box *DailyBox) QueryOrError(conditions ...objectbox.Condition) (*DailyQuery, error)

Creates a query with the given conditions. Use the fields of the Daily_ struct to create conditions. Keep the *DailyQuery if you intend to execute the query multiple times.

func (*DailyBox) Remove

func (box *DailyBox) Remove(object *Daily) error

Remove deletes a single object

func (*DailyBox) RemoveMany

func (box *DailyBox) RemoveMany(objects ...*Daily) (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.

func (*DailyBox) Update

func (box *DailyBox) Update(object *Daily) error

Update synchronously updates a single object. As opposed to Put, Update will fail if an object with the same ID is not found in the database.

type DailyQuery

type DailyQuery struct {
	*objectbox.Query
}

Query provides a way to search stored objects

For example, you can find all Daily which Id is either 42 or 47:

box.Query(Daily_.Id.In(42, 47)).Find()

func (*DailyQuery) Find

func (query *DailyQuery) Find() ([]*Daily, error)

Find returns all objects matching the query

func (*DailyQuery) Limit

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

Limit sets the number of elements to process by the query

func (*DailyQuery) Offset

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

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

type Sample

type Sample struct {
	Id           int64 `objectbox:"id"`
	Date         int64
	ProductionW  float64
	ConsumptionW float64
	NetW         float64
}

next schema change convert Date to time.Time `objectbox:"date"`

type SampleAsyncBox

type SampleAsyncBox struct {
	*objectbox.AsyncBox
}

SampleAsyncBox provides asynchronous operations on Sample 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 AsyncBoxForSample

func AsyncBoxForSample(ob *objectbox.ObjectBox, timeoutMs uint64) *SampleAsyncBox

AsyncBoxForSample 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 SampleBox::Async() which takes care of resource management and doesn't require closing.

func (*SampleAsyncBox) Insert

func (asyncBox *SampleAsyncBox) Insert(object *Sample) (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 (*SampleAsyncBox) Put

func (asyncBox *SampleAsyncBox) Put(object *Sample) (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 (*SampleAsyncBox) Remove

func (asyncBox *SampleAsyncBox) Remove(object *Sample) error

Remove deletes a single object asynchronously.

func (*SampleAsyncBox) Update

func (asyncBox *SampleAsyncBox) Update(object *Sample) error

Update a single object asynchronously. The object must already exists or the update fails silently (without an error returned).

type SampleBox

type SampleBox struct {
	*objectbox.Box
}

Box provides CRUD access to Sample objects

func BoxForSample

func BoxForSample(ob *objectbox.ObjectBox) *SampleBox

BoxForSample opens a box of Sample objects

func (*SampleBox) Async

func (box *SampleBox) Async() *SampleAsyncBox

Async provides access to the default Async Box for asynchronous operations. See SampleAsyncBox for more information.

func (*SampleBox) Get

func (box *SampleBox) Get(id uint64) (*Sample, error)

Get reads a single object.

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

func (*SampleBox) GetAll

func (box *SampleBox) GetAll() ([]*Sample, error)

GetAll reads all stored objects

func (*SampleBox) GetMany

func (box *SampleBox) GetMany(ids ...uint64) ([]*Sample, error)

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

func (*SampleBox) GetManyExisting

func (box *SampleBox) GetManyExisting(ids ...uint64) ([]*Sample, error)

GetManyExisting reads multiple objects at once, skipping those that do not exist.

func (*SampleBox) Insert

func (box *SampleBox) Insert(object *Sample) (uint64, error)

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 Sample.Id property on the passed object will be assigned the new ID as well.

func (*SampleBox) Put

func (box *SampleBox) Put(object *Sample) (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 Sample.Id property on the passed object will be assigned the new ID as well.

func (*SampleBox) PutAsync

func (box *SampleBox) PutAsync(object *Sample) (uint64, error)

PutAsync asynchronously inserts/updates a single object. Deprecated: use box.Async().Put() instead

func (*SampleBox) PutMany

func (box *SampleBox) PutMany(objects []*Sample) ([]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 Sample.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 Sample.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 (*SampleBox) Query

func (box *SampleBox) Query(conditions ...objectbox.Condition) *SampleQuery

Creates a query with the given conditions. Use the fields of the Sample_ struct to create conditions. Keep the *SampleQuery 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 (*SampleBox) QueryOrError

func (box *SampleBox) QueryOrError(conditions ...objectbox.Condition) (*SampleQuery, error)

Creates a query with the given conditions. Use the fields of the Sample_ struct to create conditions. Keep the *SampleQuery if you intend to execute the query multiple times.

func (*SampleBox) Remove

func (box *SampleBox) Remove(object *Sample) error

Remove deletes a single object

func (*SampleBox) RemoveMany

func (box *SampleBox) RemoveMany(objects ...*Sample) (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.

func (*SampleBox) Update

func (box *SampleBox) Update(object *Sample) error

Update synchronously updates a single object. As opposed to Put, Update will fail if an object with the same ID is not found in the database.

type SampleQuery

type SampleQuery struct {
	*objectbox.Query
}

Query provides a way to search stored objects

For example, you can find all Sample which Id is either 42 or 47:

box.Query(Sample_.Id.In(42, 47)).Find()

func (*SampleQuery) Find

func (query *SampleQuery) Find() ([]*Sample, error)

Find returns all objects matching the query

func (*SampleQuery) Limit

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

Limit sets the number of elements to process by the query

func (*SampleQuery) Offset

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

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