Skip to content

Commit 384fe77

Browse files
evanjjackc
authored andcommitted
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.
1 parent 20bf953 commit 384fe77

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

batch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type Batch struct {
6161
}
6262

6363
// Queue queues a query to batch b. query can be an SQL query or the name of a prepared statement.
64+
// The only pgx option argument that is supported is QueryRewriter. Queries are executed using the
65+
// connection's DefaultQueryExecMode.
6466
func (b *Batch) Queue(query string, arguments ...any) *QueuedQuery {
6567
qq := &QueuedQuery{
6668
query: query,

conn.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,15 +902,14 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) (br BatchResults) {
902902
return &batchResults{ctx: ctx, conn: c, err: err}
903903
}
904904

905-
mode := c.config.DefaultQueryExecMode
906-
907905
for _, bi := range b.queuedQueries {
908906
var queryRewriter QueryRewriter
909907
sql := bi.query
910908
arguments := bi.arguments
911909

912910
optionLoop:
913911
for len(arguments) > 0 {
912+
// Update Batch.Queue function comment when additional options are implemented
914913
switch arg := arguments[0].(type) {
915914
case QueryRewriter:
916915
queryRewriter = arg
@@ -932,6 +931,8 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) (br BatchResults) {
932931
bi.arguments = arguments
933932
}
934933

934+
// TODO: changing mode per batch? Update Batch.Queue function comment when implemented
935+
mode := c.config.DefaultQueryExecMode
935936
if mode == QueryExecModeSimpleProtocol {
936937
return c.sendBatchQueryExecModeSimpleProtocol(ctx, b)
937938
}

0 commit comments

Comments
 (0)