@@ -96,22 +96,25 @@ func getStructFieldPointers(v reflect.Value, namer sqldb.StructFieldNamer, ignor
96
96
return nil
97
97
}
98
98
99
- // structFields returns the struct field names using the passed namer ignoring names in ignoreNames
99
+ // structFieldValues returns the struct field names using the passed namer ignoring names in ignoreNames
100
100
// and if restrictToNames is not empty, then filtering out names not in it.
101
+ // struct fields with ,readonly suffix in their struct field naming tag will not be returned
102
+ // because this function is intended for getting struct values for writing.
101
103
// If true is passed for keepPK, then ignoreNames and restrictToNames are not applied to names with
102
104
// the ,pk suffix in their struct field naming tag.
103
105
// The same number of pkCol bools will be returend as names, every corresponding bool marking
104
106
// if the name had the ,pk suffix in their struct field naming tag.
105
- func structFields (v reflect.Value , namer sqldb.StructFieldNamer , ignoreNames , restrictToNames []string , keepPK bool ) (names []string , flags []sqldb.FieldFlag , vals []interface {}) {
107
+ // If false is passed for keepReadOnly then
108
+ func structFieldValues (v reflect.Value , namer sqldb.StructFieldNamer , ignoreNames , restrictToNames []string , keepPK bool ) (names []string , flags []sqldb.FieldFlag , vals []interface {}) {
106
109
for i := 0 ; i < v .NumField (); i ++ {
107
110
field := v .Type ().Field (i )
108
111
name , flag , ok := namer .StructFieldName (field )
109
- if ! ok {
112
+ if ! ok || flag . IsReadOnly () {
110
113
continue
111
114
}
112
115
113
116
if field .Anonymous {
114
- embedNames , embedFlags , embedValues := structFields (v .Field (i ), namer , ignoreNames , restrictToNames , keepPK )
117
+ embedNames , embedFlags , embedValues := structFieldValues (v .Field (i ), namer , ignoreNames , restrictToNames , keepPK )
115
118
names = append (names , embedNames ... )
116
119
flags = append (flags , embedFlags ... )
117
120
vals = append (vals , embedValues ... )
0 commit comments