new
This commit is contained in:
34
data/view/genfunc/gen.base.go
Normal file
34
data/view/genfunc/gen.base.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package genfunc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
type _BaseMgr struct {
|
||||
*gorm.DB
|
||||
ctx *context.Context
|
||||
}
|
||||
|
||||
// SetCtx set context
|
||||
func (obj *_BaseMgr) SetCtx(c *context.Context) {
|
||||
obj.ctx = c
|
||||
}
|
||||
|
||||
////////////////////////////////////////////logic
|
||||
|
||||
type _ExampleMgr struct {
|
||||
*_BaseMgr
|
||||
}
|
||||
|
||||
// ExampleMgr open func
|
||||
func ExampleMgr(db *gorm.DB) *_ExampleMgr {
|
||||
if db == nil {
|
||||
panic(fmt.Errorf("ExampleMgr init need db"))
|
||||
}
|
||||
return &_ExampleMgr{_BaseMgr: &_BaseMgr{DB: db}}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
1
data/view/genfunc/genfunc.go
Normal file
1
data/view/genfunc/genfunc.go
Normal file
@@ -0,0 +1 @@
|
||||
package genfunc
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"github.com/xxjwxc/gormt/data/view/model/genmysql"
|
||||
)
|
||||
|
||||
// GetModel get model interface. 获取model接口
|
||||
func GetModel() model.IModel {
|
||||
// GetMysqlModel get model interface. 获取model接口
|
||||
func GetMysqlModel() model.IModel {
|
||||
//now just support mysql
|
||||
return &genmysql.MySQLModel
|
||||
}
|
||||
|
||||
@@ -19,20 +19,20 @@ func Execute() {
|
||||
// orm.Where("nickname = ?", "ticket_001").Find(&tt)
|
||||
// fmt.Println(tt)
|
||||
|
||||
modeldb := GetModel()
|
||||
modeldb := GetMysqlModel()
|
||||
pkg := modeldb.GenModel()
|
||||
pkg.PackageName = modeldb.GetPkgName()
|
||||
str := model.Generate(pkg)
|
||||
list := model.Generate(pkg)
|
||||
|
||||
path := config.GetOutDir() + "/" + modeldb.GetDbName() + ".go"
|
||||
tools.WriteFile(path,
|
||||
[]string{str}, true)
|
||||
for _, v := range list {
|
||||
path := config.GetOutDir() + "/" + v.FileName
|
||||
tools.WriteFile(path, []string{v.FileCtx}, true)
|
||||
|
||||
fmt.Println("formatting differs from goimport's:")
|
||||
cmd, _ := exec.Command("goimports", "-l", "-w", path).Output()
|
||||
fmt.Println(string(cmd))
|
||||
fmt.Println("formatting differs from goimport's:")
|
||||
cmd, _ := exec.Command("goimports", "-l", "-w", path).Output()
|
||||
fmt.Println(string(cmd))
|
||||
|
||||
fmt.Println("formatting differs from gofmt's:")
|
||||
cmd, _ = exec.Command("gofmt", "-l", "-w", path).Output()
|
||||
fmt.Println(string(cmd))
|
||||
fmt.Println("formatting differs from gofmt's:")
|
||||
cmd, _ = exec.Command("gofmt", "-l", "-w", path).Output()
|
||||
fmt.Println(string(cmd))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ const (
|
||||
|
||||
// DBInfo database default info
|
||||
type DBInfo struct {
|
||||
PackageName string
|
||||
DbName string // database name
|
||||
PackageName string // package name
|
||||
TabList []TabInfo // table list .表列表
|
||||
}
|
||||
|
||||
@@ -60,3 +61,9 @@ type BaseInfo struct {
|
||||
Name string // table name.表名
|
||||
Notes string // table comment . 表注释
|
||||
}
|
||||
|
||||
// GenOutInfo generate file list. 生成的文件列表
|
||||
type GenOutInfo struct {
|
||||
FileName string // output file name .输出文件名
|
||||
FileCtx string // output file context.输出文件内容
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ func (m *mysqlModel) GenModel() model.DBInfo {
|
||||
|
||||
var dbInfo model.DBInfo
|
||||
getPackageInfo(orm, &dbInfo)
|
||||
dbInfo.PackageName = m.GetPkgName()
|
||||
dbInfo.DbName = m.GetDbName()
|
||||
return dbInfo
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user