func generateModelFields(table *Table, depth int, option *GenerateOption) string {
	structure := ""
	for _, column := range table.Columns {
		valueType := mysqlTypeToGoType(column.Type, !column.NotNull, option.WithGureguTypes)
		fieldName := fmtFieldName(stringifyFirstChar(column.Name))
		var annotations []string
		if option.WithGormAnnotation {
			annotations = append(annotations, generateGormAnnotation(column))
		}
		if option.WithJsonAnnotation {
			annotations = append(annotations, generateJSONAnnotation(column))
		}
		if option.WithDBAnnotation {
			annotations = append(annotations, generateDBAnnotation(column))
		}
		if option.WithXmlAnnotation {
			annotations = append(annotations, generateXMLAnnotation(column))
		}
		if option.WithXormAnnotation {
			annotations = append(annotations, generateXormAnnotation(column))
		}
		if option.WithFakerAnnotation {
			annotations = append(annotations, generateFakerAnnotation(column))
		}
		if len(annotations) > 0 {
			structure += fmt.Sprintf("\n%s %s `%s`",
				fieldName,
				valueType,
				strings.Join(annotations, " "))
		} else {
			structure += fmt.Sprintf("\n%s %s",
				fieldName,
				valueType)
		}
	}
	return structure
}
generateMysqlTypes go struct entries for a map[string]interface{} structure
package bases
import (
	"bytes"
	"database/sql"
	"fmt"
	"strconv"
	"strings"
	"github.com/sirupsen/logrus"
)
func ConnectToDB(user, password, host string, port int, dbname string) (*sql.DB, error) {
	var err error
	var db *sql.DB
	if password != "" {
		db, err = sql.Open("mysql", user+":"+password+"@tcp("+host+":"+strconv.Itoa(port)+")/"+dbname+"?&parseTime=True")
	} else {
		db, err = sql.Open("mysql", user+"@tcp("+host+":"+strconv.Itoa(port)+")/"+dbname+"?&parseTime=True")
	}
	if err != nil {
		return nil, err
	}
	if err := db.Ping(); err != nil {
		return nil, err
	}
	return db, nil
}
func GetTableInfo(user string, password string, host string, port int, dbname string, tableName string) (*Table, error) {
	db, err := ConnectToDB(user, password, host, port, dbname)
	if err != nil {
		logrus.Errorln("Error opening mysql db: " + err.Error())
		return nil, err
	}
	defer db.Close()
	columnDataTypeQuery := "SELECT `COLUMN_NAME`, COLUMN_KEY, DATA_TYPE,COLUMN_DEFAULT, IS_NULLABLE,CHARACTER_MAXIMUM_LENGTH,EXTRA,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ? AND table_name = ?"
	rows, err := db.Query(columnDataTypeQuery, dbname, tableName)
	if err != nil {
		logrus.Errorln("Error selecting from db: " + err.Error())
		return nil, err
	}
	table := &Table{
		Name:    tableName,
		Columns: make([]Column, 0),
	}
	for rows.Next() {
		var columnName string
		var columnKey string
		var dataType string
		var defaultValue sql.NullString
		var nullable string
		var maxLength sql.NullInt64
		var extra string
		var comment string
		if err := rows.Scan(&columnName, &columnKey, &dataType, &defaultValue, &nullable, &maxLength, &extra, &comment); err != nil {
			logrus.Errorln("scan rows error:", err)
			return nil, err
		}
		table.Columns = append(table.Columns, Column{
			Name:       columnName,
			Comment:    comment,
			Type:       dataType,
			Size:       int(maxLength.Int64),
			NotNull:    !(nullable == "YES"),
			Default:    defaultValue.String,
			AutoInc:    isAutoInc(extra),
			Unique:     isUnique(columnKey),
			PrimaryKey: isPrimaryKey(columnKey),
		})
	}
	return table, nil
}
func isAutoInc(extra string) bool {
	return strings.Contains(extra, "auto_increment")
}
func isUnique(columnKey string) bool {
	return isPrimaryKey(columnKey) || strings.Contains(columnKey, "UNI")
}
func isPrimaryKey(columnKey string) bool {
	return strings.Contains(columnKey, "PRI")
}