gen

package
v0.0.0-...-61829c1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFields

func CheckFields(table *builder.Table, fieldNames ...string) (cols builder.Columns, err error)

func ForEachField

func ForEachField(typeStruct *types.Struct, cb func(field *types.Var))

func IndirectType

func IndirectType(tpe types.Type) (types.Type, error)

func WithDefaults

func WithDefaults(dataType string, withDefaults bool, defaultValue string) string

Types

type Config

type Config struct {
	StructName          string
	TableName           string
	Database            string
	WithComments        bool
	WithTableInterfaces bool

	FieldPrimaryKey string
	FieldSoftDelete string
	FieldCreatedAt  string
	FieldUpdatedAt  string

	ConstSoftDeleteTrue  string
	ConstSoftDeleteFalse string
}

func (*Config) Defaults

func (g *Config) Defaults()

type Keys

type Keys struct {
	Primary       sqlx.FieldNames
	Indexes       sqlx.Indexes
	UniqueIndexes sqlx.Indexes
}

func (*Keys) Bind

func (ks *Keys) Bind(table *builder.Table)

func (*Keys) PatchUniqueIndexesWithSoftDelete

func (ks *Keys) PatchUniqueIndexesWithSoftDelete(softDeleteField string)

type Model

type Model struct {
	*types.TypeName
	*codegen.Importer
	*Config
	*Template
	*Keys
	*builder.Table
	Fields             map[string]*types.Var
	FieldAutoIncrement string
	HasSoftDelete      bool
	HasCreatedAt       bool
	HasUpdatedAt       bool
	HasAutoIncrement   bool
}

func NewModel

func NewModel(prog *loader.Program, typeName *types.TypeName, comments string, cfg *Config) *Model

func (*Model) AddColumn

func (m *Model) AddColumn(col *builder.Column, tpe *types.Var)

func (*Model) EnableIfNeed

func (m *Model) EnableIfNeed() string

func (*Model) FieldType

func (m *Model) FieldType(name string) (typ string)

func (*Model) GetComments

func (m *Model) GetComments() map[string]string

func (*Model) IndexFieldNames

func (m *Model) IndexFieldNames() []string

func (*Model) ParseTo

func (m *Model) ParseTo(writer io.Writer, tpl string)

func (*Model) Render

func (m *Model) Render() string

func (*Model) SetCreatedAtIfNeed

func (m *Model) SetCreatedAtIfNeed() string

func (*Model) SetEnabledForFieldValuesAtIfNeed

func (m *Model) SetEnabledForFieldValuesAtIfNeed() string

func (*Model) SetUpdatedAtIfNeed

func (m *Model) SetUpdatedAtIfNeed() string

func (*Model) SetUpdatedForFieldValuesAtIfNeed

func (m *Model) SetUpdatedForFieldValuesAtIfNeed() string

func (*Model) TypeTime

func (m *Model) TypeTime(fieldName string) string

type SqlFuncGenerator

type SqlFuncGenerator struct {
	Config
	// contains filtered or unexported fields
}

func (*SqlFuncGenerator) Load

func (g *SqlFuncGenerator) Load(cwd string)

func (*SqlFuncGenerator) Output

func (g *SqlFuncGenerator) Output(cwd string) codegen.Outputs

func (*SqlFuncGenerator) Pick

func (g *SqlFuncGenerator) Pick()

type TagGenerator

type TagGenerator struct {
	StructNames []string

	WithDefaults bool
	// contains filtered or unexported fields
}

func (*TagGenerator) Load

func (g *TagGenerator) Load(cwd string)

func (*TagGenerator) Output

func (g *TagGenerator) Output(cwd string) codegen.Outputs

func (*TagGenerator) Pick

func (g *TagGenerator) Pick()

type Template

type Template struct {
	// contains filtered or unexported fields
}

func T

func T() *Template

func (*Template) Execute

func (t *Template) Execute(wr io.Writer, data interface{})

func (Template) Funcs

func (t Template) Funcs(funcMap template.FuncMap) *Template

func (Template) Parse

func (t Template) Parse(tpl string) *Template

func (*Template) Render

func (t *Template) Render(data interface{}) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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