Compare commits
1 Commits
entgo/v1.1
...
entgo/v1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f6a4eba80 |
@@ -34,7 +34,7 @@ func BuildSetNullUpdater(fields []string) func(u *sql.UpdateBuilder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ExtractJsonFieldKeyValues 提取json字段的键值对
|
// ExtractJsonFieldKeyValues 提取json字段的键值对
|
||||||
func ExtractJsonFieldKeyValues(msg proto.Message, paths []string) []string {
|
func ExtractJsonFieldKeyValues(msg proto.Message, paths []string, needToSnakeCase bool) []string {
|
||||||
var keyValues []string
|
var keyValues []string
|
||||||
rft := msg.ProtoReflect()
|
rft := msg.ProtoReflect()
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
@@ -46,7 +46,14 @@ func ExtractJsonFieldKeyValues(msg proto.Message, paths []string) []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
keyValues = append(keyValues, fmt.Sprintf("'%s'", stringcase.ToSnakeCase(path)))
|
var k string
|
||||||
|
if needToSnakeCase {
|
||||||
|
k = stringcase.ToSnakeCase(path)
|
||||||
|
} else {
|
||||||
|
k = path
|
||||||
|
}
|
||||||
|
|
||||||
|
keyValues = append(keyValues, fmt.Sprintf("'%s'", k))
|
||||||
|
|
||||||
v := rft.Get(fd)
|
v := rft.Get(fd)
|
||||||
switch v.Interface().(type) {
|
switch v.Interface().(type) {
|
||||||
@@ -77,8 +84,8 @@ func SetJsonNullFieldUpdateBuilder(fieldName string, msg proto.Message, paths []
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetJsonFieldValueUpdateBuilder 设置json字段的值
|
// SetJsonFieldValueUpdateBuilder 设置json字段的值
|
||||||
func SetJsonFieldValueUpdateBuilder(fieldName string, msg proto.Message, paths []string) func(u *sql.UpdateBuilder) {
|
func SetJsonFieldValueUpdateBuilder(fieldName string, msg proto.Message, paths []string, needToSnakeCase bool) func(u *sql.UpdateBuilder) {
|
||||||
keyValues := ExtractJsonFieldKeyValues(msg, paths)
|
keyValues := ExtractJsonFieldKeyValues(msg, paths, needToSnakeCase)
|
||||||
if len(keyValues) == 0 {
|
if len(keyValues) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user