calapi/internal/db_model/calendar.obx.go
2023-02-24 22:17:45 +01:00

374 lines
14 KiB
Go

// Code generated by ObjectBox; DO NOT EDIT.
// Learn more about defining entities and generating this file - visit https://golang.objectbox.io/entity-annotations
package db_model
import (
"errors"
"github.com/google/flatbuffers/go"
"github.com/objectbox/objectbox-go/objectbox"
"github.com/objectbox/objectbox-go/objectbox/fbutils"
)
type calendar_EntityInfo struct {
objectbox.Entity
Uid uint64
}
var CalendarBinding = calendar_EntityInfo{
Entity: objectbox.Entity{
Id: 2,
},
Uid: 3479788557646175786,
}
// Calendar_ contains type-based Property helpers to facilitate some common operations such as Queries.
var Calendar_ = struct {
Id *objectbox.PropertyUint64
Name *objectbox.PropertyString
Description *objectbox.PropertyString
DateCreated *objectbox.PropertyInt64
}{
Id: &objectbox.PropertyUint64{
BaseProperty: &objectbox.BaseProperty{
Id: 1,
Entity: &CalendarBinding.Entity,
},
},
Name: &objectbox.PropertyString{
BaseProperty: &objectbox.BaseProperty{
Id: 2,
Entity: &CalendarBinding.Entity,
},
},
Description: &objectbox.PropertyString{
BaseProperty: &objectbox.BaseProperty{
Id: 3,
Entity: &CalendarBinding.Entity,
},
},
DateCreated: &objectbox.PropertyInt64{
BaseProperty: &objectbox.BaseProperty{
Id: 4,
Entity: &CalendarBinding.Entity,
},
},
}
// GeneratorVersion is called by ObjectBox to verify the compatibility of the generator used to generate this code
func (calendar_EntityInfo) GeneratorVersion() int {
return 6
}
// AddToModel is called by ObjectBox during model build
func (calendar_EntityInfo) AddToModel(model *objectbox.Model) {
model.Entity("Calendar", 2, 3479788557646175786)
model.Property("Id", 6, 1, 5837320313195022877)
model.PropertyFlags(1)
model.Property("Name", 9, 2, 5757515869118754632)
model.Property("Description", 9, 3, 6251208215291496247)
model.Property("DateCreated", 10, 4, 4327693086526358319)
model.EntityLastPropertyId(4, 4327693086526358319)
}
// GetId is called by ObjectBox during Put operations to check for existing ID on an object
func (calendar_EntityInfo) GetId(object interface{}) (uint64, error) {
return object.(*Calendar).Id, nil
}
// SetId is called by ObjectBox during Put to update an ID on an object that has just been inserted
func (calendar_EntityInfo) SetId(object interface{}, id uint64) error {
object.(*Calendar).Id = id
return nil
}
// PutRelated is called by ObjectBox to put related entities before the object itself is flattened and put
func (calendar_EntityInfo) PutRelated(ob *objectbox.ObjectBox, object interface{}, id uint64) error {
return nil
}
// Flatten is called by ObjectBox to transform an object to a FlatBuffer
func (calendar_EntityInfo) Flatten(object interface{}, fbb *flatbuffers.Builder, id uint64) error {
obj := object.(*Calendar)
var propDateCreated int64
{
var err error
propDateCreated, err = objectbox.TimeInt64ConvertToDatabaseValue(obj.DateCreated)
if err != nil {
return errors.New("converter objectbox.TimeInt64ConvertToDatabaseValue() failed on Calendar.DateCreated: " + err.Error())
}
}
var offsetName = fbutils.CreateStringOffset(fbb, obj.Name)
var offsetDescription = fbutils.CreateStringOffset(fbb, obj.Description)
// build the FlatBuffers object
fbb.StartObject(4)
fbutils.SetUint64Slot(fbb, 0, id)
fbutils.SetUOffsetTSlot(fbb, 1, offsetName)
fbutils.SetUOffsetTSlot(fbb, 2, offsetDescription)
fbutils.SetInt64Slot(fbb, 3, propDateCreated)
return nil
}
// Load is called by ObjectBox to load an object from a FlatBuffer
func (calendar_EntityInfo) Load(ob *objectbox.ObjectBox, bytes []byte) (interface{}, error) {
if len(bytes) == 0 { // sanity check, should "never" happen
return nil, errors.New("can't deserialize an object of type 'Calendar' - no data received")
}
var table = &flatbuffers.Table{
Bytes: bytes,
Pos: flatbuffers.GetUOffsetT(bytes),
}
var propId = table.GetUint64Slot(4, 0)
propDateCreated, err := objectbox.TimeInt64ConvertToEntityProperty(fbutils.GetInt64Slot(table, 10))
if err != nil {
return nil, errors.New("converter objectbox.TimeInt64ConvertToEntityProperty() failed on Calendar.DateCreated: " + err.Error())
}
return &Calendar{
Id: propId,
Name: fbutils.GetStringSlot(table, 6),
Description: fbutils.GetStringSlot(table, 8),
DateCreated: propDateCreated,
}, nil
}
// MakeSlice is called by ObjectBox to construct a new slice to hold the read objects
func (calendar_EntityInfo) MakeSlice(capacity int) interface{} {
return make([]*Calendar, 0, capacity)
}
// AppendToSlice is called by ObjectBox to fill the slice of the read objects
func (calendar_EntityInfo) AppendToSlice(slice interface{}, object interface{}) interface{} {
if object == nil {
return append(slice.([]*Calendar), nil)
}
return append(slice.([]*Calendar), object.(*Calendar))
}
// Box provides CRUD access to Calendar objects
type CalendarBox struct {
*objectbox.Box
}
// BoxForCalendar opens a box of Calendar objects
func BoxForCalendar(ob *objectbox.ObjectBox) *CalendarBox {
return &CalendarBox{
Box: ob.InternalBox(2),
}
}
// Put synchronously inserts/updates a single object.
// In case the Id is not specified, it would be assigned automatically (auto-increment).
// When inserting, the Calendar.Id property on the passed object will be assigned the new ID as well.
func (box *CalendarBox) Put(object *Calendar) (uint64, error) {
return box.Box.Put(object)
}
// 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 Calendar.Id property on the passed object will be assigned the new ID as well.
func (box *CalendarBox) Insert(object *Calendar) (uint64, error) {
return box.Box.Insert(object)
}
// 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.
func (box *CalendarBox) Update(object *Calendar) error {
return box.Box.Update(object)
}
// PutAsync asynchronously inserts/updates a single object.
// Deprecated: use box.Async().Put() instead
func (box *CalendarBox) PutAsync(object *Calendar) (uint64, error) {
return box.Box.PutAsync(object)
}
// 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 Calendar.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 Calendar.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 (box *CalendarBox) PutMany(objects []*Calendar) ([]uint64, error) {
return box.Box.PutMany(objects)
}
// Get reads a single object.
//
// Returns nil (and no error) in case the object with the given ID doesn't exist.
func (box *CalendarBox) Get(id uint64) (*Calendar, error) {
object, err := box.Box.Get(id)
if err != nil {
return nil, err
} else if object == nil {
return nil, nil
}
return object.(*Calendar), nil
}
// GetMany reads multiple objects at once.
// If any of the objects doesn't exist, its position in the return slice is nil
func (box *CalendarBox) GetMany(ids ...uint64) ([]*Calendar, error) {
objects, err := box.Box.GetMany(ids...)
if err != nil {
return nil, err
}
return objects.([]*Calendar), nil
}
// GetManyExisting reads multiple objects at once, skipping those that do not exist.
func (box *CalendarBox) GetManyExisting(ids ...uint64) ([]*Calendar, error) {
objects, err := box.Box.GetManyExisting(ids...)
if err != nil {
return nil, err
}
return objects.([]*Calendar), nil
}
// GetAll reads all stored objects
func (box *CalendarBox) GetAll() ([]*Calendar, error) {
objects, err := box.Box.GetAll()
if err != nil {
return nil, err
}
return objects.([]*Calendar), nil
}
// Remove deletes a single object
func (box *CalendarBox) Remove(object *Calendar) error {
return box.Box.Remove(object)
}
// 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 (box *CalendarBox) RemoveMany(objects ...*Calendar) (uint64, error) {
var ids = make([]uint64, len(objects))
for k, object := range objects {
ids[k] = object.Id
}
return box.Box.RemoveIds(ids...)
}
// Creates a query with the given conditions. Use the fields of the Calendar_ struct to create conditions.
// Keep the *CalendarQuery 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 (box *CalendarBox) Query(conditions ...objectbox.Condition) *CalendarQuery {
return &CalendarQuery{
box.Box.Query(conditions...),
}
}
// Creates a query with the given conditions. Use the fields of the Calendar_ struct to create conditions.
// Keep the *CalendarQuery if you intend to execute the query multiple times.
func (box *CalendarBox) QueryOrError(conditions ...objectbox.Condition) (*CalendarQuery, error) {
if query, err := box.Box.QueryOrError(conditions...); err != nil {
return nil, err
} else {
return &CalendarQuery{query}, nil
}
}
// Async provides access to the default Async Box for asynchronous operations. See CalendarAsyncBox for more information.
func (box *CalendarBox) Async() *CalendarAsyncBox {
return &CalendarAsyncBox{AsyncBox: box.Box.Async()}
}
// CalendarAsyncBox provides asynchronous operations on Calendar 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.
type CalendarAsyncBox struct {
*objectbox.AsyncBox
}
// AsyncBoxForCalendar 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 CalendarBox::Async() which takes care of resource management and doesn't require closing.
func AsyncBoxForCalendar(ob *objectbox.ObjectBox, timeoutMs uint64) *CalendarAsyncBox {
var async, err = objectbox.NewAsyncBox(ob, 2, timeoutMs)
if err != nil {
panic("Could not create async box for entity ID 2: %s" + err.Error())
}
return &CalendarAsyncBox{AsyncBox: async}
}
// 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 (asyncBox *CalendarAsyncBox) Put(object *Calendar) (uint64, error) {
return asyncBox.AsyncBox.Put(object)
}
// 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 (asyncBox *CalendarAsyncBox) Insert(object *Calendar) (id uint64, err error) {
return asyncBox.AsyncBox.Insert(object)
}
// Update a single object asynchronously.
// The object must already exists or the update fails silently (without an error returned).
func (asyncBox *CalendarAsyncBox) Update(object *Calendar) error {
return asyncBox.AsyncBox.Update(object)
}
// Remove deletes a single object asynchronously.
func (asyncBox *CalendarAsyncBox) Remove(object *Calendar) error {
return asyncBox.AsyncBox.Remove(object)
}
// Query provides a way to search stored objects
//
// For example, you can find all Calendar which Id is either 42 or 47:
//
// box.Query(Calendar_.Id.In(42, 47)).Find()
type CalendarQuery struct {
*objectbox.Query
}
// Find returns all objects matching the query
func (query *CalendarQuery) Find() ([]*Calendar, error) {
objects, err := query.Query.Find()
if err != nil {
return nil, err
}
return objects.([]*Calendar), nil
}
// Offset defines the index of the first object to process (how many objects to skip)
func (query *CalendarQuery) Offset(offset uint64) *CalendarQuery {
query.Query.Offset(offset)
return query
}
// Limit sets the number of elements to process by the query
func (query *CalendarQuery) Limit(limit uint64) *CalendarQuery {
query.Query.Limit(limit)
return query
}