diff --git a/tools/goctl/model/sql/template/tpl/model-new.tpl b/tools/goctl/model/sql/template/tpl/model-new.tpl index 1743e578..f6271cca 100644 --- a/tools/goctl/model/sql/template/tpl/model-new.tpl +++ b/tools/goctl/model/sql/template/tpl/model-new.tpl @@ -5,9 +5,3 @@ func new{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c ca } } -func (m *default{{.upperStartCamelObject}}Model) withSession(session sqlx.Session) *default{{.upperStartCamelObject}}Model { - return &default{{.upperStartCamelObject}}Model{ - {{if .withCache}}CachedConn:m.CachedConn.WithSession(session){{else}}conn:sqlx.NewSqlConnFromSession(session){{end}}, - table: {{.table}}, - } -} diff --git a/tools/goctl/model/sql/template/tpl/model.tpl b/tools/goctl/model/sql/template/tpl/model.tpl index 3b1b1013..d861da79 100644 --- a/tools/goctl/model/sql/template/tpl/model.tpl +++ b/tools/goctl/model/sql/template/tpl/model.tpl @@ -15,6 +15,7 @@ type ( // and implement the added methods in custom{{.upperStartCamelObject}}Model. {{.upperStartCamelObject}}Model interface { {{.lowerStartCamelObject}}Model + {{if not .withCache}}withSession(session sqlx.Session) {{.upperStartCamelObject}}Model{{end}} } custom{{.upperStartCamelObject}}Model struct { @@ -28,3 +29,10 @@ func New{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c ca default{{.upperStartCamelObject}}Model: new{{.upperStartCamelObject}}Model(conn{{if .withCache}}, c, opts...{{end}}), } } + +{{if not .withCache}} +func (m *custom{{.upperStartCamelObject}}Model) withSession(session sqlx.Session) {{.upperStartCamelObject}}Model { + return New{{.upperStartCamelObject}}Model(sqlx.NewSqlConnFromSession(session)) +} +{{end}} +