From d8054d8defb8f8b6116ede0656c4dbe07a0156a5 Mon Sep 17 00:00:00 2001 From: Mikael <13247629622@163.com> Date: Wed, 23 Mar 2022 18:55:16 +0800 Subject: [PATCH] fix -cache=true insert no clean cache (#1672) * fix -cache=true insert no clean cache * fix -cache=true insert no clean cache --- tools/goctl/model/sql/gen/insert.go | 1 - tools/goctl/model/sql/template/insert.go | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/goctl/model/sql/gen/insert.go b/tools/goctl/model/sql/gen/insert.go index 46c28748..1ca7b312 100644 --- a/tools/goctl/model/sql/gen/insert.go +++ b/tools/goctl/model/sql/gen/insert.go @@ -55,7 +55,6 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error) Parse(text). Execute(map[string]interface{}{ "withCache": withCache, - "containsIndexCache": table.ContainsUniqueCacheKey, "upperStartCamelObject": camel, "lowerStartCamelObject": stringx.From(camel).Untitle(), "expression": strings.Join(expressions, ", "), diff --git a/tools/goctl/model/sql/template/insert.go b/tools/goctl/model/sql/template/insert.go index 115ea7ff..0339808c 100644 --- a/tools/goctl/model/sql/template/insert.go +++ b/tools/goctl/model/sql/template/insert.go @@ -3,13 +3,11 @@ package template // Insert defines a template for insert code in model var Insert = ` func (m *default{{.upperStartCamelObject}}Model) Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error) { - {{if .withCache}}{{if .containsIndexCache}}{{.keys}} + {{if .withCache}}{{.keys}} ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet) return conn.ExecCtx(ctx, query, {{.expressionValues}}) }, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet) - ret,err:=m.ExecNoCacheCtx(ctx, query, {{.expressionValues}}) - {{end}}{{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet) ret,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}} return ret,err }