Skip to content

Add support for pgx #472

Description

@kyleconroy

Get out the trumpets and ready the 21-gun salute, lib/pq is deprecated (#470). This means it's time to support it's successor, pgx.

This will be the main tracking issue for pgx. It supersedes #28, as I have no intention of adding support for any additional PostgreSQL drivers beyond pgx.

Activity

  1. added this to the v1.4.0 milestone on May 1, 2020
  2. ldelossa commented on May 28, 2020

    @ldelossa

    We currently use PGX and its batching mechanism. Would be great if you keep pgx batching in mind while this unfolds.

  3. kyleconroy commented on May 28, 2020

    @kyleconroy
    CollaboratorAuthor

    @ldelossa Do you have an example of the batching API? This is the first I've heard of it

  4. ldelossa commented on May 28, 2020

    @ldelossa
  5. modified the milestones: v1.4.0, v1.5.0 on Jun 2, 2020
  6. powersjcb commented on Jun 8, 2020

    @powersjcb

    pgx is new to me, so I wanted to spend some time getting the driver working for the example in examples/booktest/postgresql/. Here's a quick diff of that: powersjcb#1

    Some learnings:

    • Several fields in pgtype do not implement MarshalJSON. (at least pgtype.Timestamp and pgtype.VarcharArray) So at first glance, it looks like fields wont be compatible with the emitjsontags feature of sqlc.
    • Many fields need to be initialized and then have a value Set into them using the following signature (dst *Timestamp) Set(src interface{}) error. User application code will no longer be able to type check these inputs at compile time. For exampleerr := pgtype.Timestamp{}.Set("asdf") will compile without errors.
  7. maxhawkins commented on Jun 9, 2020

    @maxhawkins
    Contributor

    Awesome!

    It would be cool to support decoding composite types at some point. It's pretty tedious to implement DecodeBinary since you have to pull out every value from the pgtype.Record by hand. Since we know the schema that could be automated and save a lot of time.

  8. maxhawkins commented on Jun 9, 2020

    @maxhawkins
    Contributor
    * Several fields in `pgtype` do not implement `MarshalJSON`. (at least `pgtype.Timestamp` and `pgtype.VarcharArray`) So at first glance, it looks like fields wont be compatible with the `emitjsontags` feature of sqlc.
    

    In the booktest example at least, the available column uses timestamptz whose pgtype counterpart Timestamptz does support JSON. Regardless I'm not sure it's a problem that raw timestamps don't have a JSON encoding. JSON times always have a zone and Postgres timestamps are ambiguous about what zone they're in so there's no natural conversion.

  9. mvrhov commented on Jun 9, 2020

    @mvrhov

    Do you really need to support pgtype... There are a lot of times you don't need it.. and pointer to native type is enough. This also means that you can use the same struct through most application and there is no need to convert between db struct and "domain" struct. The onl conversion is then for viewing purposes.

  10. powersjcb commented on Jun 10, 2020

    @powersjcb

    Thanks for the feedback @mvrhov! I was able to get my test cases working with some native go types and the pgx driver interfaces.

    Also, just discovered that sqlc only implements 1-dimensional array types, so that will help keep things simple. 👍

  11. johanbrandhorst commented on Jul 1, 2020

    @johanbrandhorst
    Contributor

    I noticed we're still using pq.Array for postgres array type (e.g. TEXT[] becomes pq.Array([]string)). Is it possible for these types to map to the pgx types instead (i.e. TEXT[] becomes pgtype.TextArray)? I tried using an override and it didn't seem to work in 1.4.0.

  12. 3 remaining items

  13. georgysavva commented on Aug 4, 2020

    @georgysavva

    @kyleconroy Thanks for explaining.
    It would be a great improvement to fully support pgx, can't wait for it!

  14. Streppel commented on Dec 23, 2020

    @Streppel
    Contributor

    Hey guys! @kyleconroy do we have any updates on this? I've just hit this wall unfortunately.

    Edit: I'm creating a fork right now with a colleague and we'll try to work this out for our case (pgxpool.Pool) as we need to deliver something for next week, if we're able to get this fixed I'll let you know here

  15. Streppel commented on Dec 24, 2020

    @Streppel
    Contributor

    Hey everyone, just in time for christmas

    I ended up doing something that worked out fine for me. You can check what's different in this diff.

    itaintmuch

    Usage remains equal, except that you need to inform a new parameter at the startup configuration yml file, as in

    version: "1"
    packages:
        sql_library: "pgx/v4"

    If this parameter is missing it defaults to the old behavior. Currently only supporting :one, :many, :exec (still need to implement others commands and tags)

    I'm not very fond of this name I've used but couldn't think of anything better at the time. From my restricted testing everything looks fine to me, however I didn't do anything fancy yet. Maybe this could be a start.

    Edit: to check it yourself, download my fork, switch branches to feat/pgx_pool_support, compile it and install it locally following the README instructions and test it!

  16. Streppel commented on Jan 5, 2021

    @Streppel
    Contributor

    @kyleconroy and others: even though the above fits my use case (which is indeed very simple at this moment) it still is very premature in many aspects to even consider opening a pull request. Despite that, do you think the changes made here are heading in the right direction? If so, we could maybe merge this on a new development branch and continue work over there

  17. kevinburke1 commented on Jan 11, 2021

    @kevinburke1
    Contributor

    Just following up here - found another data race in lib/pq and it would be great to have a chance to evaluate other drivers, but at the moment we're pretty tied to using sqlc.

  18. tv42 commented on Jan 11, 2021

    @tv42

    @kevinburkemeter pgx/stdlib works ok with sqlc.

  19. kevinburke1 commented on Jan 12, 2021

    @kevinburke1
    Contributor

    working on that. is there a currently supported way to replace pq.Array?

  20. mvrhov commented on Jan 12, 2021

    @mvrhov

    afaik you don't need it for standard types.

  21. kevinburke1 commented on Jan 12, 2021

    @kevinburke1
    Contributor

    pq.Array is part of github.com/lib/pq, a competing SQL driver, not part of the standard library, so it seems unlikely pgx would support it

  22. johanbrandhorst commented on Jan 12, 2021

    @johanbrandhorst
    Contributor

    pq.Array implements the database/sql/driver.Valuer and database/sql.Scanner interfaces, so it works fine with pgx in my testing. It's a bit messy to import both, but it works.

  23. johanbrandhorst commented on Jun 16, 2021

    @johanbrandhorst
    Contributor

    Did #1037 replace the use of pq.Array for postgres arrays? Otherwise I wouldn't consider this issue completely closed.

  24. esenmx commented on Aug 31, 2021

    @esenmx

    @johanbrandhorst Is it possible to generate pgtype.TextArray? I'm fighting with source codes and sqlc.yaml couldn't find a way yet.

  25. johanbrandhorst commented on Aug 31, 2021

    @johanbrandhorst
    Contributor

    I don't think is it, yet.

  26. johanbrandhorst commented on Nov 8, 2021

    @johanbrandhorst
    Contributor

    I created #1276 and #1275 to track removal of pq.Array and support of batching, respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions