mirror of https://github.com/jackc/pgx.git
Remove Results suffix from BatchResults methods
parent
64b07f0d66
commit
d5a6a5e7e0
26
batch.go
26
batch.go
|
@ -27,14 +27,14 @@ func (b *Batch) Queue(query string, arguments ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type BatchResults interface {
|
type BatchResults interface {
|
||||||
// ExecResults reads the results from the next query in the batch as if the query has been sent with Exec.
|
// Exec reads the results from the next query in the batch as if the query has been sent with Conn.Exec.
|
||||||
ExecResults() (pgconn.CommandTag, error)
|
Exec() (pgconn.CommandTag, error)
|
||||||
|
|
||||||
// QueryResults reads the results from the next query in the batch as if the query has been sent with Query.
|
// Query reads the results from the next query in the batch as if the query has been sent with Conn.Query.
|
||||||
QueryResults() (Rows, error)
|
Query() (Rows, error)
|
||||||
|
|
||||||
// QueryRowResults reads the results from the next query in the batch as if the query has been sent with QueryRow.
|
// QueryRow reads the results from the next query in the batch as if the query has been sent with Conn.QueryRow.
|
||||||
QueryRowResults() Row
|
QueryRow() Row
|
||||||
|
|
||||||
// Close closes the batch operation. Any error that occured during a batch operation may have made it impossible to
|
// Close closes the batch operation. Any error that occured during a batch operation may have made it impossible to
|
||||||
// resyncronize the connection with the server. In this case the underlying connection will have been closed.
|
// resyncronize the connection with the server. In this case the underlying connection will have been closed.
|
||||||
|
@ -48,8 +48,8 @@ type batchResults struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecResults reads the results from the next query in the batch as if the query has been sent with Exec.
|
// Exec reads the results from the next query in the batch as if the query has been sent with Exec.
|
||||||
func (br *batchResults) ExecResults() (pgconn.CommandTag, error) {
|
func (br *batchResults) Exec() (pgconn.CommandTag, error) {
|
||||||
if br.err != nil {
|
if br.err != nil {
|
||||||
return nil, br.err
|
return nil, br.err
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,8 @@ func (br *batchResults) ExecResults() (pgconn.CommandTag, error) {
|
||||||
return br.mrr.ResultReader().Close()
|
return br.mrr.ResultReader().Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryResults reads the results from the next query in the batch as if the query has been sent with Query.
|
// Query reads the results from the next query in the batch as if the query has been sent with Query.
|
||||||
func (br *batchResults) QueryResults() (Rows, error) {
|
func (br *batchResults) Query() (Rows, error) {
|
||||||
rows := br.conn.getRows(br.ctx, "batch query", nil)
|
rows := br.conn.getRows(br.ctx, "batch query", nil)
|
||||||
|
|
||||||
if br.err != nil {
|
if br.err != nil {
|
||||||
|
@ -88,9 +88,9 @@ func (br *batchResults) QueryResults() (Rows, error) {
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryRowResults reads the results from the next query in the batch as if the query has been sent with QueryRow.
|
// QueryRow reads the results from the next query in the batch as if the query has been sent with QueryRow.
|
||||||
func (br *batchResults) QueryRowResults() Row {
|
func (br *batchResults) QueryRow() Row {
|
||||||
rows, _ := br.QueryResults()
|
rows, _ := br.Query()
|
||||||
return (*connRow)(rows.(*connRows))
|
return (*connRow)(rows.(*connRows))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestConnSendBatch(t *testing.T) {
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
ct, err := br.ExecResults()
|
ct, err := br.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func TestConnSendBatch(t *testing.T) {
|
||||||
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ct, err = br.ExecResults()
|
ct, err = br.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func TestConnSendBatch(t *testing.T) {
|
||||||
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ct, err = br.ExecResults()
|
ct, err = br.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func TestConnSendBatch(t *testing.T) {
|
||||||
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := br.QueryResults()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ func TestConnSendBatch(t *testing.T) {
|
||||||
t.Fatal(rows.Err())
|
t.Fatal(rows.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = br.QueryRowResults().Scan(&amount)
|
err = br.QueryRow().Scan(&amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ func TestConnSendBatchWithPreparedStatement(t *testing.T) {
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
for i := 0; i < queryCount; i++ {
|
for i := 0; i < queryCount; i++ {
|
||||||
rows, err := br.QueryResults()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
rows, err := br.QueryResults()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
|
||||||
|
|
||||||
rows.Close()
|
rows.Close()
|
||||||
|
|
||||||
rows, err = br.QueryResults()
|
rows, err = br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ func TestConnSendBatchQueryError(t *testing.T) {
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
rows, err := br.QueryResults()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ func TestConnSendBatchQuerySyntaxError(t *testing.T) {
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
var n int32
|
var n int32
|
||||||
err := br.QueryRowResults().Scan(&n)
|
err := br.QueryRow().Scan(&n)
|
||||||
if pgErr, ok := err.(*pgconn.PgError); !(ok && pgErr.Code == "42601") {
|
if pgErr, ok := err.(*pgconn.PgError); !(ok && pgErr.Code == "42601") {
|
||||||
t.Errorf("rows.Err() => %v, want error code %v", err, 42601)
|
t.Errorf("rows.Err() => %v, want error code %v", err, 42601)
|
||||||
}
|
}
|
||||||
|
@ -330,12 +330,12 @@ func TestConnSendBatchQueryRowInsert(t *testing.T) {
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
var value int
|
var value int
|
||||||
err := br.QueryRowResults().Scan(&value)
|
err := br.QueryRow().Scan(&value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ct, err := br.ExecResults()
|
ct, err := br.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -367,13 +367,13 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
rows, err := br.QueryResults()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
rows.Close()
|
rows.Close()
|
||||||
|
|
||||||
ct, err := br.ExecResults()
|
ct, err := br.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ func TestTxSendBatch(t *testing.T) {
|
||||||
br := tx.SendBatch(context.Background(), batch)
|
br := tx.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
var id int
|
var id int
|
||||||
err := br.QueryRowResults().Scan(&id)
|
err := br.QueryRow().Scan(&id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -423,7 +423,7 @@ func TestTxSendBatch(t *testing.T) {
|
||||||
|
|
||||||
br = tx.SendBatch(context.Background(), batch)
|
br = tx.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
ct, err := br.ExecResults()
|
ct, err := br.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -432,7 +432,7 @@ func TestTxSendBatch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var amount int
|
var amount int
|
||||||
err = br.QueryRowResults().Scan(&amount)
|
err = br.QueryRow().Scan(&amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ func TestTxSendBatchRollback(t *testing.T) {
|
||||||
br := tx.SendBatch(context.Background(), batch)
|
br := tx.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
var id int
|
var id int
|
||||||
err := br.QueryRowResults().Scan(&id)
|
err := br.QueryRow().Scan(&id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ func TestConnBeginBatchDeferredError(t *testing.T) {
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
rows, err := br.QueryResults()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -579,7 +579,7 @@ func testConnSendBatch(t *testing.T, conn *pgx.Conn, queryCount int) {
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
for j := 0; j < queryCount; j++ {
|
for j := 0; j < queryCount; j++ {
|
||||||
rows, err := br.QueryResults()
|
rows, err := br.Query()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for k := 0; rows.Next(); k++ {
|
for k := 0; rows.Next(); k++ {
|
||||||
|
|
|
@ -815,7 +815,7 @@ func benchmarkMultipleQueriesBatch(b *testing.B, conn *pgx.Conn, queryCount int)
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(context.Background(), batch)
|
||||||
|
|
||||||
for j := 0; j < queryCount; j++ {
|
for j := 0; j < queryCount; j++ {
|
||||||
rows, err := br.QueryResults()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,15 @@ type errBatchResults struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br errBatchResults) ExecResults() (pgconn.CommandTag, error) {
|
func (br errBatchResults) Exec() (pgconn.CommandTag, error) {
|
||||||
return nil, br.err
|
return nil, br.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br errBatchResults) QueryResults() (pgx.Rows, error) {
|
func (br errBatchResults) Query() (pgx.Rows, error) {
|
||||||
return errRows{err: br.err}, br.err
|
return errRows{err: br.err}, br.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br errBatchResults) QueryRowResults() pgx.Row {
|
func (br errBatchResults) QueryRow() pgx.Row {
|
||||||
return errRow{err: br.err}
|
return errRow{err: br.err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,16 +30,16 @@ type poolBatchResults struct {
|
||||||
c *Conn
|
c *Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *poolBatchResults) ExecResults() (pgconn.CommandTag, error) {
|
func (br *poolBatchResults) Exec() (pgconn.CommandTag, error) {
|
||||||
return br.br.ExecResults()
|
return br.br.Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *poolBatchResults) QueryResults() (pgx.Rows, error) {
|
func (br *poolBatchResults) Query() (pgx.Rows, error) {
|
||||||
return br.br.QueryResults()
|
return br.br.Query()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *poolBatchResults) QueryRowResults() pgx.Row {
|
func (br *poolBatchResults) QueryRow() pgx.Row {
|
||||||
return br.br.QueryRowResults()
|
return br.br.QueryRow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *poolBatchResults) Close() error {
|
func (br *poolBatchResults) Close() error {
|
||||||
|
|
|
@ -75,11 +75,11 @@ func testSendBatch(t *testing.T, db sendBatcher) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var n int32
|
var n int32
|
||||||
err = br.QueryRowResults().Scan(&n)
|
err = br.QueryRow().Scan(&n)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, n)
|
assert.EqualValues(t, 1, n)
|
||||||
|
|
||||||
err = br.QueryRowResults().Scan(&n)
|
err = br.QueryRow().Scan(&n)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 2, n)
|
assert.EqualValues(t, 2, n)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue