5 Star 6 Fork 2

ha666/gen_sqlx_code

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index_info.go 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
ha666 提交于 2018-11-26 10:30 +08:00 . 方法名统一为大驼峰命名法
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ha666/gen_sqlx_code.git
git@gitee.com:ha666/gen_sqlx_code.git
ha666
gen_sqlx_code
gen_sqlx_code
73bfd39c7980

搜索帮助