feat: Database type support
This commit is contained in:
1 parent
ab34ba8aad
commit
a6970e9c67
20 files changed
+190
-301
No files matched your search
+38
-17
@@ -2,6 +2,7 @@ package tools
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/jinzhu/gorm"
|
||||
"go-admin/global/orm"
|
||||
config2 "go-admin/tools/config"
|
||||
)
|
||||
@@ -18,34 +19,54 @@ type DBTables struct {
|
||||
|
||||
func (e *DBTables) GetPage(pageSize int, pageIndex int) ([]DBTables, int, error) {
|
||||
var doc []DBTables
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("information_schema.tables")
|
||||
table = table.Where("TABLE_NAME not in (select table_name from "+config2.DatabaseConfig.Name+".sys_tables) ")
|
||||
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name)
|
||||
|
||||
if e.TableName != "" {
|
||||
table = table.Where("TABLE_NAME = ?", e.TableName)
|
||||
}
|
||||
|
||||
table := new(gorm.DB)
|
||||
var count int
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
if config2.DatabaseConfig.DbType == "mysql" {
|
||||
table = orm.Eloquent.Select("*").Table("information_schema.tables")
|
||||
table = table.Where("TABLE_NAME not in (select table_name from " + config2.DatabaseConfig.Mysql.DBName + ".sys_tables) ")
|
||||
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Mysql.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 {
|
||||
return nil, 0, err
|
||||
}
|
||||
} else if config2.DatabaseConfig.DbType == "sqlite3" {
|
||||
table = orm.Eloquent.Select("name as TABLE_NAME,name as ENGINE,name as TABLE_ROWS,name as TABLE_COLLATION,name as CREATE_TIME,name as UPDATE_TIME,name as TABLE_COMMENT ").Table("sqlite_master")
|
||||
table = table.Where("type = 'table' ")
|
||||
|
||||
if e.TableName != "" {
|
||||
table = table.Where("name = ?", e.TableName)
|
||||
}
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
table.Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
func (e *DBTables) Get() (DBTables, error) {
|
||||
var doc DBTables
|
||||
table := new(gorm.DB)
|
||||
if config2.DatabaseConfig.DbType == "mysql" {
|
||||
table = orm.Eloquent.Select("*").Table("information_schema.tables")
|
||||
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Mysql.DBName)
|
||||
if e.TableName == "" {
|
||||
return doc, errors.New("table name cannot be empty!")
|
||||
}
|
||||
table = table.Where("TABLE_NAME = ?", e.TableName)
|
||||
} else if config2.DatabaseConfig.DbType == "sqlite3" {
|
||||
table = orm.Eloquent.Select("name as TABLE_NAME,name as ENGINE,name as TABLE_ROWS,name as TABLE_COLLATION,name as CREATE_TIME,name as UPDATE_TIME,name as TABLE_COMMENT ").Table("sqlite_master")
|
||||
table = table.Where("type = 'table' ")
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("information_schema.tables")
|
||||
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name)
|
||||
if e.TableName == "" {
|
||||
return doc, errors.New("table name cannot be empty!")
|
||||
if e.TableName != "" {
|
||||
table = table.Where("name = ?", e.TableName)
|
||||
}
|
||||
}
|
||||
table = table.Where("TABLE_NAME = ?", e.TableName)
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user