model

package
v0.10.18 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

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

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

func AsEnum(t types.Type) (*types.Enum, error)

func AsEnumInstance added in v0.6.14

func AsEnumInstance(t types.Type, enums enum.Enums) (*enum.Enum, error)

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, enums enum.Enums) (string, error)

func ToGoRowType added in v0.7.16

func ToGoRowType(t types.Type, nullable bool, pkg string, enums enum.Enums, database string) (string, error)

func ToGoString

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

func ToGoType

func ToGoType(t types.Type, nullable bool, pkg string, enums enum.Enums) (string, error)

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, error)

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"`
	ConfigFile json.RawMessage            `json:"-"`
	Enums      enum.Enums                 `json:"enums,omitempty"`
	EnumFiles  map[string]json.RawMessage `json:"-"`
	Models     Models                     `json:"models,omitempty"`
	ModelFiles map[string]json.RawMessage `json:"-"`
	Groups     Groups                     `json:"groups,omitempty"`
	GroupsFile json.RawMessage            `json:"-"`
	Modules    []string                   `json:"-"`
}

func (*Args) Audit added in v0.9.7

func (a *Args) Audit(m *Model) bool

func (*Args) DBRef

func (a *Args) DBRef() string

func (*Args) Database added in v0.8.24

func (a *Args) Database() 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"`
	Indexed    bool           `json:"indexed,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) AddTag added in v0.8.25

func (c *Column) AddTag(t string)

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(enums enum.Enums) (string, error)

func (*Column) NameQuoted

func (c *Column) NameQuoted() string

func (*Column) NeedsErr added in v0.8.25

func (c *Column) NeedsErr(_ string, database string) bool

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) RemoveTag added in v0.8.25

func (c *Column) RemoveTag(t 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) ToGoEditString

func (c *Column) ToGoEditString(prefix string, format string, id string, enums enum.Enums) (string, error)

func (*Column) ToGoMapParse

func (c *Column) ToGoMapParse() string

func (*Column) ToGoRowType added in v0.7.16

func (c *Column) ToGoRowType(pkg string, enums enum.Enums, database string) (string, error)

func (*Column) ToGoString

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

func (*Column) ToGoType

func (c *Column) ToGoType(pkg string, enums enum.Enums) (string, error)

func (*Column) ToGoViewString

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

func (*Column) ToSQLType

func (c *Column) ToSQLType() (string, error)

func (*Column) ZeroVal

func (c *Column) ZeroVal() string

type Columns

type Columns []*Column

func (Columns) Args

func (c Columns) Args(pkg string, enums enum.Enums) (string, error)

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) GoRowTypes added in v0.7.16

func (c Columns) GoRowTypes(pkg string, enums enum.Enums, database string) ([]string, error)

func (Columns) GoTypeKeys

func (c Columns) GoTypeKeys(pkg string, enums enum.Enums) ([]string, error)

func (Columns) GoTypes

func (c Columns) GoTypes(pkg string, enums enum.Enums) ([]string, error)

func (Columns) HasFormat

func (c Columns) HasFormat(f string) bool

func (Columns) MaxCamelLength

func (c Columns) MaxCamelLength() int

func (Columns) MaxGoRowTypeLength added in v0.7.16

func (c Columns) MaxGoRowTypeLength(pkg string, enums enum.Enums, database string) int

func (Columns) MaxGoTypeLength

func (c Columns) MaxGoTypeLength(pkg string, enums enum.Enums) 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, relCols ...*Column) string

func (Columns) Types

func (c Columns) Types() types.Types

func (Columns) WhereClause

func (c Columns) WhereClause(offset int, placeholder string) 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"`
	Unique bool   `json:"unique,omitempty"`
}

func (*Index) SQL added in v0.8.9

func (i *Index) SQL() string

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) AddTag added in v0.8.25

func (m *Model) AddTag(t string)

func (*Model) AllSearches added in v0.7.4

func (m *Model) AllSearches(database string) []string

func (*Model) Breadcrumbs

func (m *Model) Breadcrumbs() string

func (*Model) Camel

func (m *Model) Camel() string

func (*Model) CamelPlural

func (m *Model) CamelPlural() string

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) HasSearches added in v0.8.25

func (m *Model) HasSearches() bool

func (*Model) HasTag

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

func (*Model) Help

func (m *Model) Help(enums enum.Enums) (string, error)

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) IndexedColumns added in v0.6.20

func (m *Model) IndexedColumns() Columns

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, models Models, 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

func (Models) Validate added in v0.8.10

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

type Relation

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

func (*Relation) ContainsSource added in v0.6.20

func (r *Relation) ContainsSource(colName string) bool

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

func (Relations) ContainsSource added in v0.6.20

func (r Relations) ContainsSource(colName string) bool

Jump to

Keyboard shortcuts

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