diff options
Diffstat (limited to 'benchmark/internal/oblast_pgx')
| -rw-r--r-- | benchmark/internal/oblast_pgx/handle.go | 89 | ||||
| -rw-r--r-- | benchmark/internal/oblast_pgx/results.go | 66 | ||||
| -rw-r--r-- | benchmark/internal/oblast_pgx/statement.go | 60 |
3 files changed, 0 insertions, 215 deletions
diff --git a/benchmark/internal/oblast_pgx/handle.go b/benchmark/internal/oblast_pgx/handle.go deleted file mode 100644 index 4bd72bd..0000000 --- a/benchmark/internal/oblast_pgx/handle.go +++ /dev/null @@ -1,89 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net> -// SPDX-License-Identifier: Apache-2.0 - -package oblast_pgx - -import ( - "context" - "fmt" - "strconv" - "sync/atomic" - - "github.com/jackc/pgx/v5" - "github.com/jackc/pgx/v5/pgconn" - "github.com/jackc/pgx/v5/pgxpool" - "go.xyrillian.de/gg/gsql" -) - -type Handle interface { - Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error) - Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error) - QueryRow(ctx context.Context, sql string, args ...any) pgx.Row -} - -var ( - _ Handle = &pgx.Conn{} - _ Handle = &pgxpool.Conn{} - _ Handle = pgx.Tx(&pgxpool.Tx{}) -) - -func Wrap(h Handle) gsql.Handle { - switch h := h.(type) { - case *pgx.Conn: - return wrappedHandle{h} - case *pgxpool.Conn: - return wrappedHandle{h} - case pgx.Tx: - return wrappedHandle{h} - default: - panic(fmt.Sprintf("unexpected type: %#v", h)) - } -} - -var preparedStatementId atomic.Uint64 - -type wrappedHandle struct { - inner Handle -} - -// GSQLPrepare implements the [gsql.Handle] interface. -func (h wrappedHandle) GSQLPrepare(ctx context.Context, query string, repeated bool) (gsql.Statement, error) { - if !repeated { - return wrappedUnpreparedStatement{query, h.inner}, nil - } - - name := "oblast_pgx_" + strconv.FormatUint(preparedStatementId.Add(1), 10) - switch inner := h.inner.(type) { - case *pgx.Conn: - stmt, err := inner.Prepare(ctx, name, query) - return wrappedPreparedStatement{ctx, stmt, h.inner}, err - case *pgxpool.Conn: - // pgxpool.Conn does not have Prepare() - return wrappedUnpreparedStatement{query, h.inner}, nil - case pgx.Tx: - stmt, err := inner.Conn().Prepare(ctx, name, query) - return wrappedPreparedStatement{ctx, stmt, h.inner}, err - default: - panic("unreachable") // because of the check in func Wrap() - } -} - -// Releases a prepared statement. -func deallocate(ctx context.Context, h Handle, stmt *pgconn.StatementDescription) error { - switch h := h.(type) { - case *pgx.Conn: - return h.Deallocate(ctx, stmt.Name) - case *pgxpool.Conn: - panic("unreachable") // because func GSQLPrepare() does not return a wrappedPreparedStatement for this underlying type - case pgx.Tx: - return h.Conn().Deallocate(ctx, stmt.Name) - default: - panic("unreachable") // because of the check in func Wrap() - } -} - -// GSQLQuery implements the [gsql.Handle] interface. -func (h wrappedHandle) GSQLQuery(ctx context.Context, query string, args []any) (gsql.Rows, error) { - rows, err := h.inner.Query(ctx, query, args...) - return wrappedRows{rows}, err -} diff --git a/benchmark/internal/oblast_pgx/results.go b/benchmark/internal/oblast_pgx/results.go deleted file mode 100644 index f842d36..0000000 --- a/benchmark/internal/oblast_pgx/results.go +++ /dev/null @@ -1,66 +0,0 @@ -// 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/gg/gsql" -) - -type wrappedRows struct { - inner pgx.Rows -} - -var _ gsql.Rows = wrappedRows{} - -// Columns implements the [gsql.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 [gsql.Rows] interface. -func (r wrappedRows) Close() error { - r.inner.Close() - return nil -} - -// Err implements the [gsql.Rows] interface. -func (r wrappedRows) Err() error { - return r.inner.Err() -} - -// Next implements the [gsql.Rows] interface. -func (r wrappedRows) Next() bool { - return r.inner.Next() -} - -// Scan implements the [gsql.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 -} diff --git a/benchmark/internal/oblast_pgx/statement.go b/benchmark/internal/oblast_pgx/statement.go deleted file mode 100644 index 0a33c73..0000000 --- a/benchmark/internal/oblast_pgx/statement.go +++ /dev/null @@ -1,60 +0,0 @@ -// 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/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 [gsql.Statement] interface. -func (s wrappedPreparedStatement) Close() error { - return deallocate(s.ctx, s.handle, s.statement) -} - -// Close implements the [gsql.Statement] interface. -func (s wrappedUnpreparedStatement) Close() error { - return nil -} - -// Exec implements the [gsql.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 [gsql.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 [gsql.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 [gsql.Statement] interface. -func (s wrappedUnpreparedStatement) QueryRow(ctx context.Context, args, slots []any) error { - return s.handle.QueryRow(ctx, s.query, args...).Scan(slots...) -} |
