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

package oblast_pgx

import (
	"context"
	"database/sql"

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

type wrappedPreparedStatement struct {
	ctx       context.Context
	statement *pgconn.StatementDescription
	handle    Handle
}

type wrappedUnpreparedStatement struct {
	query  string
	handle Handle
}

var (
	_ handle.Statement = wrappedPreparedStatement{}
	_ handle.Statement = wrappedUnpreparedStatement{}
)

// Close implements the [handle.Statement] interface.
func (s wrappedPreparedStatement) Close() error {
	return deallocate(s.ctx, s.handle, s.statement)
}

// Close implements the [handle.Statement] interface.
func (s wrappedUnpreparedStatement) Close() error {
	return nil
}

// Exec implements the [handle.Statement] interface.
func (s wrappedPreparedStatement) Exec(ctx context.Context, args []any) (sql.Result, error) {
	result, err := s.handle.Exec(ctx, s.statement.Name, args...)
	return wrappedResult{result}, err
}

// Exec implements the [handle.Statement] interface.
func (s wrappedUnpreparedStatement) Exec(ctx context.Context, args []any) (sql.Result, error) {
	result, err := s.handle.Exec(ctx, s.query, args...)
	return wrappedResult{result}, err
}

// QueryRow implements the [handle.Statement] interface.
func (s wrappedPreparedStatement) QueryRow(ctx context.Context, args, slots []any) error {
	return s.handle.QueryRow(ctx, s.statement.Name, args...).Scan(slots...)
}

// QueryRow implements the [handle.Statement] interface.
func (s wrappedUnpreparedStatement) QueryRow(ctx context.Context, args, slots []any) error {
	return s.handle.QueryRow(ctx, s.query, args...).Scan(slots...)
}