mysql

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MySQLCmd = &cobra.Command{
		Use:                   "mysql",
		Short:                 "generete model from mysql datasource and basic CRUD base on GORM",
		DisableFlagsInUseLine: true,
		Run: func(cmd *cobra.Command, args []string) {
			datasource := viper.GetString("datasource")
			filter := viper.GetString("filter")
			dir := viper.GetString("dir")
			pkg := viper.GetString("pkg")
			gormcomment := viper.GetBool("gormcomment")

			x := regexp.MustCompile(filter)

			config := &Config{
				Dir:         dir,
				Pkg:         pkg,
				Filter:      x,
				Gormcomment: gormcomment,
			}

			err := NewMySQLGenerator(config).Gen(datasource)
			if err != nil {
				log.Error("generate error", zap.Error(err))
			}
		},
	}
)

Functions

This section is empty.

Types

type Config added in v1.0.11

type Config struct {
	Dir         string
	Pkg         string
	Filter      *regexp.Regexp
	Gormcomment bool
}

type Field

type Field struct {
	TableName     string
	ColumnName    string
	ColumnDefault string
	IsNullable    bool
	DataType      string
	ColumnType    string
	ColumnKey     string
	Extra         string
	ColumnComment string
	GoType        string         `gorm:"-"`
	Statement     *jen.Statement `gorm:"-"`
}

type MySQLGenerator

type MySQLGenerator struct {
	Config *Config
	Tables []*Table
}

func NewMySQLGenerator

func NewMySQLGenerator(config *Config) *MySQLGenerator

func (*MySQLGenerator) Gen

func (t *MySQLGenerator) Gen(dsn string) error

type Table

type Table struct {
	Name      string
	Comment   string
	Fields    []*Field
	Statement *jen.Statement
}

Jump to

Keyboard shortcuts

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