Replies: 2 comments
-
|
I haven't used sqlc, but with pgx you can use directly use normal Go types such as |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
@0xBradock did you figure this out I am currently running into this issue |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am kind of new to
pgxand I am trying to understand how to usepgtype.I am also using sqlc, but that should make no difference.
I am writing a test that writes a struct to a postgres db, then the db is supposed to return back the value.
I am finding the use quite verbose, but I might be missing some thing.
I need to convert Go types into
pgtypetypes (i.e.stringtopgtype.Text{String: city, Valid: true}) to write to the db.Than, the value that I receive from the read is not a string and I need to convert it again.
Then my tests fail with:
Then, if I do
fmt.Printf("Just City %+v\n", weatherResponse.City)I getpgtype.Text{String:"London", Valid:true}.So, this means I have to do
correctCityName := weatherResponse.City.String?Then, if I use
temp := 12I getweatherResponse.Temperature = {Int:+1200 Exp:-2 NaN:false InfinityModifier:finite Valid:true}.The only way I made it work was by using using
Temperature pgtype.Int4, then in my test I would callCreateWeatherwithTemperature: pgtype.Int4{Int32: int32(temp), Valid: true},, then assert withrequire.Equal(t, temp, int(weatherResponse.Temperature.Int32)).So, is it normal to have go struct => pgtype => db, then db => pgtype => go struct?
I am really confused on how to use correctly the library, any help is appreciated.
Thanks,
Beta Was this translation helpful? Give feedback.
All reactions