models

package
v0.0.0-...-df6cefe Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EmptyUUID for empty UUID
	EmptyUUID uuid.UUID = uuid.UUID{}
)

Functions

func EntityType

func EntityType(entity Entity) string

EntityType return entity type

func GetFQNameByID

func GetFQNameByID(tx *gorm.DB, id uuid.UUID, entityType string) (string, error)

GetFQNameByID queries DB for ID by FQName

func GetIDByFQName

func GetIDByFQName(tx *gorm.DB, fqname string, entityType string) (uuid.UUID, error)

GetIDByFQName queries DB for FQName by ID

func MigrateDataModel

func MigrateDataModel(db *gorm.DB)

MigrateDataModel - Auto migrate project models

func ModelNames

func ModelNames() []string

ModelNames returns names for all registered models

func PopulateEntity

func PopulateEntity(entity Entity, payload map[string]interface{}) (err error)

PopulateEntity with json payload

func SaveEntity

func SaveEntity(db *gorm.DB, entity Entity) error

SaveEntity to the database

func UpdateEntity

func UpdateEntity(db *gorm.DB, entity Entity) error

UpdateEntity to the database

Types

type BaseModel

type BaseModel struct {
	ID          uuid.UUID      `gorm:"column:id;type:uuid;primary_key:<-create"`
	Name        string         `gorm:"column:name;size:128;not null;<-:create"`
	DisplayName string         `gorm:"column:display_name;size:128;not null"`
	ParentID    uuid.UUID      `gorm:"column:parent_id;type:uuid;<-:create"`
	ParentType  string         `gorm:"column:parent_type;<-:create"`
	FQName      string         `gorm:"column:fqname;not null;uniqueIndex;<:create"`
	Payload     datatypes.JSON `gorm:"column:payload"`
	// contains filtered or unexported fields
}

BaseModel - base database entity model

type BaseRef

type BaseRef struct {
	FromFQName string         `gorm:"column:from_fqname"`
	ToFQName   string         `gorm:"column:to_fqname"`
	Payload    datatypes.JSON `gorm:"column:payload"`
}

BaseRef - base ref entity model

type Device

type Device struct {
	Base BaseModel `gorm:"embedded" parentTypes:"domain,project"`
	// fields
	Connection_type string `gorm:"column:connction_type"`
	// Many-Many relations
	Device_families []Device_family `gorm:"many2many:device_device_families"`
}

Device -----------------------------------------------------------------

func (*Device) BaseModel

func (entity *Device) BaseModel() *BaseModel

BaseModel returns the reference to the base model

func (*Device) BeforeCreate

func (entity *Device) BeforeCreate(tx *gorm.DB) error

BeforeCreate to validate and set default

func (*Device) Find

func (entity *Device) Find(db *gorm.DB, conds ...interface{}) ([]Entity, error)

Find entities that meets certain conditions

type DeviceDevice_family

type DeviceDevice_family struct {
	Base            BaseRef `gorm:"embedded"`
	DeviceID        uuid.UUID
	Device_familyID uuid.UUID
}

DeviceDevice_family -----------------------------------------------------------

func (*DeviceDevice_family) BaseRef

func (entity *DeviceDevice_family) BaseRef() *BaseRef

BaseRef returns the reference to the BaseRef model

func (*DeviceDevice_family) Find

func (entity *DeviceDevice_family) Find(db *gorm.DB, conds ...interface{}) ([]RefEntity, error)

Find entities that meets certain conditions

type Device_family

type Device_family struct {
	Base BaseModel `gorm:"embedded" parentTypes:"project"`
}

Device_family -----------------------------------------------------------------

func (*Device_family) BaseModel

func (entity *Device_family) BaseModel() *BaseModel

BaseModel returns the reference to the base model

func (*Device_family) BeforeCreate

func (entity *Device_family) BeforeCreate(tx *gorm.DB) error

BeforeCreate to validate and set default

func (*Device_family) Find

func (entity *Device_family) Find(db *gorm.DB, conds ...interface{}) ([]Entity, error)

Find entities that meets certain conditions

type Domain

type Domain struct {
	Base BaseModel `gorm:"embedded"`
}

Domain -----------------------------------------------------------------

func (*Domain) BaseModel

func (entity *Domain) BaseModel() *BaseModel

BaseModel returns the reference to the base model

func (*Domain) BeforeCreate

func (entity *Domain) BeforeCreate(tx *gorm.DB) error

BeforeCreate to validate and set default

func (*Domain) Find

func (entity *Domain) Find(db *gorm.DB, conds ...interface{}) ([]Entity, error)

Find entities that meets certain conditions

type Entity

type Entity interface {
	BaseModel() *BaseModel
	Find(db *gorm.DB, conds ...interface{}) ([]Entity, error)
}

Entity is base interface for all models

func NewEntity

func NewEntity(entityType string) (Entity, error)

NewEntity is the factory function to construct a new entity by type

type ModelInfo

type ModelInfo struct {
	ParentTypes      []string
	ChildTypes       []string
	RefTypes         []string
	BackRefTypes     []string
	NormalizedFields []string
}

ModelInfo contains entity model meta info

func GetModelInfo

func GetModelInfo(entity Entity) (ModelInfo, bool)

GetModelInfo return entity model meta info

type Project

type Project struct {
	Base BaseModel `gorm:"embedded" parentTypes:"domain"`
}

Project -----------------------------------------------------------------

func (*Project) BaseModel

func (entity *Project) BaseModel() *BaseModel

BaseModel returns the reference to the base model

func (*Project) BeforeCreate

func (entity *Project) BeforeCreate(tx *gorm.DB) error

BeforeCreate to validate and set default

func (*Project) Find

func (entity *Project) Find(db *gorm.DB, conds ...interface{}) ([]Entity, error)

Find entities that meets certain conditions

type RefEntity

type RefEntity interface {
	BaseRef() *BaseRef
	Find(db *gorm.DB, conds ...interface{}) ([]RefEntity, error)
}

RefEntity is the base interface for all refs

func NewRefEntity

func NewRefEntity(refEntityType string) (RefEntity, error)

NewRefEntity is the factory function to construct a new entity by type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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