good morning!!!!

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

Support nil option types

parent 2bd78911
Branches
Tags
No related merge requests found
......@@ -1737,6 +1737,30 @@ func TestOptionTypes(t *testing.T) {
t.Fatalf("Expecting first element of Tags stringarray to be 'love'")
}
type optionType2 struct {
ID int64 `db:"id,omitempty"`
Name string `db:"name"`
Tags []string `db:"tags,stringarray"`
Settings *map[string]interface{} `db:"settings,jsonb"`
}
item3 := optionType2{
Name: "JS", Tags: []string{"hi", "bye"}, Settings: nil,
}
id, err = optionTypes.Append(item3)
if err != nil {
t.Fatal(err)
}
if pk, ok := id.(int64); !ok || pk == 0 {
t.Fatalf("Expecting an ID.")
}
var item3Chk optionType2
if err := optionTypes.Find(db.Cond{"id": id}).One(&item3Chk); err != nil {
t.Fatal(err)
}
}
// We are going to benchmark the engine, so this is no longed needed.
......
......@@ -187,9 +187,17 @@ func fetchResult(itemT reflect.Type, rows *sqlx.Rows, columns []string) (reflect
for f, v := range wrappedValues {
switch t := v.(type) {
case *StringArray:
if t != nil {
f.Set(reflect.ValueOf(*t))
}
case *Int64Array:
if t != nil {
f.Set(reflect.ValueOf(*t))
}
case *JsonbType:
if t != nil && t.V != nil {
f.Set(reflect.ValueOf((*t).V))
}
default:
}
}
......
......@@ -94,7 +94,6 @@ func (t *T) FieldValues(item interface{}) ([]string, []interface{}, error) {
value = StringArray(fld.Interface().([]string))
} else if _, ok := fi.Options["int64array"]; ok {
value = Int64Array(fld.Interface().([]int64))
} else if _, ok := fi.Options["jsonb"]; ok {
value = JsonbType{fld.Interface()}
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment