Skip to content

Commit

Permalink
feat: upgrade pgtype to v5, exposing the parameter Scan method
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenrinzema committed Nov 12, 2023
1 parent b3997db commit 413e316
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 225 deletions.
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func (srv *Server) readParameters(ctx context.Context, reader *buffer.Reader) ([
format = formats[i]
}

parameters[i] = NewParameter(format, value)
parameters[i] = NewParameter(TypeMap(ctx), format, value)
}

// NOTE: Read the total amount of result-column format that will be
Expand Down
16 changes: 8 additions & 8 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package wire
import (
"context"

"github.com/jackc/pgtype"
"github.com/jackc/pgx/v5/pgtype"
)

type ctxKey int

const (
ctxTypeInfo ctxKey = iota
ctxTypeMap ctxKey = iota
ctxClientMetadata
ctxServerMetadata
)

// setTypeInfo constructs a new Postgres type connection info for the given value
func setTypeInfo(ctx context.Context, info *pgtype.ConnInfo) context.Context {
return context.WithValue(ctx, ctxTypeInfo, info)
func setTypeInfo(ctx context.Context, info *pgtype.Map) context.Context {
return context.WithValue(ctx, ctxTypeMap, info)
}

// TypeInfo returns the Postgres type connection info if it has been set inside
// TypeMap returns the Postgres type connection info if it has been set inside
// the given context.
func TypeInfo(ctx context.Context) *pgtype.ConnInfo {
val := ctx.Value(ctxTypeInfo)
func TypeMap(ctx context.Context) *pgtype.Map {
val := ctx.Value(ctxTypeMap)
if val == nil {
return nil
}

return val.(*pgtype.ConnInfo)
return val.(*pgtype.Map)
}

// Parameters represents a parameters collection of parameter status keys and
Expand Down
7 changes: 0 additions & 7 deletions examples/numeric/README.md

This file was deleted.

57 changes: 0 additions & 57 deletions examples/numeric/main.go

This file was deleted.

31 changes: 0 additions & 31 deletions format.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
package wire

import (
"fmt"

"github.com/jackc/pgtype"
)

// FormatCode represents the encoding format of a given column
type FormatCode int16

// Encoder returns the format encoder for the given data type
func (code FormatCode) Encoder(t *pgtype.DataType) FormatEncoder {
switch code {
case TextFormat:
return t.Value.(pgtype.TextEncoder).EncodeText
case BinaryFormat:
return t.Value.(pgtype.BinaryEncoder).EncodeBinary
default:
return unknownEncoderfunc(fmt.Errorf("unknown format encoder %d", code))
}
}

// FormatEncoder represents a format code wire encoder.
// FormatEncoder should append the text format of self to buf. If self is the
// SQL value NULL then append nothing and return (nil, nil). The caller of
// FormatEncoder is responsible for writing the correct NULL value or the
// length of the data written.
type FormatEncoder func(ci *pgtype.ConnInfo, buf []byte) (newBuf []byte, err error)

func unknownEncoderfunc(err error) FormatEncoder {
return func(ci *pgtype.ConnInfo, buf []byte) (newBuf []byte, err error) {
return nil, err
}
}

const (
// TextFormat is the default, text format.
TextFormat FormatCode = 0
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ go 1.21

require (
github.com/golangci/golangci-lint v1.54.2
github.com/jackc/pgtype v1.8.1
github.com/jackc/pgx/v5 v5.0.3
github.com/lib/pq v1.10.9
github.com/neilotoole/slogt v1.1.0
github.com/shopspring/decimal v1.2.0
github.com/stretchr/testify v1.8.4
golang.org/x/tools v0.12.0
)
Expand Down Expand Up @@ -86,7 +84,6 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jgautheron/goconst v1.5.1 // indirect
Expand Down
Loading

0 comments on commit 413e316

Please sign in to comment.