Value, EncodeBinary, EncodeText, and MarshalJSON on T instead of *T
Methods defined on T are also available on *T. This change makes Value consistent with database/sql Value implementations. It also makes Value, EncodeBinary, and EncodeText more convenient to use because you can pass T or *T as an argument to a query. The MarshalJSON change is even more significant because without it json.Marshal would generate the "%v" format instead of the implemented MarshalJSON. Thought this technically changes the interface, because *T will be automatically dereferenced as needed it shouldn't be a breaking change. See: https://github.com/jackc/pgx/issues/538 for initial discussion.
This commit is contained in:
+3
-3
@@ -168,7 +168,7 @@ func (dst *Float4Array) DecodeBinary(ci *ConnInfo, src []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (src *Float4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
func (src Float4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
switch src.Status {
|
||||
case Null:
|
||||
return nil, nil
|
||||
@@ -225,7 +225,7 @@ func (src *Float4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (src *Float4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
func (src Float4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
|
||||
switch src.Status {
|
||||
case Null:
|
||||
return nil, nil
|
||||
@@ -288,7 +288,7 @@ func (dst *Float4Array) Scan(src interface{}) error {
|
||||
}
|
||||
|
||||
// Value implements the database/sql/driver Valuer interface.
|
||||
func (src *Float4Array) Value() (driver.Value, error) {
|
||||
func (src Float4Array) Value() (driver.Value, error) {
|
||||
buf, err := src.EncodeText(nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user