gengormstruct

package module
v0.0.0-...-d37b195 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

gen_gorm_struct

生成gorm结构体

如果你使用gorm并且你也在使用mysql,而且你也需要根据mysql表生成结构体,那么就可以使用整个工具。 可以选择增加form和json tag

用法

./cmd -h
Usage of ./cmd:
  -P int
        db port (default 3306)
  -d string
        db name (default "test")
  -form
        with form tag
  -h string
        db host (default "127.0.0.1")
  -json
        with json tag
  -p string
        db password (default "123456")
  -t string
        tableName name
  -u string
        db user (default "root")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCaseString

func CamelCaseString(s string) string

CamelCaseString convert string to camel case

Example:

CamelCaseString("foo_id")

Output: FooId

func FilterColumnTypeSize

func FilterColumnTypeSize(columnType string) string

过滤columnType中的大小 比如bigint(21) unsigned => bigint unsigned

func FormatSourceCode

func FormatSourceCode(input string) (output string)

func GenGormTable

func GenGormTable(config DbConfig, option OutputOption, tableName string) (err error)

GenGormTable 生成单表

func GenOrmDatabase

func GenOrmDatabase(config DbConfig, option OutputOption) (err error)

GenOrmDatabase 生成整个数据库

func MysqlTypeToGoType

func MysqlTypeToGoType(mysqlType string) string

func StringInSlice

func StringInSlice(input string, list []string) bool

Types

type Column

type Column struct {
	Name string
	Type string
	Tag  *OrmTag
}

type DbConfig

type DbConfig struct {
	DbName     string
	DbUser     string
	DbPassword string
	DbHost     string
	DbPort     int
}

type GormGenerator

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

func NewGormGenerator

func NewGormGenerator(c OutputOption) *GormGenerator

func (*GormGenerator) FormatTable

func (p *GormGenerator) FormatTable(table *Table) string

type MysqlDB

type MysqlDB struct {
	DbConfig
	// contains filtered or unexported fields
}

func NewMysqlDB

func NewMysqlDB(config DbConfig) (mdb MysqlDB, err error)

func (*MysqlDB) GetColumns

func (p *MysqlDB) GetColumns(tableName string, pkColumns []string) (columns []*Column)

GetColumns retrieves columns details from information_schema and fill in the Column struct

func (*MysqlDB) GetPkColumns

func (p *MysqlDB) GetPkColumns(tableName string) (pks []string)

GetPkColumns 获取主键

func (*MysqlDB) GetTable

func (p *MysqlDB) GetTable(tableName string) (table *Table)

func (*MysqlDB) GetTableNames

func (p *MysqlDB) GetTableNames() (tables []string)

GetTableNames returns a slice of table names in the current database

type OrmTag

type OrmTag struct {
	AutoPk     bool   // 是否是自增主键
	Pk         bool   // 是否是主键
	Null       bool   // 是否允许null
	Column     string // mysql字段名
	AutoNow    bool   // updated_at
	AutoNowAdd bool   // created_at
	Type       string // mysql 字段类型
	Default    string
	HasDefault bool // 是否you默认值
	Comment    string
}

type OutputOption

type OutputOption struct {
	JsonTag    bool
	FormTag    bool
	OutputMode string
}

func (OutputOption) GetOutputMode

func (p OutputOption) GetOutputMode() io.WriteCloser

type Table

type Table struct {
	Name          string
	Pks           []string
	Columns       []*Column
	ImportTimePkg bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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