model

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModelVersion specifies current version of the model JSON file generated
	ModelVersion = 5
)

Variables

View Source
var EntityFlagNames = map[EntityFlags]string{
	EntityFlagSyncEnabled:     "SyncEnabled",
	EntityFlagSharedGlobalIds: "SharedGlobalIds",
}

EntityFlagNames assigns a name to each PropertyFlag

View Source
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

View Source
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

func CreateEntity(model *ModelInfo, id Id, uid Uid) *Entity

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

func (entity *Entity) CreateProperty() (*Property, error)

CreateProperty creates a property

func (*Entity) CreateRelation

func (entity *Entity) CreateRelation() (*StandaloneRelation, error)

CreateRelation creates relation

func (*Entity) FindPropertyByName

func (entity *Entity) FindPropertyByName(name string) (*Property, error)

FindPropertyByName finds a property by name

func (*Entity) FindPropertyByUid

func (entity *Entity) FindPropertyByUid(uid Uid) (*Property, error)

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

func (entity *Entity) IdProperty() (*Property, error)

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

func (entity *Entity) RemoveProperty(property *Property) error

RemoveProperty removes a property

func (*Entity) RemoveRelation

func (entity *Entity) RemoveRelation(relation *StandaloneRelation) error

RemoveRelation removes relation

func (*Entity) Validate

func (entity *Entity) Validate() (err error)

Validate performs validation of the entity model

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
	EntityFlagSharedGlobalIds EntityFlags = 4
)

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 Id

type Id = uint32

Id identifies a model element locally (e.g. property inside an entity)

type IdUid

type IdUid string

IdUid represents a "ID:UID" string as used in the model jSON

func CreateIdUid

func CreateIdUid(id Id, uid Uid) IdUid

CreateIdUid creates a string representation of ID and UID

func (*IdUid) Get

func (str *IdUid) Get() (Id, Uid, error)

Get returns a pair of ID and UID

func (*IdUid) GetId

func (str *IdUid) GetId() (Id, error)

GetId returns the ID part

func (*IdUid) GetIdAllowZero

func (str *IdUid) GetIdAllowZero() (Id, error)

GetId returns the ID part, not returning an error in case of a zero value

func (*IdUid) GetUid

func (str *IdUid) GetUid() (Uid, error)

GetUid returns the UID part

func (*IdUid) GetUidAllowZero

func (str *IdUid) GetUidAllowZero() (Uid, error)

GetUid returns the UID part, not returning an error in case of a zero value

func (*IdUid) Validate

func (str *IdUid) Validate() error

Validate performs initial validation of loaded data so that it doesn't have to be checked in each function

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 LoadModelFromJSONFile(path string) (model *ModelInfo, err error)

func LoadOrCreateModel

func LoadOrCreateModel(path string) (model *ModelInfo, err error)

LoadOrCreateModel reads a model file or creates a new one if it doesn't exist

func (*ModelInfo) CheckRelationCycles

func (model *ModelInfo) CheckRelationCycles() error

CheckRelationCycles finds relations cycles

func (*ModelInfo) Close

func (model *ModelInfo) Close() error

Close and unlock model

func (*ModelInfo) CreateEntity

func (model *ModelInfo) CreateEntity(name string) (*Entity, error)

CreateEntity creates an entity

func (*ModelInfo) EntitiesWithMeta

func (model *ModelInfo) EntitiesWithMeta() []*Entity

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

func (model *ModelInfo) Finalize() error

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

func (model *ModelInfo) FindEntityByName(name string) (*Entity, error)

FindEntityByName finds entity by name

func (*ModelInfo) FindEntityByUid

func (model *ModelInfo) FindEntityByUid(uid Uid) (*Entity, error)

FindEntityByUid finds entity by Uid

func (*ModelInfo) GenerateUid

func (model *ModelInfo) GenerateUid() (Uid, error)

GenerateUid generates a unique UID

func (*ModelInfo) RemoveEntity added in v0.12.0

func (model *ModelInfo) RemoveEntity(entity *Entity) error

RemoveEntity removes an entity

func (*ModelInfo) Validate

func (model *ModelInfo) Validate() (err error)

Validate performs initial validation of loaded data so that it doesn't have to be checked in each function

func (*ModelInfo) Write

func (model *ModelInfo) Write() error

Write current model data to file

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

func CreateProperty(entity *Entity, id Id, uid Uid) *Property

CreateProperty creates a property

func (*Property) AddFlag

func (property *Property) AddFlag(flag PropertyFlags)

AddFlag flags the property

func (*Property) CreateIndex

func (property *Property) CreateIndex() error

CreateIndex creates an index

func (*Property) FbSlot

func (property *Property) FbSlot() int

FbSlot is called from the template. It calculates flatbuffers slot number.

func (*Property) FbvTableOffset

func (property *Property) FbvTableOffset() (uint16, error)

FbvTableOffset calculates flatbuffers vTableOffset.

func (*Property) IsIdProperty

func (property *Property) IsIdProperty() bool

func (*Property) RemoveIndex

func (property *Property) RemoveIndex() error

RemoveIndex removes an index

func (*Property) SetIndex

func (property *Property) SetIndex() error

SetIndex defines an index on the property

func (*Property) Validate

func (property *Property) Validate() error

Validate performs initial validation of loaded data so that it doesn't have to be checked in each function

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

type Uid

type Uid = uint64

Uid identifies an element globally (i.e. is unique across the whole model)

Jump to

Keyboard shortcuts

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