Fix all queries to ignore untagged struct attributes

pull/10/head
Vinícius Garcia 2021-12-23 22:56:25 -03:00
parent 487e2aa6ac
commit 402a9e98ac
1 changed files with 12 additions and 4 deletions

16
ksql.go
View File

@ -994,6 +994,9 @@ func getScanArgsForNestedStructs(dialect Dialect, rows Rows, t reflect.Type, v r
nestedStructValue := v.Field(i)
for j := 0; j < nestedStructValue.NumField(); j++ {
fieldInfo := nestedStructInfo.ByIndex(j)
if !fieldInfo.Valid {
continue
}
valueScanner := nopScannerValue
if fieldInfo.Valid {
@ -1130,12 +1133,12 @@ func buildSelectQueryForPlainStructs(
) string {
var fields []string
for i := 0; i < structType.NumField(); i++ {
structInfo := info.ByIndex(i)
if !structInfo.Valid {
fieldInfo := info.ByIndex(i)
if !fieldInfo.Valid {
continue
}
fields = append(fields, dialect.Escape(info.ByIndex(i).Name))
fields = append(fields, dialect.Escape(fieldInfo.Name))
}
return "SELECT " + strings.Join(fields, ", ") + " "
@ -1163,9 +1166,14 @@ func buildSelectQueryForNestedStructs(
}
for j := 0; j < structType.Field(i).Type.NumField(); j++ {
fieldInfo := nestedStructInfo.ByIndex(j)
if !fieldInfo.Valid {
continue
}
fields = append(
fields,
dialect.Escape(nestedStructName)+"."+dialect.Escape(nestedStructInfo.ByIndex(j).Name),
dialect.Escape(nestedStructName)+"."+dialect.Escape(fieldInfo.Name),
)
}
}