entity

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType = errors.New("invalid type, must be struct or pointer to struct")
)

Functions

func CellIsLazy

func CellIsLazy(cell *Cell) bool

func NewLazyCollection

func NewLazyCollection(extractor func() *Collection, afterInit func(collection *Collection)) *lazyCollection

func NewLazyWrappedEntity

func NewLazyWrappedEntity(extractor func() *Collection, afterInit func(entity *Cell)) *lazyEntity

Types

type Box

type Box struct {
	Entity interface{}
	Meta   *MetaInfo
}

func NewBox

func NewBox(entity interface{}, meta *MetaInfo) *Box

func (*Box) ExtractPk

func (b *Box) ExtractPk() (interface{}, error)

func (*Box) GetEName

func (b *Box) GetEName() Name

func (*Box) GetRelatedMeta

func (b *Box) GetRelatedMeta(relEntityName Name) *MetaInfo

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

Cell - d3 container for single entity.

func NewCell

func NewCell(entity interface{}) *Cell

NewCell - create new Cell.

func NewCellFromWrapper

func NewCellFromWrapper(w wrapper) *Cell

func (*Cell) DeepCopy

func (c *Cell) DeepCopy() interface{}

func (*Cell) IsNil

func (c *Cell) IsNil() bool

isNil - return true if nil in Cell.

func (*Cell) Unwrap

func (c *Cell) Unwrap() interface{}

unwrap - return entity under Cell.

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

Collection - d3 container for multiple entities of same type.

func NewCollection

func NewCollection(entities ...interface{}) *Collection

NewCollection - create new collection of entities.

func NewCollectionFromCollectionner

func NewCollectionFromCollectionner(c collectionner) *Collection

func (*Collection) Add

func (c *Collection) Add(el interface{})

add - add element to collection.

func (*Collection) Count

func (c *Collection) Count() int

count - return count of elements in collection.

func (*Collection) DeepCopy

func (c *Collection) DeepCopy() interface{}

func (*Collection) Empty

func (c *Collection) Empty() bool

empty - return true if collection has 0 entities, false otherwise.

func (*Collection) Get

func (c *Collection) Get(index int) interface{}

get - get element from collection by index.

func (*Collection) MakeIter

func (c *Collection) MakeIter() *iterator

MakeIter - creates structure for iterate over collection.

func (*Collection) Remove

func (c *Collection) Remove(index int)

remove - delete element from collection by index.

func (*Collection) ToSlice

func (c *Collection) ToSlice() []interface{}

toSlice - return slice of entities.

type Copiable

type Copiable interface {
	DeepCopy() interface{}
}

type Copier

type Copier func(src interface{}) interface{}

type D3Entity

type D3Entity interface {
	D3Token() MetaToken
}

type DeleteStrategy

type DeleteStrategy int
const (
	None DeleteStrategy
	Cascade
	Nullable
)

type FieldComparator

type FieldComparator func(e1, e2 interface{}, fName string) bool

type FieldExtractor

type FieldExtractor func(e interface{}, name string) (interface{}, error)

type FieldInfo

type FieldInfo struct {
	Name           string
	AssociatedType reflect.Type
	DbAlias        string
	FullDbAlias    string
}

type FieldSetter

type FieldSetter func(e interface{}, name string, val interface{}) error

type Index added in v0.1.5

type Index struct {
	Name    string
	Columns []string
	Unique  bool
}

type Instantiator

type Instantiator func() interface{}

type InternalTools

type InternalTools struct {
	ExtractField  FieldExtractor
	SetFieldVal   FieldSetter
	NewInstance   Instantiator
	Copy          Copier
	CompareFields FieldComparator
}

type KeyTpl

type KeyTpl struct {
	// contains filtered or unexported fields
}

func (*KeyTpl) Key

func (k *KeyTpl) Key() []interface{}

func (*KeyTpl) Projection

func (k *KeyTpl) Projection() []interface{}

type LazyContainer

type LazyContainer interface {
	IsInitialized() bool
}

type ManyToMany

type ManyToMany struct {
	JoinColumn      string
	ReferenceColumn string
	JoinTable       string
	// contains filtered or unexported fields
}

func (*ManyToMany) DeleteStrategy

func (b *ManyToMany) DeleteStrategy() DeleteStrategy

func (*ManyToMany) ExtractCollection

func (m *ManyToMany) ExtractCollection(ownerBox *Box) (*Collection, error)

func (*ManyToMany) Field

func (b *ManyToMany) Field() *FieldInfo

func (*ManyToMany) RelatedWith

func (b *ManyToMany) RelatedWith() Name

func (*ManyToMany) Type

func (b *ManyToMany) Type() RelationType

type ManyToOne

type ManyToOne struct {
	JoinColumn      string
	ReferenceColumn string
	// contains filtered or unexported fields
}

func (*ManyToOne) DeleteStrategy

func (b *ManyToOne) DeleteStrategy() DeleteStrategy

func (*ManyToOne) Field

func (b *ManyToOne) Field() *FieldInfo

func (*ManyToOne) RelatedWith

func (b *ManyToOne) RelatedWith() Name

func (*ManyToOne) Type

func (b *ManyToOne) Type() RelationType

type ManyToOneInverse

type ManyToOneInverse struct {
	MappedBy string
	// contains filtered or unexported fields
}

func (*ManyToOneInverse) DeleteStrategy

func (b *ManyToOneInverse) DeleteStrategy() DeleteStrategy

func (*ManyToOneInverse) Field

func (b *ManyToOneInverse) Field() *FieldInfo

func (*ManyToOneInverse) RelatedWith

func (b *ManyToOneInverse) RelatedWith() Name

func (*ManyToOneInverse) Type

func (b *ManyToOneInverse) Type() RelationType

type MetaInfo

type MetaInfo struct {
	Tpl        interface{}
	EntityName Name
	TableName  string
	Indexes    []Index

	Relations map[string]Relation
	Fields    map[string]*FieldInfo
	Pk        *pk

	RelatedMeta map[Name]*MetaInfo
	Tools       InternalTools
}

func NewMeta

func NewMeta(e interface{}) (*MetaInfo, error)

func (*MetaInfo) CreateKeyTpl

func (m *MetaInfo) CreateKeyTpl() *KeyTpl

func (*MetaInfo) Deps added in v0.1.1

func (m *MetaInfo) Deps() []Name

func (*MetaInfo) ExtractPkValue

func (m *MetaInfo) ExtractPkValue(entity interface{}) (interface{}, error)

func (*MetaInfo) FindRelativeMetaRecursive

func (m *MetaInfo) FindRelativeMetaRecursive(entityName Name) (*MetaInfo, bool)

func (*MetaInfo) FullColumnAlias

func (m *MetaInfo) FullColumnAlias(colName string) string

func (*MetaInfo) ManyToManyRelations

func (m *MetaInfo) ManyToManyRelations() []*ManyToMany

func (*MetaInfo) OneToManyRelations

func (m *MetaInfo) OneToManyRelations() []*OneToMany

func (*MetaInfo) OneToOneRelations

func (m *MetaInfo) OneToOneRelations() []*OneToOne

type MetaRegistry

type MetaRegistry struct {
	// contains filtered or unexported fields
}

func NewMetaRegistry

func NewMetaRegistry() *MetaRegistry

func (*MetaRegistry) Add

func (r *MetaRegistry) Add(entities ...interface{}) error

func (*MetaRegistry) ForEach

func (r *MetaRegistry) ForEach(f func(meta *MetaInfo) error) error

func (*MetaRegistry) GetMeta

func (r *MetaRegistry) GetMeta(entity interface{}) (MetaInfo, error)

func (*MetaRegistry) GetMetaByName

func (r *MetaRegistry) GetMetaByName(entityName Name) (MetaInfo, error)

type MetaToken

type MetaToken struct {
	Tools     InternalTools
	Tpl       interface{}
	TableName string
	Indexes   []Index
}

type Name

type Name string

func NameFromEntity

func NameFromEntity(e interface{}) Name

func (Name) Combine added in v0.1.4

func (n Name) Combine(entity Name) Name

func (Name) Equal

func (n Name) Equal(name Name) bool

func (Name) IsShort added in v0.1.1

func (n Name) IsShort() bool

func (Name) Short

func (n Name) Short() string

type OneToMany

type OneToMany struct {
	JoinColumn      string
	ReferenceColumn string
	// contains filtered or unexported fields
}

func (*OneToMany) DeleteStrategy

func (b *OneToMany) DeleteStrategy() DeleteStrategy

func (*OneToMany) ExtractCollection

func (o *OneToMany) ExtractCollection(ownerBox *Box) (*Collection, error)

func (*OneToMany) Field

func (b *OneToMany) Field() *FieldInfo

func (*OneToMany) RelatedWith

func (b *OneToMany) RelatedWith() Name

func (*OneToMany) Type

func (b *OneToMany) Type() RelationType

type OneToOne

type OneToOne struct {
	JoinColumn      string
	ReferenceColumn string
	// contains filtered or unexported fields
}

func (*OneToOne) DeleteStrategy

func (b *OneToOne) DeleteStrategy() DeleteStrategy

func (*OneToOne) Extract

func (o *OneToOne) Extract(ownerBox *Box) (*Cell, error)

func (*OneToOne) Field

func (b *OneToOne) Field() *FieldInfo

func (*OneToOne) RelatedWith

func (b *OneToOne) RelatedWith() Name

func (*OneToOne) Type

func (b *OneToOne) Type() RelationType

type PkStrategy

type PkStrategy int
const (
	Auto PkStrategy
	Manual
)

type Relation

type Relation interface {
	Type() RelationType
	DeleteStrategy() DeleteStrategy
	RelatedWith() Name

	Field() *FieldInfo
	// contains filtered or unexported methods
}

type RelationType

type RelationType int
const (
	Lazy RelationType
	Eager
	SmartLazy
)

Jump to

Keyboard shortcuts

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