Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DataFuncs = template.FuncMap{ "aliasCols": func(ta TableAlias) func(string) string { return ta.Column }, }
Functions ¶
func FillAliases ¶
FillAliases takes the table information from the driver and fills in aliases where the user has provided none.
This leaves us with a complete list of Go names for all tables, columns, and relationships.
Types ¶
type Aliases ¶
type Aliases struct {
Tables map[string]TableAlias `toml:"tables,omitempty" json:"tables,omitempty" yaml:"tables,omitempty"`
}
Aliases defines aliases for the generation run
func (Aliases) ManyRelationship ¶
func (a Aliases) ManyRelationship(table, fkey, joinTable, joinTableFKey string) RelationshipAlias
ManyRelationship looks up a relationship alias, panics if not found. It will first try to look up a join table relationship, then it will try a normal one-to-many relationship. That's to say joinTable/joinTableFKey are used if they're not empty.
This allows us to skip additional conditionals in the templates.
func (Aliases) Table ¶
func (a Aliases) Table(table string) *TableAlias
Table gets a table alias, panics if not found.
type Data ¶
type Data struct { Tables []database.Table Table database.Table Aliases Aliases // todo remove unused fields after migration //PkgName string Schema string // Helps tune the output DriverName string Dialect database.Dialect Driver database.Interface // LQ and RQ contain a quoted quote that allows us to write // the templates more easily. LQ string RQ string }
func (*Data) DriverTemplates ¶
func (d *Data) DriverTemplates() (map[string]templates.TemplateLoader, error)
func (*Data) ProcessTypeReplacements ¶
func (d *Data) ProcessTypeReplacements(typeReplaces []TypeReplace, importTypeMap importers.Map) importers.Map
ProcessTypeReplacements checks the config for type replacements and performs them.
func (*Data) SchemaTable ¶
type RelationshipAlias ¶
type RelationshipAlias struct { Local string `toml:"local,omitempty" json:"local,omitempty" yaml:"local,omitempty"` Foreign string `toml:"foreign,omitempty" json:"foreign,omitempty" yaml:"foreign,omitempty"` }
RelationshipAlias defines the naming for both sides of a foreign key.
type TableAlias ¶
type TableAlias struct { UpPlural string `toml:"up_plural,omitempty" json:"up_plural,omitempty" yaml:"up_plural,omitempty"` UpSingular string `toml:"up_singular,omitempty" json:"up_singular,omitempty" yaml:"up_singular,omitempty"` DownPlural string `toml:"down_plural,omitempty" json:"down_plural,omitempty" yaml:"down_plural,omitempty"` DownSingular string `toml:"down_singular,omitempty" json:"down_singular,omitempty" yaml:"down_singular,omitempty"` Columns map[string]string `toml:"columns,omitempty" json:"columns,omitempty" yaml:"columns,omitempty"` Relationships map[string]RelationshipAlias `toml:"relationships,omitempty" json:"relationships,omitempty" yaml:"relationships,omitempty"` }
TableAlias defines the spellings for a table name in Go
func (TableAlias) Column ¶
func (t TableAlias) Column(column string) string
Column get's a column's aliased name, panics if not found.
func (TableAlias) Relationship ¶
func (t TableAlias) Relationship(fkey string) RelationshipAlias
Relationship looks up a relationship, panics if not found.
type TypeReplace ¶
type TypeReplace struct { Tables []string `toml:"tables,omitempty" json:"tables,omitempty" yaml:"tables,omitempty"` Match database.Column `toml:"match,omitempty" json:"match,omitempty" yaml:"match,omitempty"` Replace database.Column `toml:"replace,omitempty" json:"replace,omitempty" yaml:"replace,omitempty"` Imports importers.Set `toml:"imports,omitempty" json:"imports,omitempty" yaml:"imports,omitempty"` }
TypeReplace replaces a column type with something else