Skip to content

Commit

Permalink
Batch.Queue: document always uses the conn's DefaultQueryExecMode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
evanj authored and jackc committed Dec 9, 2023
1 parent 20bf953 commit 384fe77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type Batch struct {
}

// Queue queues a query to batch b. query can be an SQL query or the name of a prepared statement.
// The only pgx option argument that is supported is QueryRewriter. Queries are executed using the
// connection's DefaultQueryExecMode.
func (b *Batch) Queue(query string, arguments ...any) *QueuedQuery {
qq := &QueuedQuery{
query: query,
Expand Down
5 changes: 3 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,14 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) (br BatchResults) {
return &batchResults{ctx: ctx, conn: c, err: err}
}

mode := c.config.DefaultQueryExecMode

for _, bi := range b.queuedQueries {
var queryRewriter QueryRewriter
sql := bi.query
arguments := bi.arguments

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

// TODO: changing mode per batch? Update Batch.Queue function comment when implemented
mode := c.config.DefaultQueryExecMode
if mode == QueryExecModeSimpleProtocol {
return c.sendBatchQueryExecModeSimpleProtocol(ctx, b)
}
Expand Down

0 comments on commit 384fe77

Please sign in to comment.