-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to pgx v5 #99
base: main
Are you sure you want to change the base?
Conversation
- For pggen row structs, implement pgx.RowScanner. - Remove the typeResolver, since we're punting type resolution to the pgx.Conn type map for now. #74
@@ -263,7 +263,7 @@ func (c CompositeInitDeclarer) Declare(string) (string, error) { | |||
// of a composite type as a generic array: []interface{}. Necessary because we | |||
// can only set pgtype.CompositeType from a []interface{}. | |||
// | |||
// Revisit after https://github.com/jackc/pgtype/pull/100 to see if we can | |||
// Revisit after https://github.com/jackc/pgx/v5/pgtype/pull/100 to see if we can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken text replace
Hey! I was interested in getting this at least sort of working and put together a set of minimal fixes here: mypricehealth@ec3a10c The main things fixed are that the complete removal of This was enough to at least get the generation of some of the |
@DavidArchibald I am interested in upgrading to pgx-v5. Do your changes remove support for composite types or arrays of composite types? joe/pgxv5...mypricehealth:pggen:joe/pgxv5 |
@kirk-anchor on the tip of my branch I was able to get all the code I personally needed generating which included generating structs for all the queries I needed, arrays included. I don't know if I tested composite types explicitly so I guess I'd recommend trying it out and seeing if it works for your queries. If it's not working I'd appreciate a simple reproduction and then I'd probably be able to fix it. Though just to be explicit, I whipped this up in an afternoon and I'd actually be surprised if my set of fixes didn't in of themselves include multiple problems. What I can say is that I audited all the code I generated and it all worked for the queries I was writing but that's it. I'm aware of a handful of issues but they were in types I didn't personally use and I couldn't figure out a straightforward migration from v4 -> v5. |
@DavidArchibald When I use a composite type, it tries to reference the now removed func (q *DBQuerier) InsertMyTable(ctx context.Context, myRows []MyTable) (pgconn.CommandTag, error) {
ctx = context.WithValue(ctx, QueryName{}, "InsertMyTable")
cmdTag, err := q.conn.Exec(ctx, insertMyTableSQL, q.types.newMyTableArrayInit(myRows))
if err != nil {
return pgconn.CommandTag{}, fmt.Errorf("exec query InsertMyTable: %w", err)
}
return cmdTag, err
} I have queries like this. -- name: InsertMyTable :exec
INSERT INTO my_table (my_col1, my_col2, my_col3)
SELECT
my_col1,
my_col2,
my_col3
FROM
unnest(pggen.arg('my_rows')::my_table[]);
-- name: GetMyTable :many
SELECT
my_table
FROM
my_table; This way I have a common InsertMyTable(ctx context.Context, myRows []MyTable) (pgconn.CommandTag, error)
GetMyTable(ctx context.Context) ([]MyTable, error) |
Looks like on pgx-v5, I can get the composite type with @jschaf Do you plan to continue development? I may see if adding composite types to the fork will get my queries working. Arrays use Go generics now so arrays of composites should work too. Do you plan to upstream the changes from the fork or take another approach? |
I was able to get the composite type example queries I provided working. Also fixed some bugs. mypricehealth/pggen@joe/pgxv5...kirk-anchor:pggen:pgxv5 |
I can't see the failed test logs, but is this something if someone was to pickup you'd be happy to review? |
Yes, work has me swamped, but I'd be happy to review a PR. |
@kirk-anchor I see that you've maintained that fork and bumped pgx to v5. Do you feel like this is something that can be worked into a PR? Happy to help. |
I've been continuing to update it here https://github.com/kirk-anchor/pggen I recently upgraded Go module versions. I already added support for composite types. The code needs some cleanup. I am also considering adding some other features, maybe a |
Another issue I have to solve is the order of RegisterType() for composite types. It currently does them in alphabetical order but if you have a composite type that contains another composite type, you must register the composite type it contains before registering that composite type. |
@kirk-anchor is that something you can put in a PR to here? |
Potentially, if there's interest. It uses |
Yes, I’m okay with that approach. The public interface won’t change, right? |
@kirk-anchor if there is anything you need help with getting a PR in I would be willing to help as much as I can |
@kirk-anchor I have a few changes on top of your's at https://github.com/mypricehealth/pggen/ again. It includes a lot of small things, some of which I argue should be removed completely for this repo. The biggest one though is multi-statement support which you may be interested in. |
I will take a look at it later this week, I have not had time. @DavidArchibald I did see you made some changes on top of mine, I will go through them. At a glance, I'm not sure I understand the multi-statement support. It doesn't seem to be batch queries like pggen used to have. If it's multiple hardcoded statements in the .sql file that are executed together, I just use a CTE for that. |
@kirk-anchor I'm admittedly unfamiliar with the batch queries pggen used to have. It is indeed multiple hardcoded statements that are executed together. It's helpful for cases where CTEs wouldn't work or would otherwise be clunky. |
The pggen batch queries were pgx batch queries, which were just concatenated SQL queries, e.g., pgx5 supports Postgres query pipelining, allowing precise control over when statements execute. See jackc/pgx#1774 for more details. |
#74