iot

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EventBinding = event_EntityInfo{
	Entity: objectbox.Entity{
		Id: 1,
	},
	Uid: 1468539308767086854,
}
View Source
var Event_ = struct {
	Id      *objectbox.PropertyUint64
	Device  *objectbox.PropertyString
	Date    *objectbox.PropertyInt64
	Uid     *objectbox.PropertyString
	Picture *objectbox.PropertyByteVector
}{
	Id: &objectbox.PropertyUint64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     1,
			Entity: &EventBinding.Entity,
		},
	},
	Device: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     2,
			Entity: &EventBinding.Entity,
		},
	},
	Date: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     3,
			Entity: &EventBinding.Entity,
		},
	},
	Uid: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     4,
			Entity: &EventBinding.Entity,
		},
	},
	Picture: &objectbox.PropertyByteVector{
		BaseProperty: &objectbox.BaseProperty{
			Id:     5,
			Entity: &EventBinding.Entity,
		},
	},
}

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

View Source
var ReadingBinding = reading_EntityInfo{
	Entity: objectbox.Entity{
		Id: 2,
	},
	Uid: 5284076134434938613,
}
View Source
var Reading_ = struct {
	Id              *objectbox.PropertyUint64
	Date            *objectbox.PropertyInt64
	EventId         *objectbox.RelationToOne
	ValueName       *objectbox.PropertyString
	ValueString     *objectbox.PropertyString
	ValueInteger    *objectbox.PropertyInt64
	ValueFloating   *objectbox.PropertyFloat64
	ValueInt32      *objectbox.PropertyInt32
	ValueFloating32 *objectbox.PropertyFloat32
}{
	Id: &objectbox.PropertyUint64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     1,
			Entity: &ReadingBinding.Entity,
		},
	},
	Date: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     2,
			Entity: &ReadingBinding.Entity,
		},
	},
	EventId: &objectbox.RelationToOne{
		Property: &objectbox.BaseProperty{
			Id:     3,
			Entity: &ReadingBinding.Entity,
		},
		Target: &EventBinding.Entity,
	},
	ValueName: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     4,
			Entity: &ReadingBinding.Entity,
		},
	},
	ValueString: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     5,
			Entity: &ReadingBinding.Entity,
		},
	},
	ValueInteger: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     6,
			Entity: &ReadingBinding.Entity,
		},
	},
	ValueFloating: &objectbox.PropertyFloat64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     7,
			Entity: &ReadingBinding.Entity,
		},
	},
	ValueInt32: &objectbox.PropertyInt32{
		BaseProperty: &objectbox.BaseProperty{
			Id:     8,
			Entity: &ReadingBinding.Entity,
		},
	},
	ValueFloating32: &objectbox.PropertyFloat32{
		BaseProperty: &objectbox.BaseProperty{
			Id:     9,
			Entity: &ReadingBinding.Entity,
		},
	},
}

Reading_ 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 Event

type Event struct {
	Id      uint64 `objectbox:"id"`
	Uid     string `objectbox:"unique"`
	Device  string
	Date    int64 `objectbox:"date"`
	Picture []byte
}

Event model

func PutEvent

func PutEvent(ob *objectbox.ObjectBox, device string, date int64) *Event

PutEvent creates an event

func PutEvents

func PutEvents(ob *objectbox.ObjectBox, count int) []*Event

PutEvents creates multiple events

type EventAsyncBox added in v1.1.0

type EventAsyncBox struct {
	*objectbox.AsyncBox
}

EventAsyncBox provides asynchronous operations on Event 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 AsyncBoxForEvent added in v1.1.0

func AsyncBoxForEvent(ob *objectbox.ObjectBox, timeoutMs uint64) *EventAsyncBox

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

func (*EventAsyncBox) Insert added in v1.1.0

func (asyncBox *EventAsyncBox) Insert(object *Event) (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 (*EventAsyncBox) Put added in v1.1.0

func (asyncBox *EventAsyncBox) Put(object *Event) (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 (*EventAsyncBox) Remove added in v1.1.0

func (asyncBox *EventAsyncBox) Remove(object *Event) error

Remove deletes a single object asynchronously.

func (*EventAsyncBox) Update added in v1.1.0

func (asyncBox *EventAsyncBox) Update(object *Event) error

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

type EventBox

type EventBox struct {
	*objectbox.Box
}

Box provides CRUD access to Event objects

func BoxForEvent

func BoxForEvent(ob *objectbox.ObjectBox) *EventBox

BoxForEvent opens a box of Event objects

func (*EventBox) Async added in v1.1.0

func (box *EventBox) Async() *EventAsyncBox

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

func (*EventBox) Get

func (box *EventBox) Get(id uint64) (*Event, error)

Get reads a single object.

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

func (*EventBox) GetAll

func (box *EventBox) GetAll() ([]*Event, error)

GetAll reads all stored objects

func (*EventBox) GetMany added in v1.0.0

func (box *EventBox) GetMany(ids ...uint64) ([]*Event, error)

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

func (*EventBox) GetManyExisting added in v1.1.0

func (box *EventBox) GetManyExisting(ids ...uint64) ([]*Event, error)

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

func (*EventBox) Insert added in v1.1.0

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

func (*EventBox) Put added in v0.7.0

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

func (*EventBox) PutAsync added in v0.7.0

func (box *EventBox) PutAsync(object *Event) (uint64, error)

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

func (*EventBox) PutMany added in v1.0.0

func (box *EventBox) PutMany(objects []*Event) ([]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 Event.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 Event.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 (*EventBox) Query added in v0.8.0

func (box *EventBox) Query(conditions ...objectbox.Condition) *EventQuery

Creates a query with the given conditions. Use the fields of the Event_ struct to create conditions. Keep the *EventQuery 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 (*EventBox) QueryOrError added in v0.8.0

func (box *EventBox) QueryOrError(conditions ...objectbox.Condition) (*EventQuery, error)

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

func (*EventBox) Remove

func (box *EventBox) Remove(object *Event) error

Remove deletes a single object

func (*EventBox) RemoveMany added in v1.0.0

func (box *EventBox) RemoveMany(objects ...*Event) (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 (*EventBox) Update added in v1.1.0

func (box *EventBox) Update(object *Event) 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 EventQuery added in v0.8.0

type EventQuery struct {
	*objectbox.Query
}

Query provides a way to search stored objects

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

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

func (*EventQuery) Find added in v0.8.0

func (query *EventQuery) Find() ([]*Event, error)

Find returns all objects matching the query

func (*EventQuery) Limit added in v0.9.0

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

Limit sets the number of elements to process by the query

func (*EventQuery) Offset added in v0.9.0

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

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

type Reading

type Reading struct {
	Id   uint64 `objectbox:"id"`
	Date int64  `objectbox:"date"`

	/// to-one relation
	EventId uint64 `objectbox:"link:Event"`

	ValueName string

	/// Device sensor data value
	ValueString string

	/// Device sensor data value
	ValueInteger int64

	/// Device sensor data value
	ValueFloating float64

	/// Device sensor data value
	ValueInt32 int32

	/// Device sensor data value
	ValueFloating32 float32
}

Reading model

func PutReading added in v0.7.0

func PutReading(ob *objectbox.ObjectBox, name string, ValueString string, ValueInteger int64, ValueFloating float64, ValueInt32 int32, ValueFloating32 float32) *Reading

PutReading creates a reading

func PutReadings added in v0.7.0

func PutReadings(ob *objectbox.ObjectBox, count int) []*Reading

PutReadings creates multiple readings

type ReadingAsyncBox added in v1.1.0

type ReadingAsyncBox struct {
	*objectbox.AsyncBox
}

ReadingAsyncBox provides asynchronous operations on Reading 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 AsyncBoxForReading added in v1.1.0

func AsyncBoxForReading(ob *objectbox.ObjectBox, timeoutMs uint64) *ReadingAsyncBox

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

func (*ReadingAsyncBox) Insert added in v1.1.0

func (asyncBox *ReadingAsyncBox) Insert(object *Reading) (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 (*ReadingAsyncBox) Put added in v1.1.0

func (asyncBox *ReadingAsyncBox) Put(object *Reading) (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 (*ReadingAsyncBox) Remove added in v1.1.0

func (asyncBox *ReadingAsyncBox) Remove(object *Reading) error

Remove deletes a single object asynchronously.

func (*ReadingAsyncBox) Update added in v1.1.0

func (asyncBox *ReadingAsyncBox) Update(object *Reading) error

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

type ReadingBox

type ReadingBox struct {
	*objectbox.Box
}

Box provides CRUD access to Reading objects

func BoxForReading

func BoxForReading(ob *objectbox.ObjectBox) *ReadingBox

BoxForReading opens a box of Reading objects

func (*ReadingBox) Async added in v1.1.0

func (box *ReadingBox) Async() *ReadingAsyncBox

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

func (*ReadingBox) Get

func (box *ReadingBox) Get(id uint64) (*Reading, error)

Get reads a single object.

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

func (*ReadingBox) GetAll

func (box *ReadingBox) GetAll() ([]*Reading, error)

GetAll reads all stored objects

func (*ReadingBox) GetMany added in v1.0.0

func (box *ReadingBox) GetMany(ids ...uint64) ([]*Reading, error)

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

func (*ReadingBox) GetManyExisting added in v1.1.0

func (box *ReadingBox) GetManyExisting(ids ...uint64) ([]*Reading, error)

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

func (*ReadingBox) Insert added in v1.1.0

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

func (*ReadingBox) Put added in v0.7.0

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

func (*ReadingBox) PutAsync added in v0.7.0

func (box *ReadingBox) PutAsync(object *Reading) (uint64, error)

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

func (*ReadingBox) PutMany added in v1.0.0

func (box *ReadingBox) PutMany(objects []*Reading) ([]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 Reading.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 Reading.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 (*ReadingBox) Query added in v0.8.0

func (box *ReadingBox) Query(conditions ...objectbox.Condition) *ReadingQuery

Creates a query with the given conditions. Use the fields of the Reading_ struct to create conditions. Keep the *ReadingQuery 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 (*ReadingBox) QueryOrError added in v0.8.0

func (box *ReadingBox) QueryOrError(conditions ...objectbox.Condition) (*ReadingQuery, error)

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

func (*ReadingBox) Remove

func (box *ReadingBox) Remove(object *Reading) error

Remove deletes a single object

func (*ReadingBox) RemoveMany added in v1.0.0

func (box *ReadingBox) RemoveMany(objects ...*Reading) (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 (*ReadingBox) Update added in v1.1.0

func (box *ReadingBox) Update(object *Reading) 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 ReadingQuery added in v0.8.0

type ReadingQuery struct {
	*objectbox.Query
}

Query provides a way to search stored objects

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

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

func (*ReadingQuery) Find added in v0.8.0

func (query *ReadingQuery) Find() ([]*Reading, error)

Find returns all objects matching the query

func (*ReadingQuery) Limit added in v0.9.0

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

Limit sets the number of elements to process by the query

func (*ReadingQuery) Offset added in v0.9.0

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

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

type TestEnv added in v1.1.1

type TestEnv struct {
	*objectbox.ObjectBox
	// contains filtered or unexported fields
}

func NewTestEnv added in v1.1.1

func NewTestEnv() *TestEnv

NewTestEnv creates an empty ObjectBox instance

func (*TestEnv) Close added in v1.1.1

func (env *TestEnv) Close()

Close closes ObjectBox and removes the database

Jump to

Keyboard shortcuts

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