Skip to content

Commit ff89062

Browse files
authored
feat: optimize ignore fields in orm (#5015)
1 parent cc79e3d commit ff89062

File tree

2 files changed

+187
-83
lines changed

2 files changed

+187
-83
lines changed

core/stores/sqlx/orm.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import (
99
"github.com/zeromicro/go-zero/core/mapping"
1010
)
1111

12-
const tagName = "db"
12+
const (
13+
tagIgnore = "-"
14+
tagName = "db"
15+
)
1316

1417
var (
1518
// ErrNotMatchDestination is an error that indicates not matching destination to scan.
@@ -269,21 +272,20 @@ func unwrapFields(v reflect.Value) []reflect.Value {
269272
continue
270273
}
271274

275+
childType := indirect.Type().Field(i)
276+
if parseTagName(childType) == tagIgnore {
277+
continue
278+
}
279+
272280
if child.Kind() == reflect.Ptr && child.IsNil() {
273281
baseValueType := mapping.Deref(child.Type())
274282
child.Set(reflect.New(baseValueType))
275283
}
276284

277285
child = reflect.Indirect(child)
278-
childType := indirect.Type().Field(i)
279286
if child.Kind() == reflect.Struct && childType.Anonymous {
280287
fields = append(fields, unwrapFields(child)...)
281288
} else {
282-
key := parseTagName(childType)
283-
if key == "-" {
284-
continue
285-
}
286-
287289
fields = append(fields, child)
288290
}
289291
}

0 commit comments

Comments
 (0)