modelinfo

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: Apache-2.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

This section is empty.

Functions

This section is empty.

Types

type Entity

type Entity struct {
	Id             IdUid                 `json:"id"`
	LastPropertyId IdUid                 `json:"lastPropertyId"`
	Name           string                `json:"name"`
	Properties     []*Property           `json:"properties"`
	Relations      []*StandaloneRelation `json:"relations,omitempty"`
	// contains filtered or unexported fields
}

Entity represents a DB entity

func CreateEntity

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

CreateEntity constructs an Entity

func (*Entity) CreateProperty

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

CreateProperty creates a property

func (*Entity) CreateRelation added in v0.9.0

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 added in v0.9.0

func (entity *Entity) FindRelationByName(name string) (*StandaloneRelation, error)

FindRelationByName finds relation by name

func (*Entity) FindRelationByUid added in v0.9.0

func (entity *Entity) FindRelationByUid(uid Uid) (*StandaloneRelation, error)

FindRelationByUid Finds relation by Uid

func (*Entity) RemoveProperty

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

RemoveProperty removes a property

func (*Entity) RemoveRelation added in v0.9.0

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

RemoveRelation removes relation

func (*Entity) Validate

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

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

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) GetUid

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

GetUid returns the UID part

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

	// Model Template
	Package string `json:"-"`
	// contains filtered or unexported fields
}

ModelInfo is a serialization interface for the model JSON file

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 added in v0.9.0

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) 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 added in v1.1.0

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

GenerateUid generates a unique UID

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           int    `json:"type"`
	Flags          int    `json:"flags,omitempty"`
	RelationTarget string `json:"relationTarget,omitempty"`
	// contains filtered or unexported fields
}

Property in a model

func CreateProperty

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

CreateProperty creates a property

func (*Property) CreateIndex

func (property *Property) CreateIndex() error

CreateIndex creates an index

func (*Property) RemoveIndex

func (property *Property) RemoveIndex() error

RemoveIndex removes an index

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 StandaloneRelation added in v0.9.0

type StandaloneRelation struct {
	Id       IdUid   `json:"id"`
	Name     string  `json:"name"`
	Target   *Entity `json:"-"`
	TargetId IdUid   `json:"targetId"`
	// contains filtered or unexported fields
}

StandaloneRelation in a model

func CreateStandaloneRelation added in v0.9.0

func CreateStandaloneRelation(entity *Entity, id IdUid) *StandaloneRelation

CreateStandaloneRelation creates a standalone relation

func (*StandaloneRelation) SetTarget added in v1.0.0

func (relation *StandaloneRelation) SetTarget(entity *Entity)

SetTarget sets the relation target entity

func (*StandaloneRelation) Validate added in v0.9.0

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