-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline_test.go
79 lines (64 loc) · 2.04 KB
/
pipeline_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package pgx_test
import (
"context"
"testing"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/stretchr/testify/require"
)
func TestPipelineWithoutPreparedOrDescribedStatements(t *testing.T) {
t.Parallel()
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
pipeline := conn.PgConn().StartPipeline(ctx)
eqb := pgx.ExtendedQueryBuilder{}
err := eqb.Build(conn.TypeMap(), nil, []any{1, 2})
require.NoError(t, err)
pipeline.SendQueryParams(`select $1::bigint + $2::bigint`, eqb.ParamValues, nil, eqb.ParamFormats, eqb.ResultFormats)
err = eqb.Build(conn.TypeMap(), nil, []any{3, 4, 5})
require.NoError(t, err)
pipeline.SendQueryParams(`select $1::bigint + $2::bigint + $3::bigint`, eqb.ParamValues, nil, eqb.ParamFormats, eqb.ResultFormats)
err = pipeline.Sync()
require.NoError(t, err)
results, err := pipeline.GetResults()
require.NoError(t, err)
rr, ok := results.(*pgconn.ResultReader)
require.True(t, ok)
rows := pgx.RowsFromResultReader(conn.TypeMap(), rr)
rowCount := 0
var n int64
for rows.Next() {
err = rows.Scan(&n)
require.NoError(t, err)
rowCount++
}
require.NoError(t, rows.Err())
require.Equal(t, 1, rowCount)
require.Equal(t, "SELECT 1", rows.CommandTag().String())
require.EqualValues(t, 3, n)
results, err = pipeline.GetResults()
require.NoError(t, err)
rr, ok = results.(*pgconn.ResultReader)
require.True(t, ok)
rows = pgx.RowsFromResultReader(conn.TypeMap(), rr)
rowCount = 0
n = 0
for rows.Next() {
err = rows.Scan(&n)
require.NoError(t, err)
rowCount++
}
require.NoError(t, rows.Err())
require.Equal(t, 1, rowCount)
require.Equal(t, "SELECT 1", rows.CommandTag().String())
require.EqualValues(t, 12, n)
results, err = pipeline.GetResults()
require.NoError(t, err)
_, ok = results.(*pgconn.PipelineSync)
require.True(t, ok)
results, err = pipeline.GetResults()
require.NoError(t, err)
require.Nil(t, results)
err = pipeline.Close()
require.NoError(t, err)
})
}