增加生成dao的模版

This commit is contained in:
2022-05-16 14:06:41 +08:00
parent f9d322e453
commit da6e156f11
3 changed files with 69 additions and 6 deletions

View File

@ -9,8 +9,6 @@ package sql2go
import (
"strings"
"git.zhangdeman.cn/zhangdeman/util"
)
// GenerateDao 根据sql自动生成dao
@ -26,9 +24,6 @@ func GenerateDao(sql string, packageName string) (string, error) {
if nil != err {
return "", err
}
// 读入模板
tplByte, _ := util.File.ReadFileContent("dao_tpl.tpl")
tpl := string(tplByte)
replaceTable := map[string]string{
"{PACKAGE}": packageName,
"{DATA_STRUCT_DAO}": basic.ModelStruct + "Dao",
@ -40,6 +35,7 @@ func GenerateDao(sql string, packageName string) (string, error) {
"{PRIMARY_KEY_TYPE}": basic.PrimaryFieldType,
}
tpl := DaoTpl
for oldVal, newVal := range replaceTable {
tpl = strings.ReplaceAll(tpl, oldVal, newVal)
}