-
With the AssignTo() and Set() funcs available v4 now gone, scanning works from a pgx Row and also with basic go native types such as string & int but not native slices:
How can I do the equivalent of |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
What exactly are you trying to do? You shouldn't need Scanning query results directly to Go slices should work out of the box. For example from the test suite: pgx/pgtype/array_codec_test.go Lines 326 to 329 in 19039e6 |
Beta Was this translation helpful? Give feedback.
-
Effectively in v4 I had a model for each table defined as a struct with each field a Yes, I gathered the Scan is really for scanning database results into the pgtype and there isn't a way to set the pgtype from native go in a generic way anymore . I'm currently headed down a path of creating wrappers like this which I don't think is ideal.
|
Beta Was this translation helpful? Give feedback.
-
I was successful using wrapper structs:
The only negative is my code that used to get a Bool in the following way:
now has to be referenced like so due to the conflicting naming of Bool and it's underlying value:
It would be really nice if |
Beta Was this translation helpful? Give feedback.
-
It's unlikely that However, v5 usually makes it easier to create application or domain types that can be directly used with pgx by exposing per PostgreSQL type interfaces. For your bool example, your type could implement |
Beta Was this translation helpful? Give feedback.
I was successful using wrapper structs:
The only negative is my code that used to get a Bool in the following way:
now has to be referenced like so due to the conflicting naming of Bool and it's underlying value:
It would be really nice if
Set()
andGet()
were reinstated in pgx/pgtype v5