model

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

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,
	}
)
View Source
var (
	FmtCode       = Format{Key: "code", Title: "Code", Description: ""}
	FmtCodeHidden = Format{Key: "codehidden", Title: "Code (hidden)", Description: ""}
	FmtCountry    = Format{Key: "country", Title: "Country", Description: ""}
	FmtHTML       = Format{Key: "html", Title: "HTML", Description: ""}
	FmtIcon       = Format{Key: "icon", Title: "Icon", Description: ""}
	FmtJSON       = Format{Key: "json", Title: "JSON", Description: ""}
	FmtLinebreaks = Format{Key: "linebreaks", Title: "Linebreaks", Description: ""}
	FmtSelect     = Format{Key: "select", Title: "Select Box", Description: ""}
	FmtSI         = Format{Key: "si", Title: "SI Units", Description: ""}
	FmtSQL        = Format{Key: "sql", Title: "SQL", Description: ""}
	FmtTags       = Format{Key: "tags", Title: "Tags", Description: ""}
	FmtURL        = Format{Key: "url", Title: "URL", Description: ""}

	AllFormats = Formats{FmtCode, FmtCodeHidden, FmtCountry, FmtHTML, FmtJSON, FmtSelect, FmtSI, FmtSQL, FmtURL}
)
View Source
var ColumnFieldDescs = util.FieldDescs{
	{Key: "name", Title: "Name", Description: "The name of the column"},
	{Key: "type", Title: "Type", Description: "The type of the column", Type: "type"},
	{Key: "pk", Title: "PK", Description: "Indicates if this column is a primary key", Type: "bool"},
	{Key: "nullable", Title: "Nullable", Description: "Indicates if this column is nullable", Type: "bool"},
	{Key: "search", Title: "Search", Description: "Indicates if this column is included in search", Type: "bool"},

	{Key: "indexed", Title: "Indexed", Description: "Indicates if this column is indexed", Type: "bool"},
	{Key: "display", Title: "Display", Description: "The display setting of the column's value"},
	{Key: "format", Title: "Format", Description: "The formatting applied to the column's value"},
	{Key: "example", Title: "Example", Description: "Example annotation for the column's value"},
	{Key: "json", Title: "JSON", Description: "JSON field name to use instead of [name]"},
	{Key: "validation", Title: "Validation", Description: "Validation annotation for the column's value"},
}
View Source
var IndexFieldDescs = util.FieldDescs{
	{Key: "name", Title: "Name", Description: "The name of the index"},
	{Key: "decl", Title: "Declaration", Description: "The declaration of the index"},
}
View Source
var LinkFieldDescs = util.FieldDescs{
	{Key: "title", Title: "Title", Description: "The title of the link"},
	{Key: "icon", Title: "Icon", Description: "The icon of this link"},
	{Key: "url", Title: "URL", Description: "The href of this link"},
}
View Source
var RelationFieldDescs = util.FieldDescs{
	{Key: "name", Title: "Name", Description: "The name of the relation"},
	{Key: "src", Title: "Source", Description: "The source columns of the relation"},
	{Key: "table", Title: "Table", Description: "The target table of the relation"},
	{Key: "tgt", Title: "Target", Description: "The target columns of the relation"},
}

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 Help

func Help(t types.Type, f string, nullable bool, 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, nullable bool, 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.Wrapped, prop string, nullable bool, format string, verbose bool, url bool, enums enum.Enums, src string) string

func ToSQLType

func ToSQLType(t types.Type, database string) (string, error)

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"`
	Acronyms   []string                   `json:"acronyms,omitempty"`
	GroupsFile json.RawMessage            `json:"-"`
	Modules    []string                   `json:"-"`
	Database   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) DatabaseNow added in v0.11.28

func (a *Args) DatabaseNow() 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"`
	JSON        string         `json:"json,omitempty"`
	SQLOverride string         `json:"sql,omitempty"`
	Example     string         `json:"example,omitempty"`
	Validation  string         `json:"validation,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) SQL added in v1.2.3

func (c *Column) SQL() 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, enums enum.Enums, src string) string

func (*Column) ToSQLType

func (c *Column) ToSQLType(database string) (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) SQL added in v1.2.3

func (c Columns) SQL() []string

func (Columns) SQLQuoted added in v1.2.3

func (c Columns) SQLQuoted() []string

func (Columns) Searches

func (c Columns) Searches() Columns

func (Columns) Smushed

func (c Columns) Smushed() string

func (Columns) Titles added in v0.11.28

func (c Columns) Titles() []string

func (Columns) TitlesLower

func (c Columns) TitlesLower() []string

func (Columns) ToGoStrings

func (c Columns) ToGoStrings(prefix string, alwaysString bool, maxLength int) 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) WithDisplay added in v1.0.6

func (c Columns) WithDisplay(f string) Columns

func (Columns) WithFormat added in v1.0.5

func (c Columns) WithFormat(f string) Columns

func (Columns) WithTag

func (c Columns) WithTag(t string) Columns

func (Columns) WithoutDisplays added in v1.0.6

func (c Columns) WithoutDisplays(f ...string) Columns

func (Columns) WithoutFormats added in v1.0.6

func (c Columns) WithoutFormats(f ...string) Columns

func (Columns) WithoutTags added in v1.0.5

func (c Columns) WithoutTags(t ...string) Columns

func (Columns) ZeroVals

func (c Columns) ZeroVals() []string

type Format added in v1.0.5

type Format struct {
	Key         string
	Title       string
	Description string
}

func (*Format) MarshalJSON added in v1.0.5

func (x *Format) MarshalJSON() ([]byte, error)

func (*Format) UnmarshalJSON added in v1.0.5

func (x *Format) UnmarshalJSON(data []byte) error

type Formats added in v1.0.5

type Formats []Format

func (Formats) Get added in v1.0.5

func (l Formats) Get(s string, logger util.Logger) Format

type Group

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

func (*Group) HasTag

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

func (*Group) IconSafe

func (g *Group) IconSafe() string

func (*Group) Proper added in v1.0.6

func (g *Group) Proper() string

func (*Group) String added in v1.0.6

func (g *Group) String() string

func (*Group) TitleSafe

func (g *Group) TitleSafe() string

type Groups

type Groups []*Group

func (Groups) Flatten added in v1.0.6

func (g Groups) Flatten() Groups

func (Groups) Get

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

func (Groups) Strings added in v1.0.6

func (g Groups) Strings(prefix string) []string

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 Link struct {
	Title string `json:"title,omitempty"`
	URL   string `json:"url"`
	Icon  string `json:"icon,omitempty"`
}
type Links []*Link

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"`
	SortIndex      int              `json:"sortIndex,omitempty"`
	View           string           `json:"view,omitempty"`
	Search         []string         `json:"search,omitempty"`
	Tags           []string         `json:"tags,omitempty"`
	TitleOverride  string           `json:"title,omitempty"`
	PluralOverride string           `json:"plural,omitempty"`
	ProperOverride string           `json:"proper,omitempty"`
	TableOverride  string           `json:"table,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"`
	Links          Links            `json:"links,omitempty"`
}

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

func (m *Model) HasSearches() bool

func (*Model) HasTag

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

func (*Model) IconSafe

func (m *Model) IconSafe() string

func (*Model) IndexedColumns added in v0.6.20

func (m *Model) IndexedColumns(includePK bool) Columns

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, enums enum.Enums) 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) ProperWithGroup added in v1.0.6

func (m *Model) ProperWithGroup(extraAcronyms []string) 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) Table added in v1.2.3

func (m *Model) Table() 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) SortedDisplay added in v0.11.9

func (m Models) SortedDisplay() Models

func (Models) SortedRoutes added in v1.2.0

func (m Models) SortedRoutes() Models

func (Models) Validate added in v0.8.10

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

func (Models) WithTag added in v1.2.9

func (m Models) WithTag(tag string) Models

func (Models) WithoutTag added in v1.2.9

func (m Models) WithoutTag(tag string) Models

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() string

func (*Relation) TgtColumns

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

func (*Relation) TgtQuoted

func (r *Relation) TgtQuoted() string

func (*Relation) WebPath

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

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