-
Notifications
You must be signed in to change notification settings - Fork 777
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
feat(pgx): Add support for batch operations #1437
Conversation
I was surprised to see the error in CI, but I see it was recently added in |
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.
If you have time, a few follow-on asks after this is merged.
- Can you update query-annotations.md to make it obvious that this only works for the PostgreSQL / Go / pgx combo?
- Can you rename the
batch import
test folder tobatch_import
? Our naming convention doesn't include spaces.
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.
Actually, it looks like that space issues with batch import
is causing the build to fail, so you'll need to fix that before I can merge it in.
batch* cmds only work with postgres/pgx/go
Yes, good idea.
Mine neither! Fixed. |
This is really nice. Thanks for doing it. |
This change offers one possible implementation of batch operations via the
pgx
driver. A full example exercising all of the new API surface can be found inexamples/batch/postgresql/db_test.go
.This implementation adds 3 new commands:
batchexec
,batchmany
, andbatchone
.Each of them returns a batch object. The batch object has 2 methods:
pgx.BatchResults
object (Exec
,Query
,QueryRow
, respectively).Each of the methods takes a callback as a parameter as follows:
The first parameter in the callback is the index of the result from the batch result. That is, if the batch result is completely consumed,
i
will range from 0 tolen(input_params_slice) - 1
.Close
method for closing the batch result early and returning the underlying connection.closes #1275