Compare commits
4 Commits
entgo/v1.1
...
entgo/v1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d549d305ae | ||
|
|
23dcad60a3 | ||
|
|
fa7ae4f876 | ||
|
|
9f6a4eba80 |
@@ -588,7 +588,7 @@ func filterJsonbField(s *sql.Selector, jsonbField, field string) string {
|
||||
p := sql.P()
|
||||
switch s.Builder.Dialect() {
|
||||
case dialect.Postgres:
|
||||
p.Ident(s.C(field)).WriteString(" -> ").WriteString(jsonbField)
|
||||
p.Ident(s.C(field)).WriteString(" ->> ").WriteString("'" + jsonbField + "'")
|
||||
//b.Arg(strings.ToLower(value))
|
||||
break
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func BuildSetNullUpdater(fields []string) func(u *sql.UpdateBuilder) {
|
||||
}
|
||||
|
||||
// ExtractJsonFieldKeyValues 提取json字段的键值对
|
||||
func ExtractJsonFieldKeyValues(msg proto.Message, paths []string) []string {
|
||||
func ExtractJsonFieldKeyValues(msg proto.Message, paths []string, needToSnakeCase bool) []string {
|
||||
var keyValues []string
|
||||
rft := msg.ProtoReflect()
|
||||
for _, path := range paths {
|
||||
@@ -46,7 +46,14 @@ func ExtractJsonFieldKeyValues(msg proto.Message, paths []string) []string {
|
||||
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)
|
||||
switch v.Interface().(type) {
|
||||
@@ -77,8 +84,8 @@ func SetJsonNullFieldUpdateBuilder(fieldName string, msg proto.Message, paths []
|
||||
}
|
||||
|
||||
// SetJsonFieldValueUpdateBuilder 设置json字段的值
|
||||
func SetJsonFieldValueUpdateBuilder(fieldName string, msg proto.Message, paths []string) func(u *sql.UpdateBuilder) {
|
||||
keyValues := ExtractJsonFieldKeyValues(msg, paths)
|
||||
func SetJsonFieldValueUpdateBuilder(fieldName string, msg proto.Message, paths []string, needToSnakeCase bool) func(u *sql.UpdateBuilder) {
|
||||
keyValues := ExtractJsonFieldKeyValues(msg, paths, needToSnakeCase)
|
||||
if len(keyValues) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
2
tag.bat
2
tag.bat
@@ -3,7 +3,7 @@ git tag v1.1.13
|
||||
git tag bank_card/v1.1.3
|
||||
git tag geoip/v1.1.3
|
||||
|
||||
git tag entgo/v1.1.17
|
||||
git tag entgo/v1.1.19
|
||||
git tag gorm/v1.1.3
|
||||
|
||||
git push origin --tags
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package timeutil
|
||||
|
||||
import "time"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package timeutil
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package timeutil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package timeutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package timeutil
|
||||
|
||||
import "time"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package timeutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package util
|
||||
package timeutil
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/tx7do/go-utils/trans"
|
||||
@@ -132,3 +133,19 @@ func TimeToTimestamppb(tm *time.Time) *timestamppb.Timestamp {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FloatToDurationpb(duration *float64, timePrecision time.Duration) *durationpb.Duration {
|
||||
if duration == nil {
|
||||
return nil
|
||||
}
|
||||
return durationpb.New(time.Duration(*duration) * timePrecision)
|
||||
}
|
||||
|
||||
func DurationpbToFloat(duration *durationpb.Duration, timePrecision time.Duration) *float64 {
|
||||
if duration == nil {
|
||||
return nil
|
||||
}
|
||||
seconds := duration.AsDuration().Seconds()
|
||||
secondsWithPrecision := seconds / timePrecision.Seconds()
|
||||
return &secondsWithPrecision
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package timeutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
Reference in New Issue
Block a user