57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// Db 数据库信息
|
|
type Db struct {
|
|
Database string `json:"database" gorm:"column:database"`
|
|
}
|
|
|
|
// Table 表信息
|
|
type Table struct {
|
|
TableName string `json:"tableName" gorm:"column:table_name"`
|
|
}
|
|
|
|
// Column 列信息
|
|
type Column struct {
|
|
ColumnName string `json:"columnName" gorm:"column:column_name"`
|
|
DataType string `json:"dataType" gorm:"column:data_type"`
|
|
DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"`
|
|
ColumnComment string `json:"columnComment" gorm:"column:column_comment"`
|
|
PrimaryKey int `json:"primaryKey" gorm:"column:primary_key"`
|
|
}
|
|
|
|
// AutoCodeRepo 自动代码仓储接口
|
|
type AutoCodeRepo interface {
|
|
GetDB(ctx context.Context) ([]Db, error)
|
|
GetTables(ctx context.Context, dbName string) ([]Table, error)
|
|
GetColumn(ctx context.Context, tableName, dbName string) ([]Column, error)
|
|
}
|
|
|
|
// AutoCodeUsecase 自动代码用例
|
|
type AutoCodeUsecase struct {
|
|
repo AutoCodeRepo
|
|
}
|
|
|
|
// NewAutoCodeUsecase 创建自动代码用例
|
|
func NewAutoCodeUsecase(repo AutoCodeRepo) *AutoCodeUsecase {
|
|
return &AutoCodeUsecase{repo: repo}
|
|
}
|
|
|
|
// GetDB 获取所有数据库
|
|
func (uc *AutoCodeUsecase) GetDB(ctx context.Context) ([]Db, error) {
|
|
return uc.repo.GetDB(ctx)
|
|
}
|
|
|
|
// GetTables 获取指定数据库的所有表
|
|
func (uc *AutoCodeUsecase) GetTables(ctx context.Context, dbName string) ([]Table, error) {
|
|
return uc.repo.GetTables(ctx, dbName)
|
|
}
|
|
|
|
// GetColumn 获取指定表的所有列
|
|
func (uc *AutoCodeUsecase) GetColumn(ctx context.Context, tableName, dbName string) ([]Column, error) {
|
|
return uc.repo.GetColumn(ctx, tableName, dbName)
|
|
}
|