code generation tool

This commit is contained in:
zhangwenjian committed 2020-03-19 22:04:38 +08:00
1 parent 1c650ce539
commit 1b03cf2c48
7 files changed
+261 -79

No files matched your search

+32 -14
View File
@@ -9,28 +9,28 @@ type DBColumns struct {
//select COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_SET_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT
//from information_schema.`COLUMNS` where table_schema='test1db' and TABLE_NAME='sys_config'
TableSchema string `gorm:"column:TABLE_SCHEMA" json:"tableSchema"`
TableName string `gorm:"column:TABLE_NAME" json:"tableName"`
Engine string `gorm:"column:COLUMN_NAME" json:"engine"`
TableRows string `gorm:"column:COLUMN_DEFAULT" json:"tableRows"`
TableCollation string `gorm:"column:IS_NULLABLE" json:"tableCollation"`
CreateTime string `gorm:"column:DATA_TYPE" json:"createTime"`
UpdateTime string `gorm:"column:CHARACTER_MAXIMUM_LENGTH" json:"updateTime"`
TableComment string `gorm:"column:CHARACTER_SET_NAME" json:"tableComment"`
ColumnType string `gorm:"column:COLUMN_TYPE" json:"columnType"`
ColumnKey string `gorm:"column:COLUMN_KEY" json:"columnKey"`
Extra string `gorm:"column:EXTRA" json:"extra"`
ColumnComment string `gorm:"column:COLUMN_COMMENT" json:"columnComment"`
TableSchema string `gorm:"column:TABLE_SCHEMA" json:"tableSchema"`
TableName string `gorm:"column:TABLE_NAME" json:"tableName"`
ColumnName string `gorm:"column:COLUMN_NAME" json:"columnName"`
ColumnDefault string `gorm:"column:COLUMN_DEFAULT" json:"columnDefault"`
IsNullable string `gorm:"column:IS_NULLABLE" json:"isNullable"`
DataType string `gorm:"column:DATA_TYPE" json:"dataType"`
CharacterMaximumLength string `gorm:"column:CHARACTER_MAXIMUM_LENGTH" json:"characterMaximumLength"`
CharacterSetName string `gorm:"column:CHARACTER_SET_NAME" json:"characterSetName"`
ColumnType string `gorm:"column:COLUMN_TYPE" json:"columnType"`
ColumnKey string `gorm:"column:COLUMN_KEY" json:"columnKey"`
Extra string `gorm:"column:EXTRA" json:"extra"`
ColumnComment string `gorm:"column:COLUMN_COMMENT" json:"columnComment"`
}
func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int32, error) {
var doc []DBColumns
table := orm.Eloquent.Select("*").Table("information_schema.`COLUMNS`")
table=table.Where("table_schema='test1db'")
table = table.Where("table_schema='test1db'")
if e.TableName != "" {
return nil,0,errors.New("table name cannot be empty!")
return nil, 0, errors.New("table name cannot be empty!")
}
table = table.Where("TABLE_NAME = ?", e.TableName)
@@ -43,3 +43,21 @@ func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int32, er
table.Count(&count)
return doc, count, nil
}
func (e *DBColumns) GetList() ([]DBColumns, error) {
var doc []DBColumns
table := orm.Eloquent.Select("*").Table("information_schema.columns")
table = table.Where("table_schema='test1db'")
if e.TableName == "" {
return nil, errors.New("table name cannot be empty!")
}
table = table.Where("TABLE_NAME = ?", e.TableName)
if err := table.Find(&doc).Error; err != nil {
return doc, err
}
return doc, nil
}