radiantpro

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const MDateFormat = "20060102_150405"

Variables

View Source
var (
	SQLModeUp   = "up"
	SQLModeDown = "down"
)
View Source
var CompareExcept = []string{"@radicalGenerateTime"}
View Source
var DefaultradiantPro = &Container{
	radiantProFile: system.CurrentDir + "/radiantpro.toml",
	TimestampFile:  system.CurrentDir + "/.radiantpro.timestamp",
	GoModFile:      system.CurrentDir + "/go.mod",
	UserOption: UserOption{
		Debug:         false,
		ContextDebug:  false,
		Dsn:           "",
		Driver:        "mysql",
		ProType:       "default",
		ApiPrefix:     "/api",
		EnableModule:  nil,
		Models:        make(map[string]TextModel),
		GitRemotePath: "https://github.com/radiant/radiant-pro.git",
		Branch:        "master",
		GitLocalPath:  system.RadiantHome + "/radiant-pro",
		EnableFormat:  true,
		SourceGen:     "text",
		EnableGitPull: true,
		Path: map[string]string{
			"radiant": ".",
		},
		EnableGomod:    true,
		RefreshGitTime: 24 * 3600,
		Extend:         nil,
	},
	GenerateTime:     time.Now().Format(MDateFormat),
	GenerateTimeUnix: time.Now().Unix(),
	TmplOption:       TmplOption{},
	CurPath:          system.CurrentDir,
	EnableModules:    make(map[string]interface{}),
	FunctionOnce:     make(map[string]sync.Once),
}
View Source
var ParserDriver = map[string]Parser{
	"text":  &TextParser{},
	"mysql": &MysqlParser{},
}
View Source
var SQLMode utils.DocValue
View Source
var SQLModePath utils.DocValue

Functions

func FileContentChange

func FileContentChange(org, new []byte, seg string) bool

func GetFilterContent

func GetFilterContent(content string, seg string) string

func GetSeg

func GetSeg(ext string) string

Types

type Container

type Container struct {
	TimestampFile    string                 // store ts file
	GoModFile        string                 // go mod file
	UserOption       UserOption             // user option
	TmplOption       TmplOption             // tmpl option
	CurPath          string                 // user current path
	EnableModules    map[string]interface{} // radiant pro provider a collection of module
	FunctionOnce     map[string]sync.Once   // exec function once
	Timestamp        Timestamp
	GenerateTime     string
	GenerateTimeUnix int64
	Parser           Parser
	// contains filtered or unexported fields
}

store all data

func (*Container) GenConfig

func (c *Container) GenConfig()

func (*Container) Migration

func (c *Container) Migration(args []string)

func (*Container) Run

func (c *Container) Run()

type Descriptor

type Descriptor struct {
	Module  string `toml:"module"`
	SrcName string `toml:"srcName"`
	DstPath string `toml:"dstPath"`
	Once    bool   `toml:"once"`
	Script  string `toml:"script"`
}

func (Descriptor) ExecScript

func (d Descriptor) ExecScript(path string) (err error)

func (Descriptor) IsExistScript

func (descriptor Descriptor) IsExistScript() bool

func (Descriptor) Parse

func (descriptor Descriptor) Parse(modelName string, paths map[string]string) (newDescriptor Descriptor, ctx pongo2.Context)

type ModelInfo

type ModelInfo struct {
	Name      string `json:"name"`      // mysql name
	InputType string `json:"inputType"` // user input type
	MysqlType string `json:"mysqlType"` // mysql type
	GoType    string `json:"goType"`    // go type
	Orm       string `json:"orm"`       // orm tag
	Comment   string `json:"comment"`   // mysql comment
	Extend    string `json:"extend"`    // user extend info
}

parse get the model info

func (ModelInfo) GetColumnKey

func (m ModelInfo) GetColumnKey() (columnKey string)

func (ModelInfo) IsPrimaryKey

func (m ModelInfo) IsPrimaryKey() (flag bool)

type ModelInfos

type ModelInfos []ModelInfo

func (ModelInfos) ToModelSchemas

func (modelInfos ModelInfos) ToModelSchemas() (output ModelSchemas)

to render model schemas

type ModelSchema

type ModelSchema struct {
	Name      string // column name
	InputType string // user input type
	MysqlType string // mysql type
	ColumnKey string // PRI
	Comment   string // comment
	GoType    string // go type
	OrmTag    string // orm tag
	Extend    string
}

type ModelSchemas

type ModelSchemas []*ModelSchema

func (ModelSchemas) GetPrimaryKey

func (m ModelSchemas) GetPrimaryKey() string

func (ModelSchemas) IsExistTime

func (m ModelSchemas) IsExistTime() bool

type MysqlParser

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

func (*MysqlParser) GetRenderInfos

func (m *MysqlParser) GetRenderInfos(descriptor Descriptor) (output []RenderInfo)

func (*MysqlParser) Parse

func (*MysqlParser) Parse(descriptor Descriptor)

func (*MysqlParser) RegisterOption

func (m *MysqlParser) RegisterOption(userOption UserOption, tmplOption TmplOption)

func (*MysqlParser) Unregister

func (t *MysqlParser) Unregister()

type Parser

type Parser interface {
	RegisterOption(userOption UserOption, tmplOption TmplOption)
	Parse(descriptor Descriptor)
	GetRenderInfos(descriptor Descriptor) (output []RenderInfo)
	Unregister()
}

type RenderFile

type RenderFile struct {
	*pongo2render.Render
	Context      pongo2.Context
	GenerateTime string
	Option       UserOption
	ModelName    string
	PackageName  string
	FlushFile    string
	PkgPath      string
	TmplPath     string
	Descriptor   Descriptor
}

render

func NewRender

func NewRender(m RenderInfo) *RenderFile

func (*RenderFile) Exec

func (r *RenderFile) Exec(name string)

func (*RenderFile) SetContext

func (r *RenderFile) SetContext(key string, value interface{})

type RenderInfo

type RenderInfo struct {
	Module       string
	ModelName    string
	Option       UserOption
	Content      ModelInfos
	Descriptor   Descriptor
	TmplPath     string
	GenerateTime string
}

type TableSchema

type TableSchema struct {
	TableName              string
	ColumnName             string
	IsNullable             string
	DataType               string
	CharacterMaximumLength sql.NullInt64
	NumericPrecision       sql.NullInt64
	NumericScale           sql.NullInt64
	ColumnType             string
	ColumnKey              string
	Comment                string
}

func (TableSchema) ToGoType

func (col TableSchema) ToGoType() (inputType string, goType string, err error)

GetGoDataType maps an SQL data type to Golang data type

type TableSchemas

type TableSchemas []TableSchema

func (TableSchemas) ToTableMap

func (tableSchemas TableSchemas) ToTableMap() (resp map[string]ModelInfos)

type TextModel

type TextModel struct {
	Names    []string
	Orms     []string
	Comments []string
	Extends  []string
}

func (TextModel) ToModelInfos

func (content TextModel) ToModelInfos() (output []ModelInfo)

type TextParser

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

func (*TextParser) GetRenderInfos

func (t *TextParser) GetRenderInfos(descriptor Descriptor) (output []RenderInfo)

func (*TextParser) Parse

func (*TextParser) Parse(descriptor Descriptor)

func (*TextParser) RegisterOption

func (t *TextParser) RegisterOption(userOption UserOption, tmplOption TmplOption)

func (*TextParser) Unregister

func (t *TextParser) Unregister()

type Timestamp

type Timestamp struct {
	GitCacheLastRefresh int64 `toml:"gitCacheLastRefresh"`
	Generate            int64 `toml:"generate"`
}

type TmplOption

type TmplOption struct {
	RenderPath string `toml:"renderPath"`
	Descriptor []Descriptor
}

tmpl option

type UserOption

type UserOption struct {
	Debug          bool                 `json:"debug"`
	ContextDebug   bool                 `json:"contextDebug"`
	Dsn            string               `json:"dsn"`
	Driver         string               `json:"driver"`
	ProType        string               `json:"proType"`
	ApiPrefix      string               `json:"apiPrefix"`
	EnableModule   []string             `json:"enableModule"`
	Models         map[string]TextModel `json:"models"`
	GitRemotePath  string               `json:"gitRemotePath"`
	Branch         string               `json:"branch"`
	GitLocalPath   string               `json:"gitLocalPath"`
	EnableFormat   bool                 `json:"enableFormat"`
	SourceGen      string               `json:"sourceGen"`
	EnableGitPull  bool                 `json:"enbaleGitPull"`
	Path           map[string]string    `json:"path"`
	EnableGomod    bool                 `json:"enableGomod"`
	RefreshGitTime int64                `json:"refreshGitTime"`
	Extend         map[string]string    `json:"extend"` // extend user data
}

user option

Jump to

Keyboard shortcuts

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