Fix ommit empty db tag

This commit is contained in:
2025-03-05 22:03:32 +01:00
parent 904d4ce106
commit 7e9aab01cb

View File

@@ -55,6 +55,7 @@ func StructTagsToFields(s any) ([]DBField, error) {
useDefault := false useDefault := false
encrypted := false encrypted := false
ommit := false
if strings.Contains(tag, ",") { if strings.Contains(tag, ",") {
parts := strings.Split(tag, ",") parts := strings.Split(tag, ",")
@@ -64,7 +65,7 @@ func StructTagsToFields(s any) ([]DBField, error) {
switch opt { switch opt {
case "omitempty": case "omitempty":
if reflect.DeepEqual(v.Field(i).Interface(), reflect.Zero(f.Type).Interface()) { if reflect.DeepEqual(v.Field(i).Interface(), reflect.Zero(f.Type).Interface()) {
continue ommit = true
} }
case "default": case "default":
useDefault = true useDefault = true
@@ -74,6 +75,10 @@ func StructTagsToFields(s any) ([]DBField, error) {
} }
} }
if ommit {
continue
}
fields = append(fields, DBField{ fields = append(fields, DBField{
Name: tag, Name: tag,
Value: v.Field(i).Interface(), Value: v.Field(i).Interface(),