Code generation module

This commit is contained in:
zhangwenjian committed 2020-03-19 22:04:38 +08:00
1 parent e149589990
commit 65dbf587f9
13 files changed
+497 -62

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
package tools
import (
"errors"
orm "go-admin/database"
)
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"`
}
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'")
if e.TableName != "" {
return nil,0,errors.New("table name cannot be empty!")
}
table = table.Where("TABLE_NAME = ?", e.TableName)
var count int32
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
}
+34
View File
@@ -0,0 +1,34 @@
package tools
import (
orm "go-admin/database"
)
type DBTables struct {
TableName string `gorm:"column:TABLE_NAME" json:"tableName"`
Engine string `gorm:"column:ENGINE" json:"engine"`
TableRows string `gorm:"column:TABLE_ROWS" json:"tableRows"`
TableCollation string `gorm:"column:TABLE_COLLATION" json:"tableCollation"`
CreateTime string `gorm:"column:CREATE_TIME" json:"createTime"`
UpdateTime string `gorm:"column:UPDATE_TIME" json:"updateTime"`
TableComment string `gorm:"column:TABLE_COMMENT" json:"tableComment"`
}
func (e *DBTables) GetPage(pageSize int, pageIndex int) ([]DBTables, int32, error) {
var doc []DBTables
table := orm.Eloquent.Select("*").Table("information_schema.tables")
table=table.Where("table_schema='test1db'")
if e.TableName != "" {
table = table.Where("TABLE_NAME = ?", e.TableName)
}
var count int32
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
}
+52
View File
@@ -0,0 +1,52 @@
package tools
import orm "go-admin/database"
type SysColumns struct {
ColumnId int64 `gorm:"column:configId;primary_key" json:"configId"`
TableId int64 `gorm:"column:configId" json:"configId"`
ColumnName string `gorm:"column:configId" json:"configId"`
ColumnComment string `gorm:"column:column_comment" json:"columnComment"`
ColumnType string `gorm:"column:column_type" json:"columnType"`
GoType string `gorm:"column:go_type" json:"goType"`
GoField string `gorm:"column:go_field" json:"goField"`
IsPk string `gorm:"column:is_pk" json:"isPk"`
IsIncrement string `gorm:"column:is_increment" json:"isIncrement"`
IsRequired string `gorm:"column:is_required" json:"isRequired"`
IsInsert string `gorm:"column:is_insert" json:"isInsert"`
IsEdit string `gorm:"column:is_edit" json:"isEdit"`
IsList string `gorm:"column:is_list" json:"isList"`
IsQuery string `gorm:"column:is_query" json:"isQuery"`
QueryType string `gorm:"column:query_type" json:"queryType"`
HtmlType string `gorm:"column:html_type" json:"htmlType"`
DictType string `gorm:"column:dict_type" json:"dictType"`
Sort string `gorm:"column:sort" json:"sort"`
List string `gorm:"column:list" json:"list"`
Pk bool `gorm:"column:pk" json:"pk"`
Required bool `gorm:"column:required" json:"required"`
SuperColumn bool `gorm:"column:super_column" json:"superColumn"`
UsableColumn bool `gorm:"column:usable_column" json:"usableColumn"`
Increment bool `gorm:"column:increment" json:"increment"`
Insert bool `gorm:"column:insert" json:"insert"`
Edit bool `gorm:"column:edit" json:"edit"`
Query bool `gorm:"column:query" json:"query"`
Remark string `gorm:"column:remark" json:"remark"`
CreateBy string `gorm:"column:create_by" json:"createBy"`
CreateTime string `gorm:"column:create_time" json:"createTime"`
UpdateBy string `gorm:"column:update_By" json:"updateBy"`
UpdateTime string `gorm:"column:update_time" json:"updateTime"`
}
func (e *SysColumns) GetList() ([]SysColumns, error) {
var doc []SysColumns
table := orm.Eloquent.Select("*").Table("sys_columns")
table = table.Where("table_id = ?", e.TableId)
if err := table.Find(&doc).Error; err != nil {
return nil, err
}
return doc, nil
}
+61
View File
@@ -0,0 +1,61 @@
package tools
import orm "go-admin/database"
type SysTables struct {
//表编码
TableId string `gorm:"column:table_id" json:"tableName"`
//表名称
TableName string `gorm:"column:table_name" json:"tableName"`
//表备注
TableComment string `gorm:"column:table_comment" json:"tableComment"`
//类名
ClassName string `gorm:"column:class_name" json:"className"`
TplCategory string `gorm:"column:tpl_category" json:"tplCategory"`
//包名
PackageName string `gorm:"column:package_name" json:"packageName"`
//模块名
ModuleName string `gorm:"column:module_name" json:"moduleName"`
BusinessName string `gorm:"column:business_name" json:"businessName"`
//功能名称
FunctionName string `gorm:"column:function_name" json:"functionName"`
//功能作者
FunctionAuthor string `gorm:"column:function_author" json:"functionAuthor"`
PkColumn string `gorm:"column:pk_column" json:"pkColumn"`
Options string `gorm:"column:options" json:"options"`
TreeCode string `gorm:"column:tree_code" json:"treeCode"`
TreeParentCode string `gorm:"column:tree_parent_code" json:"treeParentCode"`
TreeName string `gorm:"column:tree_name" json:"treeName"`
Tree bool `gorm:"column:tree" json:"tree"`
Crud bool `gorm:"column:crud" json:"crud"`
Remark string `gorm:"column:remark" json:"remark"`
CreateBy string `gorm:"column:create_by" json:"createBy"`
CreateTime string `gorm:"column:create_time" json:"createTime"`
UpdateBy string `gorm:"column:update_By" json:"updateBy"`
UpdateTime string `gorm:"column:update_time" json:"updateTime"`
DataScope string `gorm:"-" json:"dataScope"`
Params string `gorm:"-" json:"params"`
}
func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int32, error) {
var doc []SysTables
table := orm.Eloquent.Select("*").Table("sys_tables")
if e.TableName != "" {
table = table.Where("table_name = ?", e.TableName)
}
if e.TableComment !=""{
table = table.Where("table_comment = ?", e.TableComment)
}
var count int32
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
}