feat: model type change

This commit is contained in:
zhangwenjian
2020-07-10 00:17:01 +08:00
parent 84a78d7b4f
commit 02cc68daea
20 changed files with 286 additions and 257 deletions
+7 -5
View File
@@ -4,6 +4,7 @@ import (
"errors"
"github.com/jinzhu/gorm"
orm "go-admin/global"
"go-admin/tools"
config2 "go-admin/tools/config"
)
@@ -38,7 +39,6 @@ func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int, erro
table = table.Where("TABLE_NAME = ?", e.TableName)
}
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
return nil, 0, err
}
@@ -51,15 +51,17 @@ func (e *DBColumns) GetList() ([]DBColumns, error) {
var doc []DBColumns
table := new(gorm.DB)
if e.TableName == "" {
return nil, errors.New("table name cannot be empty!")
}
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Select("*").Table("information_schema.columns")
table = table.Where("table_schema= ? ", config2.DatabaseConfig.DBName)
if e.TableName == "" {
return nil, errors.New("table name cannot be empty!")
}
table = table.Where("TABLE_NAME = ?", e.TableName)
} else {
tools.Assert(true, "目前只支持mysql数据库", 500)
}
if err := table.Find(&doc).Error; err != nil {
return doc, err