Skip to content

Commit 7542d1e

Browse files
committed
chwange
1 parent f69950e commit 7542d1e

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

goqu.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ type SQLValuer struct {
3737

3838
// Value converts the given value to the correct drive.Value.
3939
func (t SQLValuer) Value() (driver.Value, error) {
40+
if valuer, ok := t.V.(driver.Valuer); ok {
41+
if reflect.TypeOf(t.V).Kind() == reflect.Pointer && reflect.ValueOf(t.V).IsZero() {
42+
return nil, nil
43+
}
44+
return valuer.Value()
45+
}
4046
switch t.V.(type) {
4147
case []string, []bool, []float32, []float64, []int, []int64, []int32:
4248
value, err := pq.Array(t.V).Value()
@@ -55,17 +61,6 @@ func (t SQLValuer) Value() (driver.Value, error) {
5561
// if we didn't find a common type use reflection to guess if the type is of map
5662
if reflect.TypeOf(t.V).Kind() == reflect.Map {
5763
return json.Marshal(t.V)
58-
} else if reflect.TypeOf(t.V).Kind() == reflect.Pointer {
59-
if reflect.ValueOf(t.V).IsZero() {
60-
return nil, nil
61-
}
62-
s := reflect.ValueOf(t.V).Elem().Interface()
63-
if valuer, ok := s.(driver.Valuer); ok {
64-
return valuer.Value()
65-
}
66-
}
67-
if valuer, ok := t.V.(driver.Valuer); ok {
68-
return valuer.Value()
6964
}
7065
return t.V, nil
7166
}

0 commit comments

Comments
 (0)