easycode

package
v0.0.0-...-70261f9 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

inject 使用ast在文件中指定位置注入代码 --east

plate 模版生成

provider 数据库操作帮助

controller --- api.handler service --- api.logic repository--- rpc.handler、logic entity--- model

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Replace        bool //是否替换文件
	ReplaceCommon  bool //是否替换自定义文件
	GenerateCommon bool //生成自定义文件

	OutPath   string                                   // 输出路径
	OutFileNS func(tableName string) (fileName string) // 输出文件名称

	FieldNullable     bool // generate pointer when field is nullable
	FieldCoverable    bool // generate pointer when field has default value, to fix problem zero value cannot be assign: https://gorm.io/docs/create.html#Default-Values
	FieldSignable     bool // detect integer field's unsigned type, adjust generated data type
	FieldWithIndexTag bool // generate with gorm index tag
	FieldWithTypeTag  bool // generate with gorm column type tag

	IgnoreMap map[string]string
	// contains filtered or unexported fields
}

func (*Config) ConvertStructMetas

func (cfg *Config) ConvertStructMetas(structs ...interface{}) (metas []*plate.PlateMeta, err error)

ConvertStructs convert to base structures

func (*Config) Revise

func (cfg *Config) Revise() (err error)

func (*Config) WithDataTypeMap

func (cfg *Config) WithDataTypeMap(newMap map[string]func(columnType gorm.ColumnType) (dataType string))

WithDataTypeMap specify data type mapping relationship, only work when syncing table from db

func (*Config) WithJSONTagNameStrategy

func (cfg *Config) WithJSONTagNameStrategy(ns func(columnName string) (tagContent string))

WithJSONTagNameStrategy specify json tag naming strategy

type Generator

type Generator struct {
	*log.Logger

	InjectMetas []*inject.AstInjectMeta
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator(cfg Config) *Generator

func (*Generator) ApplyMetas

func (g *Generator) ApplyMetas(plates []*plate.PlateMeta, injects []*inject.AstInjectMeta)

func (*Generator) Execute

func (g *Generator) Execute()

Execute generate code to output path

func (*Generator) GenFieldConfig

func (g *Generator) GenFieldConfig() *field.FieldConfig

func (*Generator) GenerateCommonFile

func (g *Generator) GenerateCommonFile(tableName string, tableComment string) error

func (*Generator) GenerateMetasFromModel

func (g *Generator) GenerateMetasFromModel(tableName, tableComment string, fields []*provider.Field) ([]*plate.PlateMeta, []*inject.AstInjectMeta)

使用data进行创建

func (*Generator) GenerateMetasFromSchema

func (g *Generator) GenerateMetasFromSchema() ([]*plate.PlateMeta, []*inject.AstInjectMeta)

创建数据库中所有表

func (*Generator) GenerateMetasFromTable

func (g *Generator) GenerateMetasFromTable(tableName, tableComment string) ([]*plate.PlateMeta, []*inject.AstInjectMeta)

创建一个表

func (*Generator) GetTemplateDatas

func (g *Generator) GetTemplateDatas() []*plate.AutoCodeStructData

func (*Generator) InitPackage

func (g *Generator) InitPackage(tableName string)

func (*Generator) RollBack

func (g *Generator) RollBack()

func (*Generator) UseDB

func (g *Generator) UseDB(db *gorm.DB)

UseDB set db connection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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