From c07b527119cee64ffc2f3baa9f23262b1da1cea4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 01:36:15 +0000 Subject: [PATCH] chore(template): update .template go-zero/model --- .template/go-zero/model/model-new.tpl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.template/go-zero/model/model-new.tpl b/.template/go-zero/model/model-new.tpl index 879d231c..b1d4f31a 100644 --- a/.template/go-zero/model/model-new.tpl +++ b/.template/go-zero/model/model-new.tpl @@ -1,9 +1,15 @@ func new{{.upperStartCamelObject}}Model(conn sqlx.SqlConn, op ...opts.Opt[modelx.ModelOpts]) *default{{.upperStartCamelObject}}Model { - {{if .withCache}}o := opts.DefaultApply(op...){{end}} + o := opts.DefaultApply(op...) + var cachedConn sqlc.CachedConn + if len(o.CacheConf) > 0 { + cachedConn = sqlc.NewConn(conn, o.CacheConf, o.CacheOpts...) + } + if o.CachedConn != nil { + cachedConn = *o.CachedConn + } return &default{{.upperStartCamelObject}}Model{ - {{if .withCache}}cachedConn: sqlc.NewConn(conn, o.CacheConf, o.CacheOpts...),{{end}} + cachedConn: cachedConn, conn: conn, table: {{.table}}, } -} - +} \ No newline at end of file