Only use anynil inside of pgtype

pull/2019/head
Jack Christensen 2024-05-18 21:06:23 -05:00
parent 6ea2d248a3
commit 79cab4640f
3 changed files with 3 additions and 15 deletions

View File

@ -3,7 +3,6 @@ package pgx
import ( import (
"fmt" "fmt"
"github.com/jackc/pgx/v5/internal/anynil"
"github.com/jackc/pgx/v5/pgconn" "github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgtype" "github.com/jackc/pgx/v5/pgtype"
) )
@ -117,10 +116,6 @@ func (eqb *ExtendedQueryBuilder) reset() {
} }
func (eqb *ExtendedQueryBuilder) encodeExtendedParamValue(m *pgtype.Map, oid uint32, formatCode int16, arg any) ([]byte, error) { func (eqb *ExtendedQueryBuilder) encodeExtendedParamValue(m *pgtype.Map, oid uint32, formatCode int16, arg any) ([]byte, error) {
if anynil.Is(arg) {
return nil, nil
}
if eqb.paramValueBytes == nil { if eqb.paramValueBytes == nil {
eqb.paramValueBytes = make([]byte, 0, 128) eqb.paramValueBytes = make([]byte, 0, 128)
} }

View File

@ -9,6 +9,8 @@ import (
"net/netip" "net/netip"
"reflect" "reflect"
"time" "time"
"github.com/jackc/pgx/v5/internal/anynil"
) )
// PostgreSQL oids for common types // PostgreSQL oids for common types
@ -1912,7 +1914,7 @@ func newEncodeError(value any, m *Map, oid uint32, formatCode int16, err error)
// (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data // (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data
// written. // written.
func (m *Map) Encode(oid uint32, formatCode int16, value any, buf []byte) (newBuf []byte, err error) { func (m *Map) Encode(oid uint32, formatCode int16, value any, buf []byte) (newBuf []byte, err error) {
if value == nil { if anynil.Is(value) {
return nil, nil return nil, nil
} }

View File

@ -3,7 +3,6 @@ package pgx
import ( import (
"errors" "errors"
"github.com/jackc/pgx/v5/internal/anynil"
"github.com/jackc/pgx/v5/internal/pgio" "github.com/jackc/pgx/v5/internal/pgio"
"github.com/jackc/pgx/v5/pgtype" "github.com/jackc/pgx/v5/pgtype"
) )
@ -15,10 +14,6 @@ const (
) )
func convertSimpleArgument(m *pgtype.Map, arg any) (any, error) { func convertSimpleArgument(m *pgtype.Map, arg any) (any, error) {
if anynil.Is(arg) {
return nil, nil
}
buf, err := m.Encode(0, TextFormatCode, arg, []byte{}) buf, err := m.Encode(0, TextFormatCode, arg, []byte{})
if err != nil { if err != nil {
return nil, err return nil, err
@ -30,10 +25,6 @@ func convertSimpleArgument(m *pgtype.Map, arg any) (any, error) {
} }
func encodeCopyValue(m *pgtype.Map, buf []byte, oid uint32, arg any) ([]byte, error) { func encodeCopyValue(m *pgtype.Map, buf []byte, oid uint32, arg any) ([]byte, error) {
if anynil.Is(arg) {
return pgio.AppendInt32(buf, -1), nil
}
sp := len(buf) sp := len(buf)
buf = pgio.AppendInt32(buf, -1) buf = pgio.AppendInt32(buf, -1)
argBuf, err := m.Encode(oid, BinaryFormatCode, arg, buf) argBuf, err := m.Encode(oid, BinaryFormatCode, arg, buf)