model

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FmtCode    = "code"
	FmtCountry = "country"
	FmtURL     = "url"
	FmtSelect  = "select"
)
View Source
const (
	HistoryType  = "history"
	RevisionType = "revision"
)

Variables

View Source
var (
	ExampleColumns = Columns{
		{Name: "id", Type: types.NewUUID(), PK: true, Search: true, HelpString: "The primary key"},
		{Name: "name", Type: types.NewString(), Search: true, HelpString: "The name of the thing"},
		{Name: "created", Type: types.NewTimestamp(), SQLDefault: "now()", Tags: []string{"created"}, HelpString: "Created timestamp"},
		{Name: "deleted_at", Type: types.NewTimestamp(), Nullable: true, Tags: []string{"deleted"}, HelpString: "Optional timestamp"},
	}
	ExampleRelations = Relations{
		{Name: "relation_a", Src: []string{"parent_id"}, Table: "parent", Tgt: []string{"id"}},
	}
	ExampleIndexes = Indexes{
		{Name: "example_idx", Decl: `"table_name" ("id", "created")`},
	}
	Examples = map[string]any{
		"columns":   ExampleColumns,
		"relations": ExampleRelations,
		"indexes":   ExampleIndexes,
	}
)

Functions

func AsRef

func AsRef(t types.Type) (*types.Reference, error)

func ColToString

func ColToString(c *Column, prefix string) string

func ColToViewString

func ColToViewString(c *Column, prefix string) string

func Help

func Help(t types.Type, f string) string

func ToGoDTOType

func ToGoDTOType(t types.Type, nullable bool, pkg string) string

func ToGoString

func ToGoString(t types.Type, prop string, alwaysString bool) string

func ToGoType

func ToGoType(t types.Type, nullable bool, pkg string) string

func ToGoViewString

func ToGoViewString(t types.Type, prop string, nullable bool, format string, verbose bool, url bool) string

func ToSQLType

func ToSQLType(t types.Type) string

func TypeToString

func TypeToString(t types.Type, prop string) string

func TypeToViewString

func TypeToViewString(t types.Type, prop string, nullable bool) string

Types

type Args

type Args struct {
	Config  util.ValueMap `json:"config,omitempty"`
	Models  Models        `json:"models,omitempty"`
	Groups  Groups        `json:"groups,omitempty"`
	Modules []string      `json:"-"`
}

func (*Args) DBRef

func (a *Args) DBRef() string

func (*Args) HasModule

func (a *Args) HasModule(key string) bool

func (*Args) Validate

func (a *Args) Validate() error

type Column

type Column struct {
	Name       string         `json:"name"`
	Type       *types.Wrapped `json:"type"`
	PK         bool           `json:"pk,omitempty"`
	Nullable   bool           `json:"nullable,omitempty"`
	Search     bool           `json:"search,omitempty"`
	SQLDefault string         `json:"sqlDefault,omitempty"`
	Display    string         `json:"display,omitempty"`
	Format     string         `json:"format,omitempty"`
	Values     []string       `json:"values,omitempty"`
	Tags       []string       `json:"tags,omitempty"`
	HelpString string         `json:"helpString,omitempty"`
}

func (*Column) BC

func (c *Column) BC() string

func (*Column) Camel

func (c *Column) Camel() string

func (*Column) CamelPlural

func (c *Column) CamelPlural() string

func (*Column) Clone

func (c *Column) Clone() *Column

func (*Column) HasTag

func (c *Column) HasTag(t string) bool

func (*Column) Help

func (c *Column) Help() string

func (*Column) NameQuoted

func (c *Column) NameQuoted() string

func (*Column) Plural

func (c *Column) Plural() string

func (*Column) Proper

func (c *Column) Proper() string

func (*Column) ProperPlural

func (c *Column) ProperPlural() string

func (*Column) ShouldDisplay

func (c *Column) ShouldDisplay(k string) bool

func (*Column) Title

func (c *Column) Title() string

func (*Column) TitleLower

func (c *Column) TitleLower() string

func (*Column) ToGoDTOType

func (c *Column) ToGoDTOType(pkg string) string

func (*Column) ToGoEditString

func (c *Column) ToGoEditString(prefix string, format string) string

func (*Column) ToGoMapParse

func (c *Column) ToGoMapParse() string

func (*Column) ToGoString

func (c *Column) ToGoString(prefix string) string

func (*Column) ToGoType

func (c *Column) ToGoType(pkg string) string

func (*Column) ToGoViewString

func (c *Column) ToGoViewString(prefix string, verbose bool, url bool) string

func (*Column) ToSQLType

func (c *Column) ToSQLType() string

func (*Column) ZeroVal

func (c *Column) ZeroVal() string

type Columns

type Columns []*Column

func (Columns) Args

func (c Columns) Args(pkg string) string

func (Columns) CamelNames

func (c Columns) CamelNames() []string

func (Columns) ForDisplay

func (c Columns) ForDisplay(k string) Columns

func (Columns) Get

func (c Columns) Get(name string) *Column

func (Columns) GoDTOTypeKeys

func (c Columns) GoDTOTypeKeys(pkg string) []string

func (Columns) GoTypeKeys

func (c Columns) GoTypeKeys(pkg string) []string

func (Columns) GoTypes

func (c Columns) GoTypes(pkg string) []string

func (Columns) HasFormat

func (c Columns) HasFormat(f string) bool

func (Columns) MaxCamelLength

func (c Columns) MaxCamelLength() int

func (Columns) MaxGoDTOKeyLength

func (c Columns) MaxGoDTOKeyLength(pkg string) int

func (Columns) MaxGoKeyLength

func (c Columns) MaxGoKeyLength(pkg string) int

func (Columns) MaxGoTypeLength

func (c Columns) MaxGoTypeLength(pkg string) int

func (Columns) Names

func (c Columns) Names() []string

func (Columns) NamesQuoted

func (c Columns) NamesQuoted() []string

func (Columns) NonPKs

func (c Columns) NonPKs() Columns

func (Columns) OneWithTag

func (c Columns) OneWithTag(t string) (*Column, error)

func (Columns) PKs

func (c Columns) PKs() Columns

func (Columns) ProperNames

func (c Columns) ProperNames() []string

func (Columns) Refs

func (c Columns) Refs() string

func (Columns) Searches

func (c Columns) Searches() Columns

func (Columns) Smushed

func (c Columns) Smushed() string

func (Columns) TitlesLower

func (c Columns) TitlesLower() []string

func (Columns) ToGoStrings

func (c Columns) ToGoStrings(prefix string) string

func (Columns) ToRefs

func (c Columns) ToRefs(prefix string) string

func (Columns) Types

func (c Columns) Types() types.Types

func (Columns) WhereClause

func (c Columns) WhereClause(offset int) string

func (Columns) WithTag

func (c Columns) WithTag(t string) Columns

func (Columns) WithoutTag

func (c Columns) WithoutTag(t string) Columns

func (Columns) ZeroVals

func (c Columns) ZeroVals() []string

type Group

type Group struct {
	Key         string   `json:"key"`
	Title       string   `json:"title,omitempty"`
	Description string   `json:"description,omitempty"`
	Icon        string   `json:"icon,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Children    Groups   `json:"children,omitempty"`
}

func (*Group) HasTag

func (g *Group) HasTag(t string) bool

func (*Group) IconSafe

func (g *Group) IconSafe() string

func (*Group) TitleSafe

func (g *Group) TitleSafe() string

type Groups

type Groups []*Group

func (Groups) Get

func (g Groups) Get(keys ...string) *Group

type HistoryMap

type HistoryMap struct {
	Col   *Column `json:"col"`
	Const Columns `json:"const,omitempty"`
	Var   Columns `json:"var,omitempty"`
	Err   error   `json:"-"`
}

type Index

type Index struct {
	Name string `json:"name"`
	Decl string `json:"decl"`
}

type Indexes

type Indexes []*Index

type Model

type Model struct {
	Name           string           `json:"name"`
	Package        string           `json:"package"`
	Group          []string         `json:"group,omitempty"`
	Description    string           `json:"description,omitempty"`
	Icon           string           `json:"icon,omitempty"`
	Ordering       filter.Orderings `json:"ordering,omitempty"`
	Search         []string         `json:"search,omitempty"`
	History        string           `json:"history,omitempty"`
	Tags           []string         `json:"tags,omitempty"`
	TitleOverride  string           `json:"title,omitempty"`
	ProperOverride string           `json:"proper,omitempty"`
	RouteOverride  string           `json:"route,omitempty"`
	Config         util.ValueMap    `json:"config,omitempty"`
	Columns        Columns          `json:"columns"`
	Relations      Relations        `json:"relations,omitempty"`
	Indexes        Indexes          `json:"indexes,omitempty"`
	SeedData       [][]any          `json:"seedData,omitempty"`
	// contains filtered or unexported fields
}

func (*Model) Breadcrumbs

func (m *Model) Breadcrumbs() string

func (*Model) Camel

func (m *Model) Camel() string

func (*Model) CamelPlural

func (m *Model) CamelPlural() any

func (*Model) CanTraverseRelation

func (m *Model) CanTraverseRelation() bool

func (*Model) ClassRef

func (m *Model) ClassRef() string

func (*Model) FirstLetter

func (m *Model) FirstLetter() string

func (*Model) GroupString

func (m *Model) GroupString(prefix string, dflt string) string

func (*Model) GroupedColumns

func (m *Model) GroupedColumns() Columns

func (*Model) HasTag

func (m *Model) HasTag(t string) bool

func (*Model) Help

func (m *Model) Help() string

func (*Model) HistoryColumn

func (m *Model) HistoryColumn() *Column

func (*Model) HistoryColumns

func (m *Model) HistoryColumns(coreColumns bool) *HistoryMap

func (*Model) IconSafe

func (m *Model) IconSafe() string

func (*Model) IsHistory

func (m *Model) IsHistory() bool

func (*Model) IsRevision

func (m *Model) IsRevision() bool

func (*Model) IsSoftDelete

func (m *Model) IsSoftDelete() bool

func (*Model) LastGroup

func (m *Model) LastGroup(prefix string, dflt string) string

func (*Model) LinkURL

func (m *Model) LinkURL(prefix string) string

func (*Model) PKs

func (m *Model) PKs() Columns

func (*Model) PackageWithGroup

func (m *Model) PackageWithGroup(prefix string) string

func (*Model) Plural

func (m *Model) Plural() string

func (*Model) Proper

func (m *Model) Proper() string

func (*Model) ProperPlural

func (m *Model) ProperPlural() string

func (*Model) RelationsFor

func (m *Model) RelationsFor(col *Column) Relations

func (*Model) Route

func (m *Model) Route() string

func (*Model) SoftDeleteSuffix

func (m *Model) SoftDeleteSuffix() string

func (*Model) Title

func (m *Model) Title() string

func (*Model) TitleLower

func (m *Model) TitleLower() string

func (*Model) TitlePlural

func (m *Model) TitlePlural() string

func (*Model) TitlePluralLower

func (m *Model) TitlePluralLower() string

func (*Model) URLPath

func (m *Model) URLPath(prefix string) string

func (*Model) Validate

func (m *Model) Validate(mods []string, groups Groups) error

type Models

type Models []*Model

func (Models) ForGroup

func (m Models) ForGroup(pth ...string) Models

func (Models) Get

func (m Models) Get(n string) *Model

func (Models) HasSearch

func (m Models) HasSearch() bool

func (Models) HasSeedData

func (m Models) HasSeedData() bool

func (Models) ReverseRelations

func (m Models) ReverseRelations(t string) Relations

func (Models) Sorted

func (m Models) Sorted() Models

type Relation

type Relation struct {
	Name  string   `json:"name"`
	Src   []string `json:"src"`
	Table string   `json:"table"`
	Tgt   []string `json:"tgt"`
}

func (*Relation) Reverse

func (r *Relation) Reverse(name string) *Relation

func (*Relation) SrcColumns

func (r *Relation) SrcColumns(m *Model) Columns

func (*Relation) SrcQuoted

func (r *Relation) SrcQuoted() any

func (*Relation) TgtColumns

func (r *Relation) TgtColumns(m *Model) Columns

func (*Relation) TgtQuoted

func (r *Relation) TgtQuoted() any

func (*Relation) WebPath

func (r *Relation) WebPath(src *Model, tgt *Model, prefix string) any

type Relations

type Relations []*Relation

Jump to

Keyboard shortcuts

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