Commit Graph

65 Commits (bf1c1d7848c087c99fb30a67657a5ec3197f7f32)

Author SHA1 Message Date
Pavlo Golub c90f82a4e3 make properties of QueuedQuery and Batch public, closes #1878 2024-01-25 18:03:59 -06:00
Evan Jones 384fe7775c Batch.Queue: document always uses the conn's DefaultQueryExecMode
The only way to change the query mode used by Batch.Queue and
SendBatch is to use a connection with a different
DefaultQueryExecMode. Add this to the function documentation.

Conn.SendBatch: Move where mode is defined to make this clearer in
the code. I spent time looking for the option that does not exist.
2023-12-09 11:47:56 -06:00
Jack Christensen 6defa2a607 Fix error when using BatchResults.Exec
...on a select that returns an error after some rows.

This was initially found in by a failure with CockroachDB because it
seems to send a RowDescription before an error even when no rows are
returned. PostgreSQL doesn't.
2023-04-20 21:43:59 -05:00
Jack Christensen a23a423f55 Fix pipelineBatchResults.Exec() not returning error from ResultReader 2023-04-20 21:19:41 -05:00
Jack Christensen 09371981f9 Fix pipeline batch results not closing pipeline
when error occurs while reading directly from results instead of using
a callback.

https://github.com/jackc/pgx/issues/1578
2023-04-20 20:58:04 -05:00
Jack Christensen be79f1c8f5 Allow batch callback function to override error
https://github.com/jackc/pgx/pull/1538#issuecomment-1486083411
2023-03-31 20:18:05 -05:00
Jack Christensen 7af80ae8a6 Batch Query callback is called even when there is an error
This allows the callback to handle additional error types such as
foreign key constraint violations.

See https://github.com/jackc/pgx/pull/1538.
2023-03-25 10:21:34 -05:00
Jack Christensen 29254180ca Add callback functions to queued queries
Improve batch query ergonomics by allowing the code to handle the
results of a query to be right next to the query.
2022-07-16 17:46:47 -05:00
Jack Christensen 78875bb95a Add tracing support
Replaces existing logging support. Package tracelog provides adapter for
old style logging.

https://github.com/jackc/pgx/issues/1061
2022-07-16 12:27:10 -05:00
Jack Christensen e7aa76ccf9 SendBatch now uses pipeline mode to prepare and describe statements
Previously, a batch with 10 unique parameterized statements executed
100 times would entail 11 network round trips. 1 for each prepare /
describe and 1 for executing them all. Now pipeline mode is used to
prepare / describe all statements in a single network round trip. So it
would only take 2 round trips.
2022-07-09 09:32:36 -05:00
Jack Christensen 76946fb5a3 Replace QueryFunc with ForEachScannedRow 2022-07-07 20:29:04 -05:00
Jack Christensen 1168b375e4 Expose pgx functionality for manual integration with pgconn
This is primarily useful for using pipeline mode.
2022-07-04 13:29:49 -05:00
Jack Christensen b72b0daa5a Add QueryRewriter interface 2022-04-23 17:26:42 -05:00
Jack Christensen f14fb3d692 Replace interface{} with any 2022-04-09 09:12:55 -05:00
Jack Christensen 9c5dfbdfb3 pgconn.CommandTag is now an opaque type
It now makes a copy instead of retaining driver memory. This is in
preparation to reuse the driver read buffer.
2022-02-12 10:26:26 -06:00
Jack Christensen 318018504a Merge branch 'master' into v5-dev 2022-02-07 11:22:01 -06:00
Jack Christensen e8857f04a1 Make BatchResults.Close safe to be called multiple times
https://github.com/jackc/pgx/issues/1138
https://github.com/jackc/pgx/issues/938
2022-02-07 10:44:39 -06:00
Jack Christensen 72cc95e4dd Bump module version to v5 2021-12-11 13:29:03 -06:00
Jack Christensen 0e293b966c Finish import of pgconn 2021-12-04 14:06:57 -06:00
Jack Christensen 38cd1b40aa Add QueryFunc to BatchResults
https://github.com/jackc/pgx/issues/1048#issuecomment-915123822
2021-09-11 10:32:02 -05:00
Jack Christensen a49f4bb135 Use errors instead of golang.org/x/xerrors 2021-03-25 09:55:12 -04:00
Matt Schultz a0028cbd0d Handle SendBatch calls on closed transactions with null connections. This was previously panicking due to a null pointer exception as exposed in the provided unit test. 2021-03-19 08:38:19 -05:00
Jack Christensen 710ddf7134
Merge pull request #682 from WGH-/batch-len
Add Len() method to *pgx.Batch
2020-02-22 09:21:21 -06:00
WGH c01721e3ba Add Len() method to *pgx.Batch
This makes the API slightly easier to use when number of calls to
Queue() cannot be trivially computed.

For example, if the program contains the loop like the following,
a separate variable counting the iterations is needed:

    numHeaders := 0
    for _, header := range prepareHeadersForInsert(*res.Headers) {
        headerBatch.Queue("INSERT ...", ...)
        numHeaders++
    }

    headerBatchResult := tx.SendBatch(ctx, headerBatch)

    for i := 0; i < numHeaders; i++ {
        _, err := headerBatchResult.Exec()
        // ...
    }

With method Len(), this extra variable can be eliminated.
2020-02-21 22:28:34 +03:00
Ben Bader a10b89ebc0 Add query logging for individual batch items 2020-02-18 16:22:29 -08:00
Jack Christensen e16bfa9af5 Add docs regarding closing BatchResults 2019-09-19 22:46:43 -05:00
ferhat elmas 912b2fcc3a Fix some typos 2019-09-04 12:46:50 +02:00
Jack Christensen d5a6a5e7e0 Remove Results suffix from BatchResults methods 2019-08-24 23:41:28 -05:00
Jack Christensen 64b07f0d66 Batch uses statement cache.
This streamlines Queue's interface as well.
2019-08-24 23:40:21 -05:00
Jack Christensen 6972a57421 pgtype.OID type should only be used for scanning and encoding values
It was a mistake to use it in other contexts. This made interop
difficult between pacakges that depended on pgtype such as pgx and
packages that did not like pgconn and pgproto3. In particular this was
awkward for prepared statements.

This is preparation for removing pgx.PreparedStatement in favor of
pgconn.PreparedStatement.
2019-08-24 13:55:57 -05:00
Jack Christensen 3028821487 Add context.Context to Logger interface
This allows custom logger adapters to add additional fields to log
messages. For example, a HTTP server may with to log the request ID.

fixes #428
2019-08-03 16:16:21 -05:00
Jack Christensen 7b1272d254 Add SendBatch to pool 2019-04-25 15:07:35 -05:00
Jack Christensen aed6b822d9 Split batch command and result 2019-04-24 16:39:06 -05:00
Jack Christensen 7b4e145e7c Remove Batch.die 2019-04-24 16:03:50 -05:00
Jack Christensen 3795c7131a Remove unused Batch.ctx 2019-04-24 16:02:23 -05:00
Jack Christensen 044a55ad2c Remove unused Batch.resultsRead 2019-04-24 13:44:25 -05:00
Jack Christensen 187157e773 Remove unused Batch.inTx 2019-04-24 13:43:37 -05:00
Jack Christensen d5c510b590 Remove unused Batch field 2019-04-24 13:40:54 -05:00
Jack Christensen 1b8f0016e9 Split pgtype into own repo 2019-04-20 19:20:00 -05:00
Jack Christensen cc3461e65d Use golang.org/x/xerrors 2019-04-20 17:43:44 -05:00
Jack Christensen efb333df6b Fix go modules
Wow. This is fun. Sure is easy to get modules wrong when upgrading a v2+
project.
2019-04-20 17:41:08 -05:00
Jack Christensen 1f010f412d Simplify Batch.Queue for prepared statements 2019-04-20 11:29:28 -05:00
Jack Christensen af1beca9a5 Update pgconn to resolve batch deadlock issue 2019-04-20 11:27:43 -05:00
Jack Christensen ae73ca2da1 Update to more effecient pgconn 2019-04-19 15:55:45 -05:00
Jack Christensen 938ee9f434 Rows and Row are now interfaces 2019-04-11 17:58:16 -05:00
Jack Christensen acd15cf589 Remove some obsolete context handling 2019-04-10 14:25:06 -05:00
Jack Christensen 77a2da2b46 Replace connection pool 2019-04-10 11:09:42 -05:00
Jack Christensen 858d00788a Use extracted packages with Go modules 2019-04-05 10:59:47 -05:00
Jack Christensen bd181764bf Remove ensureConnectionReadyForQuery 2019-02-02 13:00:31 -06:00
Jack Christensen 5cb17c5859 Remove unused method 2019-02-02 11:52:25 -06:00