feat: format reference

This commit is contained in:
zhangwenjian committed 2020-08-28 00:02:53 +08:00
1 parent 6877e1324c
commit c69a7d9fd9
87 files changed
+1124 -287

No files matched your search

+7 -5
View File
@@ -2,10 +2,12 @@ package tools
import (
"errors"
"gorm.io/gorm"
orm "go-admin/global"
"go-admin/tools"
config2 "go-admin/tools/config"
"gorm.io/gorm"
)
type DBColumns struct {
@@ -29,7 +31,7 @@ func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int, erro
table := new(gorm.DB)
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Select("*").Table("information_schema.`COLUMNS`")
table = orm.Eloquent.Table("information_schema.`COLUMNS`")
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
if e.TableName != "" {
@@ -39,10 +41,10 @@ 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 {
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
return nil, 0, err
}
table.Count(&count)
//table.Count(&count)
return doc, int(count), nil
}
@@ -56,7 +58,7 @@ func (e *DBColumns) GetList() ([]DBColumns, error) {
}
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Select("*").Table("information_schema.columns")
table = orm.Eloquent.Table("information_schema.columns")
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
table = table.Where("TABLE_NAME = ?", e.TableName).Order("ORDINAL_POSITION asc")
+7 -5
View File
@@ -2,10 +2,12 @@ package tools
import (
"errors"
"gorm.io/gorm"
orm "go-admin/global"
"go-admin/tools"
config2 "go-admin/tools/config"
"gorm.io/gorm"
)
type DBTables struct {
@@ -24,21 +26,21 @@ func (e *DBTables) GetPage(pageSize int, pageIndex int) ([]DBTables, int, error)
var count int64
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Select("*").Table("information_schema.tables")
table = orm.Eloquent.Table("information_schema.tables")
table = table.Where("TABLE_NAME not in (select table_name from " + config2.GenConfig.DBName + ".sys_tables) ")
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
if e.TableName != "" {
table = table.Where("TABLE_NAME = ?", e.TableName)
}
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
return nil, 0, err
}
} else {
tools.Assert(true, "目前只支持mysql数据库", 500)
}
table.Count(&count)
//table.Count(&count)
return doc, int(count), nil
}
@@ -46,7 +48,7 @@ func (e *DBTables) Get() (DBTables, error) {
var doc DBTables
table := new(gorm.DB)
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Select("*").Table("information_schema.tables")
table = orm.Eloquent.Table("information_schema.tables")
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
if e.TableName == "" {
return doc, errors.New("table name cannot be empty!")
+1 -1
View File
@@ -54,7 +54,7 @@ func (SysColumns) TableName() string {
func (e *SysColumns) GetList() ([]SysColumns, error) {
var doc []SysColumns
table := orm.Eloquent.Select("*").Table("sys_columns")
table := orm.Eloquent.Table("sys_columns")
table = table.Where("table_id = ?", e.TableId)
+7 -6
View File
@@ -1,9 +1,10 @@
package tools
import (
"strings"
orm "go-admin/global"
"go-admin/models"
"strings"
)
type SysTables struct {
@@ -52,7 +53,7 @@ type Params struct {
func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int, error) {
var doc []SysTables
table := orm.Eloquent.Select("*").Table("sys_tables")
table := orm.Eloquent.Table("sys_tables")
if e.TBName != "" {
table = table.Where("table_name = ?", e.TBName)
@@ -63,17 +64,17 @@ func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int, erro
var count int64
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
return nil, 0, err
}
table.Where("`deleted_at` IS NULL").Count(&count)
//table.Where("`deleted_at` IS NULL").Count(&count)
return doc, int(count), nil
}
func (e *SysTables) Get() (SysTables, error) {
var doc SysTables
var err error
table := orm.Eloquent.Select("*").Table("sys_tables")
table := orm.Eloquent.Table("sys_tables")
if e.TBName != "" {
table = table.Where("table_name = ?", e.TBName)
@@ -100,7 +101,7 @@ func (e *SysTables) Get() (SysTables, error) {
func (e *SysTables) GetTree() ([]SysTables, error) {
var doc []SysTables
var err error
table := orm.Eloquent.Select("*").Table("sys_tables")
table := orm.Eloquent.Table("sys_tables")
if e.TBName != "" {
table = table.Where("table_name = ?", e.TBName)