Replace QueryFunc with ForEachScannedRow
This commit is contained in:
+2
-2
@@ -17,8 +17,8 @@ type BytesValuer interface {
|
||||
}
|
||||
|
||||
// DriverBytes is a byte slice that holds a reference to memory owned by the driver. It is only valid from the time it
|
||||
// is scanned until Rows.Next or Rows.Close is called. It is safe to use in a function passed to QueryFunc. It is never
|
||||
// safe to use DriverBytes with QueryRow as Row.Scan internally calls Rows.Close before returning.
|
||||
// is scanned until Rows.Next or Rows.Close is called. It is never safe to use DriverBytes with QueryRow as Row.Scan
|
||||
// internally calls Rows.Close before returning.
|
||||
type DriverBytes []byte
|
||||
|
||||
func (b *DriverBytes) ScanBytes(v []byte) error {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,13 +22,12 @@ func BenchmarkQuery<%= format_name %>FormatDecode_PG_<%= pg_type %>_to_Go_<%= go
|
||||
b.ResetTimer()
|
||||
var v [<%= columns %>]<%= go_type %>
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := conn.QueryFunc(
|
||||
rows, _ := conn.Query(
|
||||
ctx,
|
||||
`select <% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>n::<%= pg_type %> + <%= col_idx%><% end %> from generate_series(1, <%= rows %>) n`,
|
||||
[]any{pgx.QueryResultFormats{<%= format_code %>}},
|
||||
[]any{<% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>&v[<%= col_idx%>]<% end %>},
|
||||
func(pgx.QueryFuncRow) error { return nil },
|
||||
)
|
||||
_, err := pgx.ForEachScannedRow(rows, []any{<% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>&v[<%= col_idx%>]<% end %>}, func() error { return nil })
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
@@ -47,13 +46,12 @@ func BenchmarkQuery<%= format_name %>FormatDecode_PG_Int4Array_With_Go_Int4Array
|
||||
b.ResetTimer()
|
||||
var v []int32
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := conn.QueryFunc(
|
||||
rows, _ := conn.Query(
|
||||
ctx,
|
||||
`select array_agg(n) from generate_series(1, <%= array_size %>) n`,
|
||||
[]any{pgx.QueryResultFormats{<%= format_code %>}},
|
||||
[]any{&v},
|
||||
func(pgx.QueryFuncRow) error { return nil },
|
||||
)
|
||||
_, err := pgx.ForEachScannedRow(rows, []any{&v}, func() error { return nil })
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user