good morning!!!!

Skip to content
Snippets Groups Projects
Commit d9ac5ec9 authored by Peter Kieltyka's avatar Peter Kieltyka
Browse files

Fix null values of wrapped types from being alloc'd

parent 989d3e1d
Branches
Tags
No related merge requests found
...@@ -152,7 +152,7 @@ func fetchResult(itemT reflect.Type, rows *sqlx.Rows, columns []string) (reflect ...@@ -152,7 +152,7 @@ func fetchResult(itemT reflect.Type, rows *sqlx.Rows, columns []string) (reflect
values := make([]interface{}, len(columns)) values := make([]interface{}, len(columns))
typeMap := rows.Mapper.TypeMap(itemT) typeMap := rows.Mapper.TypeMap(itemT)
fieldMap := typeMap.Names fieldMap := typeMap.Names
wrappedValues := map[reflect.Value][]interface{}{} wrappedValues := map[*reflectx.Field]interface{}{}
for i, k := range columns { for i, k := range columns {
fi, ok := fieldMap[k] fi, ok := fieldMap[k]
...@@ -161,19 +161,18 @@ func fetchResult(itemT reflect.Type, rows *sqlx.Rows, columns []string) (reflect ...@@ -161,19 +161,18 @@ func fetchResult(itemT reflect.Type, rows *sqlx.Rows, columns []string) (reflect
continue continue
} }
f := reflectx.FieldByIndexes(item, fi.Index)
// TODO: refactor into a nice pattern // TODO: refactor into a nice pattern
if _, ok := fi.Options["stringarray"]; ok { if _, ok := fi.Options["stringarray"]; ok {
values[i] = &[]byte{} values[i] = &[]byte{}
wrappedValues[f] = []interface{}{"stringarray", values[i]} wrappedValues[fi] = values[i]
} else if _, ok := fi.Options["int64array"]; ok { } else if _, ok := fi.Options["int64array"]; ok {
values[i] = &[]byte{} values[i] = &[]byte{}
wrappedValues[f] = []interface{}{"int64array", values[i]} wrappedValues[fi] = values[i]
} else if _, ok := fi.Options["jsonb"]; ok { } else if _, ok := fi.Options["jsonb"]; ok {
values[i] = &[]byte{} values[i] = &[]byte{}
wrappedValues[f] = []interface{}{"jsonb", values[i]} wrappedValues[fi] = values[i]
} else { } else {
f := reflectx.FieldByIndexes(item, fi.Index)
values[i] = f.Addr().Interface() values[i] = f.Addr().Interface()
} }
...@@ -194,9 +193,19 @@ func fetchResult(itemT reflect.Type, rows *sqlx.Rows, columns []string) (reflect ...@@ -194,9 +193,19 @@ func fetchResult(itemT reflect.Type, rows *sqlx.Rows, columns []string) (reflect
} }
// TODO: move this stuff out of here.. find a nice pattern // TODO: move this stuff out of here.. find a nice pattern
for f, v := range wrappedValues { for fi, v := range wrappedValues {
opt := v[0].(string) var opt string
b := v[1].(*[]byte) if _, ok := fi.Options["stringarray"]; ok {
opt = "stringarray"
} else if _, ok := fi.Options["int64array"]; ok {
opt = "int64array"
} else if _, ok := fi.Options["jsonb"]; ok {
opt = "jsonb"
}
b := v.(*[]byte)
f := reflectx.FieldByIndexesReadOnly(item, fi.Index)
switch opt { switch opt {
case "stringarray": case "stringarray":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment