util

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GureguNullString = "null.String"
	GureguNullInt    = "null.Int"
	GureguNullFloat  = "null.Float"
	GureguNullBool   = "null.Bool"
	GureguNullTime   = "null.Time"

	SQLNullString  = "sql.NullString"
	SQLNullInt32   = "sql.NullInt32"
	SQLNullInt64   = "sql.NullInt64"
	SQLNullFloat64 = "sql.NullFloat64"
	SQLNullBool    = "sql.NullBool"
	SQLNullTime    = "sql.NullTime"

	GoString      = "string"
	GoBytes       = "[]byte"
	GoInt         = "int"
	GoUint        = "uint"
	GoInt32       = "int32"
	GoUint32      = "uint32"
	GoInt64       = "int64"
	GoUint64      = "uint64"
	GoFloat32     = "float32"
	GoFloat64     = "float64"
	GoBool        = "bool"
	GoTime        = "time.Time"
	GoPointerTime = "*time.Time"
)

Global data type constants.

View Source
const (
	// MySQLDriverName represents the mysql driver name.
	MySQLDriverName = "mysql"
)

Variables

This section is empty.

Functions

func CloseDB added in v1.0.6

func CloseDB()

CloseDB closes the db connection.

func ConvertTable

func ConvertTable(cc CmdConfig) (string, error)

ConvertTable converts mysql table fields to golang model structure by command config.

Types

type CmdConfig added in v1.0.7

type CmdConfig struct {
	DBConfig
	PackageName        string   `json:"package_name"`
	StructName         string   `json:"struct_name"`
	EnableInitialism   bool     `json:"enable_initialism"`
	EnableFieldComment bool     `json:"enable_field_comment"`
	EnableSQLNull      bool     `json:"enable_sql_null"`
	EnableGureguNull   bool     `json:"enable_guregu_null"`
	EnableJSONTag      bool     `json:"enable_json_tag"`
	EnableXMLTag       bool     `json:"enable_xml_tag"`
	EnableGormTag      bool     `json:"enable_gorm_tag"`
	EnableXormTag      bool     `json:"enable_xorm_tag"`
	EnableBeegoTag     bool     `json:"enable_beego_tag"`
	EnableGoroseTag    bool     `json:"enable_gorose_tag"`
	EnableGormV2Tag    bool     `json:"enable_gorm_v2_tag"`
	DisableUnsigned    bool     `json:"disable_unsigned"`
	EnableGoTime       bool     `json:"-"`
	TableComment       string   `json:"-"`
	TableIndexes       []string `json:"-"`
	TableUniques       []string `json:"-"`
}

CmdConfig represents the config of the running grom command line.

type ColumnInfo

type ColumnInfo struct {
	Name            string       `mysql:"COLUMN_NAME"`
	DataType        string       `mysql:"DATA_TYPE"`
	Type            string       `mysql:"COLUMN_TYPE"`
	Default         string       `mysql:"COLUMN_DEFAULT"`
	Comment         string       `mysql:"COLUMN_COMMENT"`
	Length          int64        `mysql:"CHARACTER_MAXIMUM_LENGTH"`
	Precision       int64        `mysql:"NUMERIC_PRECISION"`
	Scale           int64        `mysql:"NUMERIC_SCALE"`
	Position        int          `mysql:"ORDINAL_POSITION"`
	IsPrimaryKey    bool         `mysql:"COLUMN_KEY"`
	IsAutoIncrement bool         `mysql:"EXTRA"`
	IsUnsigned      bool         `mysql:"COLUMN_TYPE"`
	IsNullable      bool         `mysql:"IS_NULLABLE"`
	Indexes         []*IndexInfo `mysql:"-"`
	UniqueIndexes   []*IndexInfo `mysql:"-"`
}

ColumnInfo represents the information of the column.

type DBConfig

type DBConfig struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
	Database string `json:"database"`
	Table    string `json:"table"`
}

DBConfig represents the config of the connected database.

type IndexInfo

type IndexInfo struct {
	Name       string `mysql:"INDEX_NAME"`
	ColumnName string `mysql:"COLUMN_NAME"`
	Comment    string `mysql:"INDEX_COMMENT"`
	Sequence   int    `mysql:"SEQ_IN_INDEX"`
	IsUnique   bool   `mysql:"NON_UNIQUE"`
}

IndexInfo represents the information of the index.

type StructField

type StructField struct {
	Name         string
	Type         string
	Tag          string
	Comment      string
	RawName      string
	Default      string
	IsPrimaryKey bool
	IsNullable   bool
}

StructField represents the field of the generated model structure.

func GetFields added in v1.0.6

func GetFields(cc *CmdConfig) ([]*StructField, error)

GetFields gets golang structure fields converted by mysql table fields. Note that after using this function, you need to call the util.CloseDB() function to close the database.

Jump to

Keyboard shortcuts

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