Skip to content

Can't use v4 Get()/Set() Array behaviour in v5 #1542

Answered by crodwell
crodwell asked this question in Q&A
Discussion options

You must be logged in to vote

I was successful using wrapper structs:


import (
	"fmt"
	"strconv"

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

// Bool is a wrapper for pgtype.Bool allowing a .Set() method
type Bool struct {
	pgtype.Bool
}

// Set makes up for a non-existent method in the pgx v5 lib that worked in v4
func (dst *Bool) Set(src any) error {

The only negative is my code that used to get a Bool in the following way:

var myBool pgtype.Bool
value := myBool.Bool

now has to be referenced like so due to the conflicting naming of Bool and it's underlying value:

var myBool customTypes.Bool
value := customTypes.Bool.Bool

It would be really nice if Set() and Get() were reinstated in pgx/pgtype v5

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by crodwell
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants