From 3ca40001b4aa1666cb3bd0e668195a0d3361dcfb Mon Sep 17 00:00:00 2001 From: anqiansong Date: Wed, 24 May 2023 15:34:26 +0800 Subject: [PATCH] feat(goctl): Add with session for model tpl (#3272) --- tools/goctl/internal/version/version.go | 2 +- tools/goctl/model/sql/template/tpl/model-new.tpl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/goctl/internal/version/version.go b/tools/goctl/internal/version/version.go index 77f93077..103fe713 100644 --- a/tools/goctl/internal/version/version.go +++ b/tools/goctl/internal/version/version.go @@ -6,7 +6,7 @@ import ( ) // BuildVersion is the version of goctl. -const BuildVersion = "1.5.2" +const BuildVersion = "1.5.3" var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5} diff --git a/tools/goctl/model/sql/template/tpl/model-new.tpl b/tools/goctl/model/sql/template/tpl/model-new.tpl index 76598ecd..1743e578 100644 --- a/tools/goctl/model/sql/template/tpl/model-new.tpl +++ b/tools/goctl/model/sql/template/tpl/model-new.tpl @@ -4,3 +4,10 @@ func new{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c ca table: {{.table}}, } } + +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}}, + } +}