|
@@ -11,8 +11,13 @@ import (
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/stringx"
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/stringx"
|
|
)
|
|
)
|
|
|
|
|
|
-func genUpdate(table Table, withCache, postgreSql bool) (string, string, error) {
|
|
|
|
|
|
+func genUpdate(table Table, withCache, postgreSql bool) (
|
|
|
|
+ string, string, error) {
|
|
expressionValues := make([]string, 0)
|
|
expressionValues := make([]string, 0)
|
|
|
|
+ var pkg = "data."
|
|
|
|
+ if table.ContainsUniqueCacheKey {
|
|
|
|
+ pkg = "newData."
|
|
|
|
+ }
|
|
for _, field := range table.Fields {
|
|
for _, field := range table.Fields {
|
|
camel := util.SafeString(field.Name.ToCamel())
|
|
camel := util.SafeString(field.Name.ToCamel())
|
|
if camel == "CreateTime" || camel == "UpdateTime" {
|
|
if camel == "CreateTime" || camel == "UpdateTime" {
|
|
@@ -23,7 +28,7 @@ func genUpdate(table Table, withCache, postgreSql bool) (string, string, error)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
- expressionValues = append(expressionValues, "data."+camel)
|
|
|
|
|
|
+ expressionValues = append(expressionValues, pkg+camel)
|
|
}
|
|
}
|
|
|
|
|
|
keySet := collection.NewSet()
|
|
keySet := collection.NewSet()
|
|
@@ -40,9 +45,14 @@ func genUpdate(table Table, withCache, postgreSql bool) (string, string, error)
|
|
sort.Strings(keyVars)
|
|
sort.Strings(keyVars)
|
|
|
|
|
|
if postgreSql {
|
|
if postgreSql {
|
|
- expressionValues = append([]string{"data." + table.PrimaryKey.Name.ToCamel()}, expressionValues...)
|
|
|
|
|
|
+ expressionValues = append(
|
|
|
|
+ []string{pkg + table.PrimaryKey.Name.ToCamel()},
|
|
|
|
+ expressionValues...,
|
|
|
|
+ )
|
|
} else {
|
|
} else {
|
|
- expressionValues = append(expressionValues, "data."+table.PrimaryKey.Name.ToCamel())
|
|
|
|
|
|
+ expressionValues = append(
|
|
|
|
+ expressionValues, pkg+table.PrimaryKey.Name.ToCamel(),
|
|
|
|
+ )
|
|
}
|
|
}
|
|
camelTableName := table.Name.ToCamel()
|
|
camelTableName := table.Name.ToCamel()
|
|
text, err := pathx.LoadTemplate(category, updateTemplateFile, template.Update)
|
|
text, err := pathx.LoadTemplate(category, updateTemplateFile, template.Update)
|
|
@@ -50,21 +60,29 @@ func genUpdate(table Table, withCache, postgreSql bool) (string, string, error)
|
|
return "", "", err
|
|
return "", "", err
|
|
}
|
|
}
|
|
|
|
|
|
- output, err := util.With("update").
|
|
|
|
- Parse(text).
|
|
|
|
- Execute(map[string]interface{}{
|
|
|
|
|
|
+ output, err := util.With("update").Parse(text).Execute(
|
|
|
|
+ map[string]interface{}{
|
|
"withCache": withCache,
|
|
"withCache": withCache,
|
|
|
|
+ "containsIndexCache": table.ContainsUniqueCacheKey,
|
|
"upperStartCamelObject": camelTableName,
|
|
"upperStartCamelObject": camelTableName,
|
|
"keys": strings.Join(keys, "\n"),
|
|
"keys": strings.Join(keys, "\n"),
|
|
"keyValues": strings.Join(keyVars, ", "),
|
|
"keyValues": strings.Join(keyVars, ", "),
|
|
"primaryCacheKey": table.PrimaryCacheKey.DataKeyExpression,
|
|
"primaryCacheKey": table.PrimaryCacheKey.DataKeyExpression,
|
|
"primaryKeyVariable": table.PrimaryCacheKey.KeyLeft,
|
|
"primaryKeyVariable": table.PrimaryCacheKey.KeyLeft,
|
|
"lowerStartCamelObject": stringx.From(camelTableName).Untitle(),
|
|
"lowerStartCamelObject": stringx.From(camelTableName).Untitle(),
|
|
- "originalPrimaryKey": wrapWithRawString(table.PrimaryKey.Name.Source(), postgreSql),
|
|
|
|
- "expressionValues": strings.Join(expressionValues, ", "),
|
|
|
|
- "postgreSql": postgreSql,
|
|
|
|
- "data": table,
|
|
|
|
- })
|
|
|
|
|
|
+ "upperStartCamelPrimaryKey": util.EscapeGolangKeyword(
|
|
|
|
+ stringx.From(table.PrimaryKey.Name.ToCamel()).Title(),
|
|
|
|
+ ),
|
|
|
|
+ "originalPrimaryKey": wrapWithRawString(
|
|
|
|
+ table.PrimaryKey.Name.Source(), postgreSql,
|
|
|
|
+ ),
|
|
|
|
+ "expressionValues": strings.Join(
|
|
|
|
+ expressionValues, ", ",
|
|
|
|
+ ),
|
|
|
|
+ "postgreSql": postgreSql,
|
|
|
|
+ "data": table,
|
|
|
|
+ },
|
|
|
|
+ )
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", "", nil
|
|
return "", "", nil
|
|
}
|
|
}
|
|
@@ -75,12 +93,12 @@ func genUpdate(table Table, withCache, postgreSql bool) (string, string, error)
|
|
return "", "", err
|
|
return "", "", err
|
|
}
|
|
}
|
|
|
|
|
|
- updateMethodOutput, err := util.With("updateMethod").
|
|
|
|
- Parse(text).
|
|
|
|
- Execute(map[string]interface{}{
|
|
|
|
|
|
+ updateMethodOutput, err := util.With("updateMethod").Parse(text).Execute(
|
|
|
|
+ map[string]interface{}{
|
|
"upperStartCamelObject": camelTableName,
|
|
"upperStartCamelObject": camelTableName,
|
|
"data": table,
|
|
"data": table,
|
|
- })
|
|
|
|
|
|
+ },
|
|
|
|
+ )
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", "", nil
|
|
return "", "", nil
|
|
}
|
|
}
|