aboutsummaryrefslogtreecommitdiff
path: root/benchmark/internal/oblast_pgx/results.go
blob: 3ccb5ce28e2d9522b8dc0323b762e6098542840e (plain)
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
// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
// SPDX-License-Identifier: Apache-2.0

package oblast_pgx

import (
	"database/sql"
	"errors"

	"github.com/jackc/pgx/v5"
	"github.com/jackc/pgx/v5/pgconn"
	"go.xyrillian.de/oblast/handle"
)

type wrappedRows struct {
	inner pgx.Rows
}

var _ handle.Rows = wrappedRows{}

// Columns implements the [handle.Rows] interface.
func (r wrappedRows) Columns() ([]string, error) {
	descriptions := r.inner.FieldDescriptions()
	result := make([]string, len(descriptions))
	for idx, desc := range descriptions {
		result[idx] = desc.Name
	}
	return result, nil
}

// Close implements the [handle.Rows] interface.
func (r wrappedRows) Close() error {
	r.inner.Close()
	return nil
}

// Err implements the [handle.Rows] interface.
func (r wrappedRows) Err() error {
	return r.inner.Err()
}

// Next implements the [handle.Rows] interface.
func (r wrappedRows) Next() bool {
	return r.inner.Next()
}

// Scan implements the [handle.Rows] interface.
func (r wrappedRows) Scan(args ...any) error {
	return r.inner.Scan(args...)
}

type wrappedResult struct {
	inner pgconn.CommandTag
}

var _ sql.Result = wrappedResult{}

// LastInsertId implements the [sql.Result] interface.
func (r wrappedResult) LastInsertId() (int64, error) {
	return 0, errors.New("PostgreSQL does not support LastInsertId()")
}

// LastInsertId implements the [sql.Result] interface.
func (r wrappedResult) RowsAffected() (int64, error) {
	return r.inner.RowsAffected(), nil
}