model

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 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: ""}
	FmtColor      = Format{Key: "color", Title: "Color", Description: ""}
	FmtCountry    = Format{Key: "country", Title: "Country", Description: ""}
	FmtHTML       = Format{Key: "html", Title: "HTML", Description: ""}
	FmtIcon       = Format{Key: "icon", Title: "Icon", Description: ""}
	FmtImage      = Format{Key: "image", Title: "Image", Description: ""}
	FmtJSON       = Format{Key: "json", Title: "JSON", Description: ""}
	FmtLinebreaks = Format{Key: "linebreaks", Title: "Linebreaks", Description: ""}
	FmtSelect     = Format{Key: "select", Title: "Select Box", Description: ""}
	FmtSeconds    = Format{Key: "seconds", Title: "Seconds", 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, FmtColor, FmtCountry, FmtHTML, FmtIcon, FmtImage, FmtJSON, FmtSelect, FmtSeconds, 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: "url", Title: "URL", Description: "The href of this link"},
	{Key: "icon", Title: "Icon", Description: "The icon of this link"},
	{Key: "dangerous", Title: "Dangerous", Description: "If set, this link will require confirmation", Type: "bool"},
	{Key: "tags", Title: "Tags", Description: "The tags that apply to this link", Type: "[]string"},
}
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

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

func AsEnumInstance

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

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, display 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) ApplyAcronyms added in v1.4.3

func (a *Args) ApplyAcronyms(acronyms ...string)

func (*Args) Audit

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

func (*Args) DBRef

func (a *Args) DBRef() string

func (*Args) DatabaseNow

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"`
	TitleOverride  string         `json:"title,omitempty"`
	PluralOverride string         `json:"plural,omitempty"`
	ProperOverride string         `json:"proper,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"`
	// contains filtered or unexported fields
}

func (*Column) AddTag

func (c *Column) AddTag(t string)

func (*Column) BC

func (c *Column) BC() string

func (*Column) Camel

func (c *Column) Camel() string

func (*Column) CamelNoReplace added in v1.4.5

func (c *Column) CamelNoReplace() string

func (*Column) CamelPlural

func (c *Column) CamelPlural() string

func (*Column) Clone

func (c *Column) Clone() *Column

func (*Column) Derived added in v1.4.3

func (c *Column) Derived() bool

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

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

func (*Column) Plural

func (c *Column) Plural() string

func (*Column) Proper

func (c *Column) Proper() string

func (*Column) ProperDerived added in v1.4.3

func (c *Column) ProperDerived() string

func (*Column) ProperPlural

func (c *Column) ProperPlural() string

func (*Column) RemoveTag

func (c *Column) RemoveTag(t string)

func (*Column) SQL

func (c *Column) SQL() string

func (*Column) SetAcronyms added in v1.4.3

func (c *Column) SetAcronyms(acronyms ...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

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

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

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) NotDerived added in v1.4.3

func (c Columns) NotDerived() 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

func (c Columns) SQL() []string

func (Columns) SQLQuoted

func (c Columns) SQLQuoted() []string

func (Columns) Searches

func (c Columns) Searches() Columns

func (Columns) Smushed

func (c Columns) Smushed() string

func (Columns) Titles

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

func (c Columns) WithDisplay(f string) Columns

func (Columns) WithFormat

func (c Columns) WithFormat(f string) Columns

func (Columns) WithTag

func (c Columns) WithTag(t string) Columns

func (Columns) WithoutDisplays

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

func (Columns) WithoutFormats

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

func (Columns) WithoutTags

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

func (Columns) ZeroVals

func (c Columns) ZeroVals() []string

type Format

type Format struct {
	Key         string
	Title       string
	Description string
}

func (*Format) MarshalJSON

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

func (*Format) UnmarshalJSON

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

type Formats

type Formats []Format

func (Formats) Get

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

func (g *Group) Proper() string

func (*Group) String

func (g *Group) String() string

func (*Group) TitleSafe

func (g *Group) TitleSafe() string

type Groups

type Groups []*Group

func (Groups) Flatten

func (g Groups) Flatten() Groups

func (Groups) Get

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

func (Groups) Strings

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

type Import added in v1.4.5

type Import struct {
	Type      ImportType `json:"type"`
	Value     string     `json:"value"`
	Alias     string     `json:"alias,omitempty"`
	Supported []string   `json:"supported,omitempty"`
}

func NewImport added in v1.4.5

func NewImport(t ImportType, v string) *Import

func (*Import) Equals added in v1.4.5

func (i *Import) Equals(x *Import) bool

func (*Import) Render added in v1.4.5

func (i *Import) Render() string

func (*Import) Supports added in v1.4.5

func (i *Import) Supports(key string) bool

func (*Import) WithAlias added in v1.4.5

func (i *Import) WithAlias(a string) *Import

type ImportType added in v1.4.5

type ImportType string
const (
	ImportTypeInternal ImportType = "internal"
	ImportTypeExternal ImportType = "external"
	ImportTypeApp      ImportType = "app"
)

type Imports added in v1.4.5

type Imports []*Import

func (Imports) Add added in v1.4.5

func (i Imports) Add(imports ...*Import) Imports

func (Imports) Render added in v1.4.5

func (i Imports) Render(linebreak string) string

func (Imports) RenderHTML added in v1.4.5

func (i Imports) RenderHTML(linebreak string) string

func (Imports) Supporting added in v1.4.5

func (i Imports) Supporting(key string) Imports

type Index

type Index struct {
	Name   string `json:"name"`
	Decl   string `json:"decl"`
	Unique bool   `json:"unique,omitempty"`
}

func (*Index) SQL

func (i *Index) SQL() string

type Indexes

type Indexes []*Index

func (Indexes) Get added in v1.3.2

func (i Indexes) Get(name string) *Index
type Link struct {
	Title     string   `json:"title,omitempty"`
	URL       string   `json:"url"`
	Icon      string   `json:"icon,omitempty"`
	Dangerous bool     `json:"dangerous,omitempty"`
	Tags      []string `json:"tags,omitempty"`
}
type Links []*Link

func (Links) WithTags

func (l Links) WithTags(includeEmpty bool, tags ...string) Links

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"`
	Imports        Imports          `json:"imports,omitempty"`
	// contains filtered or unexported fields
}

func (*Model) AddTag

func (m *Model) AddTag(t string)

func (*Model) AllSearches

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

func (*Model) Breadcrumbs

func (m *Model) Breadcrumbs() string

func (*Model) CSRoute

func (m *Model) CSRoute() string

func (*Model) Camel

func (m *Model) Camel() string

func (*Model) CamelLower

func (m *Model) CamelLower() 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

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

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) 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) PluralLower

func (m *Model) PluralLower() string

func (*Model) Proper

func (m *Model) Proper() string

func (*Model) ProperPlural

func (m *Model) ProperPlural() string

func (*Model) ProperWithGroup

func (m *Model) ProperWithGroup() string

func (*Model) RelationsFor

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

func (*Model) Route

func (m *Model) Route() string

func (*Model) SetAcronyms added in v1.4.3

func (m *Model) SetAcronyms(acronyms ...string)

func (*Model) SoftDeleteSuffix

func (m *Model) SoftDeleteSuffix() string

func (*Model) Table

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

func (m Models) SortedDisplay() Models

func (Models) SortedRoutes

func (m Models) SortedRoutes() Models

func (Models) Validate

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

func (Models) WithTag

func (m Models) WithTag(tag string) Models

func (Models) WithoutTag

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

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

type Relations

type Relations []*Relation

func (Relations) ContainsSource

func (r Relations) ContainsSource(colName string) bool

func (Relations) Get added in v1.3.2

func (r Relations) Get(name string) *Relation

Jump to

Keyboard shortcuts

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