Skip to content

Commit

Permalink
Only use anynil inside of pgtype
Browse files Browse the repository at this point in the history
  • Loading branch information
jackc committed May 19, 2024
1 parent 6ea2d24 commit 79cab46
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
5 changes: 0 additions & 5 deletions extended_query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pgx
import (
"fmt"

"github.com/jackc/pgx/v5/internal/anynil"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgtype"
)
Expand Down Expand Up @@ -117,10 +116,6 @@ func (eqb *ExtendedQueryBuilder) reset() {
}

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 {
eqb.paramValueBytes = make([]byte, 0, 128)
}
Expand Down
4 changes: 3 additions & 1 deletion pgtype/pgtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/netip"
"reflect"
"time"

"github.com/jackc/pgx/v5/internal/anynil"
)

// PostgreSQL oids for common types
Expand Down Expand Up @@ -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
// written.
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
}

Expand Down
9 changes: 0 additions & 9 deletions values.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pgx
import (
"errors"

"github.com/jackc/pgx/v5/internal/anynil"
"github.com/jackc/pgx/v5/internal/pgio"
"github.com/jackc/pgx/v5/pgtype"
)
Expand All @@ -15,10 +14,6 @@ const (
)

func convertSimpleArgument(m *pgtype.Map, arg any) (any, error) {
if anynil.Is(arg) {
return nil, nil
}

buf, err := m.Encode(0, TextFormatCode, arg, []byte{})
if err != nil {
return nil, err
Expand All @@ -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) {
if anynil.Is(arg) {
return pgio.AppendInt32(buf, -1), nil
}

sp := len(buf)
buf = pgio.AppendInt32(buf, -1)
argBuf, err := m.Encode(oid, BinaryFormatCode, arg, buf)
Expand Down

0 comments on commit 79cab46

Please sign in to comment.