model

package
v0.0.0-...-88f9026 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ReminderBinding = reminder_EntityInfo{
	Entity: objectbox.Entity{
		Id: 1,
	},
	Uid: 8669441415074368449,
}
View Source
var Reminder_ = struct {
	Id      *objectbox.PropertyUint64
	User    *objectbox.PropertyString
	Channel *objectbox.PropertyString
	Time    *objectbox.PropertyInt64
	Text    *objectbox.PropertyString
}{
	Id: &objectbox.PropertyUint64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     1,
			Entity: &ReminderBinding.Entity,
		},
	},
	User: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     2,
			Entity: &ReminderBinding.Entity,
		},
	},
	Channel: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     3,
			Entity: &ReminderBinding.Entity,
		},
	},
	Time: &objectbox.PropertyInt64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     4,
			Entity: &ReminderBinding.Entity,
		},
	},
	Text: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     5,
			Entity: &ReminderBinding.Entity,
		},
	},
}

Reminder_ 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 Reminder

type Reminder struct {
	Id      uint64
	User    string
	Channel string
	Time    int64
	Text    string
}

type ReminderAsyncBox

type ReminderAsyncBox struct {
	*objectbox.AsyncBox
}

ReminderAsyncBox provides asynchronous operations on Reminder 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 AsyncBoxForReminder

func AsyncBoxForReminder(ob *objectbox.ObjectBox, timeoutMs uint64) *ReminderAsyncBox

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

func (*ReminderAsyncBox) Insert

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

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

func (asyncBox *ReminderAsyncBox) Remove(object *Reminder) error

Remove deletes a single object asynchronously.

func (*ReminderAsyncBox) Update

func (asyncBox *ReminderAsyncBox) Update(object *Reminder) error

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

type ReminderBox

type ReminderBox struct {
	*objectbox.Box
}

Box provides CRUD access to Reminder objects

func BoxForReminder

func BoxForReminder(ob *objectbox.ObjectBox) *ReminderBox

BoxForReminder opens a box of Reminder objects

func (*ReminderBox) Async

func (box *ReminderBox) Async() *ReminderAsyncBox

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

func (*ReminderBox) Get

func (box *ReminderBox) Get(id uint64) (*Reminder, error)

Get reads a single object.

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

func (*ReminderBox) GetAll

func (box *ReminderBox) GetAll() ([]*Reminder, error)

GetAll reads all stored objects

func (*ReminderBox) GetMany

func (box *ReminderBox) GetMany(ids ...uint64) ([]*Reminder, error)

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

func (*ReminderBox) GetManyExisting

func (box *ReminderBox) GetManyExisting(ids ...uint64) ([]*Reminder, error)

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

func (*ReminderBox) Insert

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

func (*ReminderBox) Put

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

func (*ReminderBox) PutAsync

func (box *ReminderBox) PutAsync(object *Reminder) (uint64, error)

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

func (*ReminderBox) PutMany

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

func (box *ReminderBox) Query(conditions ...objectbox.Condition) *ReminderQuery

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

func (box *ReminderBox) QueryOrError(conditions ...objectbox.Condition) (*ReminderQuery, error)

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

func (*ReminderBox) Remove

func (box *ReminderBox) Remove(object *Reminder) error

Remove deletes a single object

func (*ReminderBox) RemoveMany

func (box *ReminderBox) RemoveMany(objects ...*Reminder) (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 (*ReminderBox) Update

func (box *ReminderBox) Update(object *Reminder) 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 ReminderQuery

type ReminderQuery struct {
	*objectbox.Query
}

Query provides a way to search stored objects

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

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

func (*ReminderQuery) Find

func (query *ReminderQuery) Find() ([]*Reminder, error)

Find returns all objects matching the query

func (*ReminderQuery) Limit

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

Limit sets the number of elements to process by the query

func (*ReminderQuery) Offset

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

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