Documentation ¶
Index ¶
- Constants
- Variables
- type Entity
- func (entity *Entity) AddFlag(flag EntityFlags)
- func (entity *Entity) AutosetIdProperty(acceptedTypes []PropertyType) error
- func (entity *Entity) CreateProperty() (*Property, error)
- func (entity *Entity) CreateRelation() (*StandaloneRelation, error)
- func (entity *Entity) FindPropertyByName(name string) (*Property, error)
- func (entity *Entity) FindPropertyByUid(uid Uid) (*Property, error)
- func (entity *Entity) FindRelationByName(name string) (*StandaloneRelation, error)
- func (entity *Entity) FindRelationByUid(uid Uid) (*StandaloneRelation, error)
- func (entity *Entity) IdProperty() (*Property, error)
- func (entity *Entity) RemoveProperty(property *Property) error
- func (entity *Entity) RemoveRelation(relation *StandaloneRelation) error
- func (entity *Entity) Validate() (err error)
- type EntityFlags
- type EntityMeta
- type Id
- type IdUid
- type ModelInfo
- func (model *ModelInfo) CheckRelationCycles() error
- func (model *ModelInfo) Close() error
- func (model *ModelInfo) CreateEntity(name string) (*Entity, error)
- func (model *ModelInfo) EntitiesWithMeta() []*Entity
- func (model *ModelInfo) Finalize() error
- func (model *ModelInfo) FindEntityByName(name string) (*Entity, error)
- func (model *ModelInfo) FindEntityByUid(uid Uid) (*Entity, error)
- func (model *ModelInfo) GenerateUid() (Uid, error)
- func (model *ModelInfo) RemoveEntity(entity *Entity) error
- func (model *ModelInfo) Validate() (err error)
- func (model *ModelInfo) Write() error
- type Property
- func (property *Property) AddFlag(flag PropertyFlags)
- func (property *Property) CreateIndex() error
- func (property *Property) FbSlot() int
- func (property *Property) FbvTableOffset() (uint16, error)
- func (property *Property) IsIdProperty() bool
- func (property *Property) RemoveIndex() error
- func (property *Property) SetIndex() error
- func (property *Property) Validate() error
- type PropertyFlags
- type PropertyMeta
- type PropertyType
- type StandaloneRelation
- type StandaloneRelationMeta
- type Uid
Constants ¶
const (
// ModelVersion specifies current version of the model JSON file generated
ModelVersion = 5
)
Variables ¶
var EntityFlagNames = map[EntityFlags]string{ EntityFlagSyncEnabled: "SyncEnabled", EntityFlagSharedGlobalIds: "SharedGlobalIds", }
EntityFlagNames assigns a name to each PropertyFlag
var PropertyFlagNames = map[PropertyFlags]string{ PropertyFlagId: "Id", PropertyFlagNonPrimitiveType: "NonPrimitiveType", PropertyFlagNotNull: "NotNull", PropertyFlagIndexed: "Indexed", PropertyFlagReserved: "Reserved", PropertyFlagUnique: "Unique", PropertyFlagIdMonotonicSequence: "IdMonotonicSequence", PropertyFlagIdSelfAssignable: "IdSelfAssignable", PropertyFlagIndexPartialSkipNull: "IndexPartialSkipNull", PropertyFlagIndexPartialSkipZero: "IndexPartialSkipZero", PropertyFlagVirtual: "Virtual", PropertyFlagIndexHash: "IndexHash", PropertyFlagIndexHash64: "IndexHash64", PropertyFlagUnsigned: "Unsigned", PropertyFlagIdCompanion: "IdCompanion", }
PropertyFlagNames assigns a name to each PropertyFlag
var PropertyTypeNames = map[PropertyType]string{ PropertyTypeBool: "Bool", PropertyTypeByte: "Byte", PropertyTypeShort: "Short", PropertyTypeChar: "Char", PropertyTypeInt: "Int", PropertyTypeLong: "Long", PropertyTypeFloat: "Float", PropertyTypeDouble: "Double", PropertyTypeString: "String", PropertyTypeDate: "Date", PropertyTypeRelation: "Relation", PropertyTypeDateNano: "DateNano", PropertyTypeByteVector: "ByteVector", PropertyTypeStringVector: "StringVector", }
PropertyTypeNames assigns a name to each PropertyType
Functions ¶
This section is empty.
Types ¶
type Entity ¶
type Entity struct { Id IdUid `json:"id"` LastPropertyId IdUid `json:"lastPropertyId"` Name string `json:"name"` Flags EntityFlags `json:"flags,omitempty"` Properties []*Property `json:"properties"` Relations []*StandaloneRelation `json:"relations,omitempty"` UidRequest bool `json:"-"` // used when the user gives an empty uid annotation Meta EntityMeta `json:"-"` CurrentlyPresent bool `json:"-"` Comments []string `json:"-"` Model *ModelInfo `json:"-"` }
Entity represents a DB entity
func CreateEntity ¶
CreateEntity constructs an Entity
func (*Entity) AddFlag ¶ added in v0.11.0
func (entity *Entity) AddFlag(flag EntityFlags)
AddFlag flags the entity
func (*Entity) AutosetIdProperty ¶
func (entity *Entity) AutosetIdProperty(acceptedTypes []PropertyType) error
AutosetIdProperty updates finds a property that's defined as an ID and if none is, tries to set one based on its name and type
func (*Entity) CreateProperty ¶
CreateProperty creates a property
func (*Entity) CreateRelation ¶
func (entity *Entity) CreateRelation() (*StandaloneRelation, error)
CreateRelation creates relation
func (*Entity) FindPropertyByName ¶
FindPropertyByName finds a property by name
func (*Entity) FindPropertyByUid ¶
FindPropertyByUid finds a property by Uid
func (*Entity) FindRelationByName ¶
func (entity *Entity) FindRelationByName(name string) (*StandaloneRelation, error)
FindRelationByName finds relation by name
func (*Entity) FindRelationByUid ¶
func (entity *Entity) FindRelationByUid(uid Uid) (*StandaloneRelation, error)
FindRelationByUid Finds relation by Uid
func (*Entity) IdProperty ¶
IdProperty updates finds a property that's defined as an ID and if none is, tries to set one based on its name and type
func (*Entity) RemoveProperty ¶
RemoveProperty removes a property
func (*Entity) RemoveRelation ¶
func (entity *Entity) RemoveRelation(relation *StandaloneRelation) error
RemoveRelation removes relation
type EntityFlags ¶ added in v0.11.0
type EntityFlags int32
EntityFlags is a bit combination of 0..n entity flags corresponding with objectbox-c
const ( EntityFlagSyncEnabled EntityFlags = 2 )
type EntityMeta ¶
type EntityMeta interface { // Merge produces new EntityMeta based on its internal state and given entity Merge(entity *Entity) EntityMeta }
EntityMeta provides a way for bindings to provide additional information to other users of Entity
type IdUid ¶
type IdUid string
IdUid represents a "ID:UID" string as used in the model jSON
func CreateIdUid ¶
CreateIdUid creates a string representation of ID and UID
func (*IdUid) GetIdAllowZero ¶
GetId returns the ID part, not returning an error in case of a zero value
func (*IdUid) GetUidAllowZero ¶
GetUid returns the UID part, not returning an error in case of a zero value
type ModelInfo ¶
type ModelInfo struct { // NOTE don't change order of these json exported properties because it will change users' model.json files Note1 string `json:"_note1"` Note2 string `json:"_note2"` Note3 string `json:"_note3"` Entities []*Entity `json:"entities"` LastEntityId IdUid `json:"lastEntityId"` LastIndexId IdUid `json:"lastIndexId"` LastRelationId IdUid `json:"lastRelationId"` ModelVersion int `json:"modelVersion"` MinimumParserVersion int `json:"modelVersionParserMinimum"` RetiredEntityUids []Uid `json:"retiredEntityUids"` RetiredIndexUids []Uid `json:"retiredIndexUids"` RetiredPropertyUids []Uid `json:"retiredPropertyUids"` RetiredRelationUids []Uid `json:"retiredRelationUids"` Version int `json:"version"` // user specified version Rand *rand.Rand `json:"-"` // seeded random number generator // contains filtered or unexported fields }
ModelInfo represents a database model and also serves as a serialization interface for the model JSON file
func LoadModelFromJSONFile ¶ added in v0.10.0
func LoadOrCreateModel ¶
LoadOrCreateModel reads a model file or creates a new one if it doesn't exist
func (*ModelInfo) CheckRelationCycles ¶
CheckRelationCycles finds relations cycles
func (*ModelInfo) CreateEntity ¶
CreateEntity creates an entity
func (*ModelInfo) EntitiesWithMeta ¶
EntitiesWithMeta returns all entities with .Meta != nil - which usually means they're the ones processed in the current generator run, as opposed to all the entities available in the stored JSON model.
func (*ModelInfo) Finalize ¶
Finalize should be called after making changes to the model (e.g. from user schema definitions) to verify and update as necessary.
func (*ModelInfo) FindEntityByName ¶
FindEntityByName finds entity by name
func (*ModelInfo) FindEntityByUid ¶
FindEntityByUid finds entity by Uid
func (*ModelInfo) GenerateUid ¶
GenerateUid generates a unique UID
func (*ModelInfo) RemoveEntity ¶ added in v0.12.0
RemoveEntity removes an entity
type Property ¶
type Property struct { Id IdUid `json:"id"` Name string `json:"name"` IndexId *IdUid `json:"indexId,omitempty"` // a pointer because it may be nil Type PropertyType `json:"type"` Flags PropertyFlags `json:"flags,omitempty"` RelationTarget string `json:"relationTarget,omitempty"` Entity *Entity `json:"-"` UidRequest bool `json:"-"` // used when the user gives an empty uid annotation Meta PropertyMeta `json:"-"` Comments []string `json:"-"` }
Property in a model
func CreateProperty ¶
CreateProperty creates a property
func (*Property) AddFlag ¶
func (property *Property) AddFlag(flag PropertyFlags)
AddFlag flags the property
func (*Property) CreateIndex ¶
CreateIndex creates an index
func (*Property) FbSlot ¶
FbSlot is called from the template. It calculates flatbuffers slot number.
func (*Property) FbvTableOffset ¶
FbvTableOffset calculates flatbuffers vTableOffset.
func (*Property) IsIdProperty ¶
func (*Property) RemoveIndex ¶
RemoveIndex removes an index
type PropertyFlags ¶
type PropertyFlags int32
PropertyFlags is a bit combination of 0..n property flags corresponding with objectbox-c
const ( PropertyFlagId PropertyFlags = 1 PropertyFlagNonPrimitiveType PropertyFlags = 2 PropertyFlagNotNull PropertyFlags = 4 PropertyFlagIndexed PropertyFlags = 8 PropertyFlagReserved PropertyFlags = 16 PropertyFlagUnique PropertyFlags = 32 PropertyFlagIdMonotonicSequence PropertyFlags = 64 PropertyFlagIdSelfAssignable PropertyFlags = 128 PropertyFlagIndexPartialSkipNull PropertyFlags = 256 PropertyFlagIndexPartialSkipZero PropertyFlags = 512 PropertyFlagVirtual PropertyFlags = 1024 PropertyFlagIndexHash PropertyFlags = 2048 PropertyFlagIndexHash64 PropertyFlags = 4096 PropertyFlagUnsigned PropertyFlags = 8192 PropertyFlagIdCompanion PropertyFlags = 16384 )
type PropertyMeta ¶
type PropertyMeta interface { // Merge produces new PropertyMeta based on its internal state and given property Merge(property *Property) PropertyMeta }
PropertyMeta provides a way for bindings to provide additional information to other users of Property
type PropertyType ¶
type PropertyType int8
PropertyType is an identifier of a property type corresponding with objectbox-c
const ( PropertyTypeBool PropertyType = 1 PropertyTypeByte PropertyType = 2 PropertyTypeShort PropertyType = 3 PropertyTypeChar PropertyType = 4 PropertyTypeInt PropertyType = 5 PropertyTypeLong PropertyType = 6 PropertyTypeFloat PropertyType = 7 PropertyTypeDouble PropertyType = 8 PropertyTypeString PropertyType = 9 PropertyTypeDate PropertyType = 10 PropertyTypeRelation PropertyType = 11 PropertyTypeDateNano PropertyType = 12 PropertyTypeByteVector PropertyType = 23 PropertyTypeStringVector PropertyType = 30 )
type StandaloneRelation ¶
type StandaloneRelation struct { Id IdUid `json:"id"` Name string `json:"name"` Target *Entity `json:"-"` // TODO consider changing to TargetName, nothing else seems to be used. TargetId IdUid `json:"targetId"` UidRequest bool `json:"-"` // used when the user gives an empty uid annotation // TODO test Meta StandaloneRelationMeta `json:"-"` // contains filtered or unexported fields }
StandaloneRelation in a model
func CreateStandaloneRelation ¶
func CreateStandaloneRelation(entity *Entity, id IdUid) *StandaloneRelation
CreateStandaloneRelation creates a standalone relation
func (*StandaloneRelation) SetTarget ¶
func (relation *StandaloneRelation) SetTarget(entity *Entity)
SetTarget sets the relation target entity
func (*StandaloneRelation) Validate ¶
func (relation *StandaloneRelation) Validate() error
Validate performs initial validation of loaded data so that it doesn't have to be checked in each function
type StandaloneRelationMeta ¶ added in v0.10.0
type StandaloneRelationMeta interface { // Merge produces new StandaloneRelationMeta based on its internal state and given standalone relation Merge(relation *StandaloneRelation) StandaloneRelationMeta }
StandaloneRelationMeta provides a way for bindings to provide additional information to other users of StandaloneRelation