georgysavva / scany

Library for scanning data from a database into Go structs and more
MIT License
1.27k stars 67 forks source link

pgx module needs to be updated #20

Closed PaulForgey closed 3 years ago

PaulForgey commented 3 years ago

The version of pgx used uses an older version of pgtype which does not support nullable pointers to custom types. Later versions of pgtype >= 1.4.0 support this.

georgysavva commented 3 years ago

I will take a look at this. Thanks for the issue!

georgysavva commented 3 years ago

Hi. I just upgraded pgx to v4.8.1 https://github.com/georgysavva/scany/commit/d03fac1ef3c48f83eea39a48af58b17312a3a45a in the master. I don't want to create a new release yet because there are a few things that I want to check first:

  1. I couldn't upgrade to the latest version v4.9.0 because there is a regression in pgtype v1.5.0, I created an issue for this https://github.com/jackc/pgtype/issues/72.
  2. Could you please give me an example of the feature that is new in the pgtype 1.4.0 that you want, because I couldn't find what you are talking about and this seems relevant to scany functionality and might require documentation update.

Thanks!

PaulForgey commented 3 years ago
  1. When playing with my own fork of scany, I noticed the same behavior too.
  2. Related to https://github.com/jackc/pgtype/issues/9, we have a NULL-able type implementing Scanner/Valuer. While we could work around this by extending the type itself to have an IsNull method, that interacts poorly with other users of this same field outside the database. Specifically, it reproduces with
    
    import "github.com/google/uuid"

struct MyRecord { ID *uuid.UUID db:"id" // pgtype uuid }

georgysavva commented 3 years ago

Hi. Thanks for giving me an example. I just checked it with scany v0.2.6 and pgtype v1.3.0 and it works the same way as it works with the latest scany in master and pgtype v1.4.2 So I am not sure what new functionality in pgtype v1.4.0 you are talking about, again :)

Besides that, as far as I understand if you are using scany with go modules, you can install pgtype of the latest version:

go get github.com/jackc/pgtype@v1.4.2

And go modules will force scany to use this, higher version of pgtype, instead of the one defined in its dependencies.

PaulForgey commented 3 years ago

It appears this issue was finally fixed in pgtype, once there's a release tag I will test this out in our codebase (go issue 37438 is making this difficult in the meantime)

PaulForgey commented 3 years ago

also the go get in the module will for that module it is in, but I still need to fork yours to get specific versions of your dependencies in your module.

georgysavva commented 3 years ago

also the go get in the module will for that module it is in, but I still need to fork yours to get specific versions of your dependencies in your module.

I just checked this and it works as I was saying. I installed the latest scany release v0.2.6 that uses pgtype v1.3.1 and made scany to scan into a pointer to a slice and it worked. Then I installed the latest pgtype version in my module:

go get github.com/jackc/pgtype@v1.5.0

And it replaced the pgtype version in scany module too, because when I made scany to scan into a pointer a slice again it didn't work (since this feature is broken in pgtype v1.5.0). This proves that go get will replace the dependency version not only in your module but in your dependencies too.

georgysavva commented 3 years ago

Closing due to inactivity.