Skip to content

Commit

Permalink
make QueuedQuery.Fn property public, closes #1878
Browse files Browse the repository at this point in the history
This commit fixes the overlook of the #1886 where SQL and Arguments
properties were exposed
  • Loading branch information
pashagolub authored and jackc committed May 12, 2024
1 parent a966716 commit 523411a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
type QueuedQuery struct {
SQL string
Arguments []any
fn batchItemFunc
Fn batchItemFunc
sd *pgconn.StatementDescription
}

type batchItemFunc func(br BatchResults) error

// Query sets fn to be called when the response to qq is received.
func (qq *QueuedQuery) Query(fn func(rows Rows) error) {
qq.fn = func(br BatchResults) error {
qq.Fn = func(br BatchResults) error {
rows, _ := br.Query()
defer rows.Close()

Expand All @@ -36,15 +36,15 @@ func (qq *QueuedQuery) Query(fn func(rows Rows) error) {

// Query sets fn to be called when the response to qq is received.
func (qq *QueuedQuery) QueryRow(fn func(row Row) error) {
qq.fn = func(br BatchResults) error {
qq.Fn = func(br BatchResults) error {
row := br.QueryRow()
return fn(row)
}
}

// Exec sets fn to be called when the response to qq is received.
func (qq *QueuedQuery) Exec(fn func(ct pgconn.CommandTag) error) {
qq.fn = func(br BatchResults) error {
qq.Fn = func(br BatchResults) error {
ct, err := br.Exec()
if err != nil {
return err
Expand Down Expand Up @@ -228,8 +228,8 @@ func (br *batchResults) Close() error {

// Read and run fn for all remaining items
for br.err == nil && !br.closed && br.b != nil && br.qqIdx < len(br.b.QueuedQueries) {
if br.b.QueuedQueries[br.qqIdx].fn != nil {
err := br.b.QueuedQueries[br.qqIdx].fn(br)
if br.b.QueuedQueries[br.qqIdx].Fn != nil {
err := br.b.QueuedQueries[br.qqIdx].Fn(br)
if err != nil {
br.err = err
}
Expand Down Expand Up @@ -397,8 +397,8 @@ func (br *pipelineBatchResults) Close() error {

// Read and run fn for all remaining items
for br.err == nil && !br.closed && br.b != nil && br.qqIdx < len(br.b.QueuedQueries) {
if br.b.QueuedQueries[br.qqIdx].fn != nil {
err := br.b.QueuedQueries[br.qqIdx].fn(br)
if br.b.QueuedQueries[br.qqIdx].Fn != nil {
err := br.b.QueuedQueries[br.qqIdx].Fn(br)
if err != nil {
br.err = err
}
Expand Down

0 comments on commit 523411a

Please sign in to comment.