feat: ent update fields.

This commit is contained in:
tx7do
2023-11-08 18:15:48 +08:00
parent 78452b1abf
commit d65e7bb928
3 changed files with 54 additions and 1 deletions

25
entgo/update/update.go Normal file
View File

@@ -0,0 +1,25 @@
package update
import (
"entgo.io/ent/dialect/sql"
"github.com/tx7do/go-utils/stringcase"
)
func BuildSetNullUpdate(u *sql.UpdateBuilder, fields []string) {
if len(fields) > 0 {
for _, field := range fields {
field = stringcase.ToSnakeCase(field)
u.SetNull(field)
}
}
}
func BuildSetNullUpdater(fields []string) (error, func(u *sql.UpdateBuilder)) {
if len(fields) > 0 {
return nil, func(u *sql.UpdateBuilder) {
BuildSetNullUpdate(u, fields)
}
} else {
return nil, nil
}
}