aboutsummaryrefslogtreecommitdiff
path: root/statement.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-07-30 20:20:42 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-07-30 20:20:52 +0200
commit1186412d28857b9bfa14e7e3106ecd845e71fe71 (patch)
tree8e099198aa5587beb9c022c0acd269923d2fe439 /statement.go
parentb5cd5579747a459113a7e6c899fca5c6afbea066 (diff)
downloadgo-gg-pgx-1186412d28857b9bfa14e7e3106ecd845e71fe71.tar.gz
import code from oblast/benchmark/internal
Minimally edited to s/oblast/gsql/.
Diffstat (limited to 'statement.go')
-rw-r--r--statement.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/statement.go b/statement.go
new file mode 100644
index 0000000..bb95252
--- /dev/null
+++ b/statement.go
@@ -0,0 +1,60 @@
+// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
+// SPDX-License-Identifier: Apache-2.0
+
+package gg_pgx
+
+import (
+ "context"
+ "database/sql"
+
+ "github.com/jackc/pgx/v5/pgconn"
+ "go.xyrillian.de/gg/gsql"
+)
+
+type wrappedPreparedStatement struct {
+ ctx context.Context
+ statement *pgconn.StatementDescription
+ handle Handle
+}
+
+type wrappedUnpreparedStatement struct {
+ query string
+ handle Handle
+}
+
+var (
+ _ gsql.Statement = wrappedPreparedStatement{}
+ _ gsql.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...)
+}