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 {
|
||||
// ExecResults reads the results from the next query in the batch as if the query has been sent with Exec.
|
||||
ExecResults() (pgconn.CommandTag, error)
|
||||
// Exec reads the results from the next query in the batch as if the query has been sent with Conn.Exec.
|
||||
Exec() (pgconn.CommandTag, error)
|
||||
|
||||
// QueryResults reads the results from the next query in the batch as if the query has been sent with Query.
|
||||
QueryResults() (Rows, error)
|
||||
// Query reads the results from the next query in the batch as if the query has been sent with Conn.Query.
|
||||
Query() (Rows, error)
|
||||
|
||||
// QueryRowResults reads the results from the next query in the batch as if the query has been sent with QueryRow.
|
||||
QueryRowResults() Row
|
||||
// QueryRow reads the results from the next query in the batch as if the query has been sent with Conn.QueryRow.
|
||||
QueryRow() Row
|
||||
|
||||
// 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.
|
||||
|
@ -48,8 +48,8 @@ type batchResults struct {
|
|||
err error
|
||||
}
|
||||
|
||||
// ExecResults 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) {
|
||||
// Exec reads the results from the next query in the batch as if the query has been sent with Exec.
|
||||
func (br *batchResults) Exec() (pgconn.CommandTag, error) {
|
||||
if br.err != nil {
|
||||
return nil, br.err
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ func (br *batchResults) ExecResults() (pgconn.CommandTag, error) {
|
|||
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.
|
||||
func (br *batchResults) QueryResults() (Rows, error) {
|
||||
// Query reads the results from the next query in the batch as if the query has been sent with Query.
|
||||
func (br *batchResults) Query() (Rows, error) {
|
||||
rows := br.conn.getRows(br.ctx, "batch query", nil)
|
||||
|
||||
if br.err != nil {
|
||||
|
@ -88,9 +88,9 @@ func (br *batchResults) QueryResults() (Rows, error) {
|
|||
return rows, nil
|
||||
}
|
||||
|
||||
// QueryRowResults reads the results from the next query in the batch as if the query has been sent with QueryRow.
|
||||
func (br *batchResults) QueryRowResults() Row {
|
||||
rows, _ := br.QueryResults()
|
||||
// QueryRow reads the results from the next query in the batch as if the query has been sent with QueryRow.
|
||||
func (br *batchResults) QueryRow() Row {
|
||||
rows, _ := br.Query()
|
||||
return (*connRow)(rows.(*connRows))
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func TestConnSendBatch(t *testing.T) {
|
|||
|
||||
br := conn.SendBatch(context.Background(), batch)
|
||||
|
||||
ct, err := br.ExecResults()
|
||||
ct, err := br.Exec()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func TestConnSendBatch(t *testing.T) {
|
|||
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
||||
}
|
||||
|
||||
ct, err = br.ExecResults()
|
||||
ct, err = br.Exec()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func TestConnSendBatch(t *testing.T) {
|
|||
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
||||
}
|
||||
|
||||
ct, err = br.ExecResults()
|
||||
ct, err = br.Exec()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func TestConnSendBatch(t *testing.T) {
|
|||
t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1)
|
||||
}
|
||||
|
||||
rows, err := br.QueryResults()
|
||||
rows, err := br.Query()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ func TestConnSendBatch(t *testing.T) {
|
|||
t.Fatal(rows.Err())
|
||||
}
|
||||
|
||||
err = br.QueryRowResults().Scan(&amount)
|
||||
err = br.QueryRow().Scan(&amount)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ func TestConnSendBatchWithPreparedStatement(t *testing.T) {
|
|||
br := conn.SendBatch(context.Background(), batch)
|
||||
|
||||
for i := 0; i < queryCount; i++ {
|
||||
rows, err := br.QueryResults()
|
||||
rows, err := br.Query()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
|
|||
|
||||
br := conn.SendBatch(context.Background(), batch)
|
||||
|
||||
rows, err := br.QueryResults()
|
||||
rows, err := br.Query()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
|
|||
|
||||
rows.Close()
|
||||
|
||||
rows, err = br.QueryResults()
|
||||
rows, err = br.Query()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ func TestConnSendBatchQueryError(t *testing.T) {
|
|||
|
||||
br := conn.SendBatch(context.Background(), batch)
|
||||
|
||||
rows, err := br.QueryResults()
|
||||
rows, err := br.Query()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ func TestConnSendBatchQuerySyntaxError(t *testing.T) {
|
|||
br := conn.SendBatch(context.Background(), batch)
|
||||
|
||||
var n int32
|
||||
err := br.QueryRowResults().Scan(&n)
|
||||
err := br.QueryRow().Scan(&n)
|
||||
if pgErr, ok := err.(*pgconn.PgError); !(ok && pgErr.Code == "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)
|
||||
|
||||
var value int
|
||||
err := br.QueryRowResults().Scan(&value)
|
||||
err := br.QueryRow().Scan(&value)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
ct, err := br.ExecResults()
|
||||
ct, err := br.Exec()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -367,13 +367,13 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
|
|||
|
||||
br := conn.SendBatch(context.Background(), batch)
|
||||
|
||||
rows, err := br.QueryResults()
|
||||
rows, err := br.Query()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
ct, err := br.ExecResults()
|
||||
ct, err := br.Exec()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ func TestTxSendBatch(t *testing.T) {
|
|||
br := tx.SendBatch(context.Background(), batch)
|
||||
|
||||
var id int
|
||||
err := br.QueryRowResults().Scan(&id)
|
||||
err := br.QueryRow().Scan(&id)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ func TestTxSendBatch(t *testing.T) {
|
|||
|
||||
br = tx.SendBatch(context.Background(), batch)
|
||||
|
||||
ct, err := br.ExecResults()
|
||||
ct, err := br.Exec()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ func TestTxSendBatch(t *testing.T) {
|
|||
}
|
||||
|
||||
var amount int
|
||||
err = br.QueryRowResults().Scan(&amount)
|
||||
err = br.QueryRow().Scan(&amount)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ func TestTxSendBatchRollback(t *testing.T) {
|
|||
br := tx.SendBatch(context.Background(), batch)
|
||||
|
||||
var id int
|
||||
err := br.QueryRowResults().Scan(&id)
|
||||
err := br.QueryRow().Scan(&id)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ func TestConnBeginBatchDeferredError(t *testing.T) {
|
|||
|
||||
br := conn.SendBatch(context.Background(), batch)
|
||||
|
||||
rows, err := br.QueryResults()
|
||||
rows, err := br.Query()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -579,7 +579,7 @@ func testConnSendBatch(t *testing.T, conn *pgx.Conn, queryCount int) {
|
|||
br := conn.SendBatch(context.Background(), batch)
|
||||
|
||||
for j := 0; j < queryCount; j++ {
|
||||
rows, err := br.QueryResults()
|
||||
rows, err := br.Query()
|
||||
require.NoError(t, err)
|
||||
|
||||
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)
|
||||
|
||||
for j := 0; j < queryCount; j++ {
|
||||
rows, err := br.QueryResults()
|
||||
rows, err := br.Query()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -9,15 +9,15 @@ type errBatchResults struct {
|
|||
err error
|
||||
}
|
||||
|
||||
func (br errBatchResults) ExecResults() (pgconn.CommandTag, error) {
|
||||
func (br errBatchResults) Exec() (pgconn.CommandTag, error) {
|
||||
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
|
||||
}
|
||||
|
||||
func (br errBatchResults) QueryRowResults() pgx.Row {
|
||||
func (br errBatchResults) QueryRow() pgx.Row {
|
||||
return errRow{err: br.err}
|
||||
}
|
||||
|
||||
|
@ -30,16 +30,16 @@ type poolBatchResults struct {
|
|||
c *Conn
|
||||
}
|
||||
|
||||
func (br *poolBatchResults) ExecResults() (pgconn.CommandTag, error) {
|
||||
return br.br.ExecResults()
|
||||
func (br *poolBatchResults) Exec() (pgconn.CommandTag, error) {
|
||||
return br.br.Exec()
|
||||
}
|
||||
|
||||
func (br *poolBatchResults) QueryResults() (pgx.Rows, error) {
|
||||
return br.br.QueryResults()
|
||||
func (br *poolBatchResults) Query() (pgx.Rows, error) {
|
||||
return br.br.Query()
|
||||
}
|
||||
|
||||
func (br *poolBatchResults) QueryRowResults() pgx.Row {
|
||||
return br.br.QueryRowResults()
|
||||
func (br *poolBatchResults) QueryRow() pgx.Row {
|
||||
return br.br.QueryRow()
|
||||
}
|
||||
|
||||
func (br *poolBatchResults) Close() error {
|
||||
|
|
|
@ -75,11 +75,11 @@ func testSendBatch(t *testing.T, db sendBatcher) {
|
|||
|
||||
var err error
|
||||
var n int32
|
||||
err = br.QueryRowResults().Scan(&n)
|
||||
err = br.QueryRow().Scan(&n)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, n)
|
||||
|
||||
err = br.QueryRowResults().Scan(&n)
|
||||
err = br.QueryRow().Scan(&n)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, n)
|
||||
|
||||
|
|
Loading…
Reference in New Issue