代码拉取完成,页面将自动刷新
package models
import (
"database/sql"
"gitee.com/ha666/gen_sqlx_code/utils"
"strings"
)
type IndexInfo struct {
NonUnique int
IndexName string
ColumnName string
Comment string
IndexComment string
ColumnNameCase string
}
func GetIndexInfos(database_name, table_name string) (index_infos []IndexInfo, err error) {
rows, err := mainDB.Query("SELECT NON_UNIQUE,INDEX_NAME,COLUMN_NAME,`COMMENT`,INDEX_COMMENT FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema = ? AND table_name = ?;", database_name, table_name)
defer rows.Close()
if err != nil {
return index_infos, err
}
return _IndexInfoRowsToArray(rows)
}
func _IndexInfoRowsToArray(rows *sql.Rows) (models []IndexInfo, err error) {
for rows.Next() {
model := IndexInfo{}
err = rows.Scan(&model.NonUnique, &model.IndexName, &model.ColumnName, &model.Comment, &model.IndexComment)
if err != nil {
return models, err
}
if len(model.Comment) > 0 {
model.Comment = strings.Replace(model.Comment, "\r", "", -1)
model.Comment = strings.Replace(model.Comment, "\n", "", -1)
}
if len(model.IndexComment) > 0 {
model.IndexComment = strings.Replace(model.IndexComment, "\r", "", -1)
model.IndexComment = strings.Replace(model.IndexComment, "\n", "", -1)
}
model.ColumnNameCase = model.ColumnName
utils.ToBigHump(&model.ColumnNameCase)
models = append(models, model)
}
return models, err
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。