Use wrapper to treat fmt.String as pgtype.TextValuer
This commit is contained in:
@@ -1421,6 +1421,8 @@ func tryWrapBuiltinTypeEncodePlan(value interface{}) (plan WrappedEncodePlanNext
|
||||
return &wrapMapStringToPointerStringEncodePlan{}, mapStringToPointerStringWrapper(value), true
|
||||
case map[string]string:
|
||||
return &wrapMapStringToStringEncodePlan{}, mapStringToStringWrapper(value), true
|
||||
case fmt.Stringer:
|
||||
return &wrapFmtStringerEncodePlan{}, fmtStringerWrapper{value}, true
|
||||
}
|
||||
|
||||
return nil, nil, false
|
||||
@@ -1616,6 +1618,16 @@ func (plan *wrapMapStringToStringEncodePlan) Encode(value interface{}, buf []byt
|
||||
return plan.next.Encode(mapStringToStringWrapper(value.(map[string]string)), buf)
|
||||
}
|
||||
|
||||
type wrapFmtStringerEncodePlan struct {
|
||||
next EncodePlan
|
||||
}
|
||||
|
||||
func (plan *wrapFmtStringerEncodePlan) SetNext(next EncodePlan) { plan.next = next }
|
||||
|
||||
func (plan *wrapFmtStringerEncodePlan) Encode(value interface{}, buf []byte) (newBuf []byte, err error) {
|
||||
return plan.next.Encode(fmtStringerWrapper{value.(fmt.Stringer)}, buf)
|
||||
}
|
||||
|
||||
// Encode appends the encoded bytes of value to buf. If value is the SQL value NULL then append nothing and return
|
||||
// (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data
|
||||
// written.
|
||||
|
||||
Reference in New Issue
Block a user