model

package
v0.4.14 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeEnum         = Type{Key: "enum", Title: "Enum", Plural: "Enums", Icon: "list"}
	TypeStruct       = Type{Key: "struct", Title: "Struct", Plural: "Structs", Icon: "struct"}
	TypeInterface    = Type{Key: "interface", Title: "Interface", Plural: "Interfaces", Icon: "list"}
	TypeUnion        = Type{Key: "union", Title: "Union", Plural: "Unions", Icon: "world"}
	TypeIntersection = Type{Key: "intersection", Title: "Intersection", Plural: "Intersections", Icon: "world"}
	TypeUnknown      = Type{Key: "unknown", Title: "Unknown", Plural: "Unknowns", Icon: "world"}
)

Functions

func GetStrings

func GetStrings(src field.Fields, tgt []string, vals []any) ([]string, error)

func GetValues

func GetValues(src field.Fields, tgt []string, vals []any) ([]any, error)

Types

type Index

type Index struct {
	Key      string          `json:"key"`
	Fields   []string        `json:"type"`
	Unique   bool            `json:"unique,omitempty"`
	Primary  bool            `json:"primary,omitempty"`
	Metadata *field.Metadata `json:"metadata,omitempty"`
}

func (Index) String

func (i Index) String() string

type Indexes

type Indexes []*Index

func (Indexes) Get

func (s Indexes) Get(key string) *Index

type Metadata

type Metadata struct {
	Description string   `json:"description,omitempty"`
	Comments    []string `json:"comments,omitempty"`
	Source      string   `json:"source,omitempty"`
	Line        int      `json:"line,omitempty"`
	Column      int      `json:"column,omitempty"`
}

type Model

type Model struct {
	Key           string        `json:"key"`
	Pkg           util.Pkg      `json:"pkg,omitempty"`
	Type          Type          `json:"type"`
	Title         string        `json:"-"` // override only
	Plural        string        `json:"-"` // override only
	Interfaces    []string      `json:"interfaces,omitempty"`
	Fields        field.Fields  `json:"fields,omitempty"`
	Indexes       Indexes       `json:"indexes,omitempty"`
	Relationships Relationships `json:"relationships,omitempty"`
	References    References    `json:"-"` // internal cache
	Metadata      *Metadata     `json:"metadata,omitempty"`
	// contains filtered or unexported fields
}

func NewModel

func NewModel(pkg util.Pkg, key string) *Model

func (*Model) AddField

func (m *Model) AddField(f *field.Field) error

func (*Model) AddIndex

func (m *Model) AddIndex(i *Index) error

func (*Model) AddReference

func (m *Model) AddReference(r *Reference) error

func (*Model) AddRelationship

func (m *Model) AddRelationship(r *Relationship) error

func (*Model) ApplicableRelations

func (m *Model) ApplicableRelations(key string) Relationships

func (*Model) Description

func (m *Model) Description() string

func (*Model) GetPK

func (m *Model) GetPK(logger util.Logger) []string

func (*Model) IsPK

func (m *Model) IsPK(key string, logger util.Logger) bool

func (*Model) Name

func (m *Model) Name() string

func (*Model) OrderedMap

func (m *Model) OrderedMap(data []any) (*util.OrderedMap[any], error)

func (*Model) Path

func (m *Model) Path() util.Pkg

func (*Model) PathString

func (m *Model) PathString() string

func (*Model) PluralName

func (m *Model) PluralName() string

func (*Model) String

func (m *Model) String() string

type Models

type Models []*Model

func (Models) Get

func (m Models) Get(pkg util.Pkg, key string) *Model

func (Models) Names

func (m Models) Names() []string

func (Models) Sort

func (m Models) Sort()

type Package

type Package struct {
	Key           string   `json:"key"`
	Title         string   `json:"title,omitempty"`
	Pkg           util.Pkg `json:"pkg"`
	ChildModels   Models   `json:"childModels,omitempty"`
	ChildPackages Packages `json:"childPackages,omitempty"`
}

func ToModelPackage

func ToModelPackage(models Models) *Package

func (*Package) Add

func (p *Package) Add(pkg util.Pkg, m *Model)

func (*Package) Get

func (p *Package) Get(paths []string) (any, []string)

func (*Package) GetModel

func (p *Package) GetModel(key string) *Model

func (*Package) GetPkg

func (p *Package) GetPkg(key string, createIfMissing bool) *Package

func (*Package) Name

func (p *Package) Name() string

func (*Package) Path

func (p *Package) Path() util.Pkg

func (*Package) PathString

func (p *Package) PathString() string

type Packages

type Packages []*Package

type Reference

type Reference struct {
	Key          string   `json:"key"`
	TargetFields []string `json:"tgtFields"`
	SourcePkg    util.Pkg `json:"sourcePackage"`
	SourceModel  string   `json:"sourceModel"`
	SourceFields []string `json:"srcFields"`
	// contains filtered or unexported fields
}

func ReferenceFromRelation

func ReferenceFromRelation(rel *Relationship, m *Model) *Reference

func (*Reference) Debug

func (r *Reference) Debug() string

func (*Reference) String

func (r *Reference) String() string

type References

type References []*Reference

func (References) Get

func (s References) Get(key string) *Reference

type Relationship

type Relationship struct {
	Key          string   `json:"key"`
	SourceFields []string `json:"srcFields"`
	TargetPkg    util.Pkg `json:"tgtPackage"`
	TargetModel  string   `json:"tgtModel"`
	TargetFields []string `json:"tgtFields"`
}

func (*Relationship) Path

func (r *Relationship) Path() string

func (*Relationship) String

func (r *Relationship) String() string

type Relationships

type Relationships []*Relationship

func (Relationships) Get

func (s Relationships) Get(key string) *Relationship

type Type

type Type struct {
	Key    string
	Title  string
	Plural string
	Icon   string
}

func (*Type) MarshalText added in v0.2.16

func (t *Type) MarshalText() ([]byte, error)

func (*Type) String

func (t *Type) String() string

func (*Type) UnmarshalText added in v0.2.16

func (t *Type) UnmarshalText(data []byte) error

Jump to

Keyboard shortcuts

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