r3pgx

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package r3pgx provides an r3.CRUD[T, ID] driver backed by jackc/pgx, the pure Go PostgreSQL driver.

Driver: github.com/jackc/pgx/v5 Source: https://github.com/jackc/pgx

This driver uses pgx in database/sql compatibility mode (pgx/v5/stdlib), which means it works through the standard database/sql interface while still benefiting from pgx's connection handling and type support.

Supported r3 features:

  • Full CRUD (Create, Get, List, Update, Delete)
  • Filters, Sorts, Pagination via the r3 SQL dialect
  • Thread-safe default queries (SetDefaultListQuery, SetDefaultGetQuery)
  • Raw escape hatch (BaseRaw) for arbitrary SQL with $1-style placeholders

Limitations / notes:

  • No ORM layer: this driver builds raw SQL and uses reflection-based struct scanning. Model structs must use `db` struct tags (e.g. `db:"column_name,pk"`).
  • No preload support. Relations (joins, eager loading) must be done via Raw().
  • No soft-delete support. IncludeTrashed is ignored. Restore/HardDelete not available.
  • Table names are derived automatically from struct name (CamelCase -> snake_case + plural).
  • Nullable columns require pointer types (e.g. *string, *int64) in the model struct.
  • The r3 SQL dialect produces `?` placeholders; this driver converts them to PostgreSQL-style `$1, $2, ...` numbered placeholders internally.
  • Transactions are supported via the r3.Transactor interface (BeginTx).
  • For advanced use cases (CTEs, etc.), use Raw().DB to access the underlying *sql.DB directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPgxQuerier

func NewPgxQuerier[T any, ID comparable](db *sql.DB, opts ...r3.Option) r3.Querier[T, ID]

NewPgxQuerier creates a read-only pgx-based repository. Returns r3.Querier — a compile-time guarantee of read-only access.

Types

type PgxCRUD

type PgxCRUD[T any, ID comparable] struct {
	*enginesql.BaseCRUD[T, ID]
}

PgxCRUD is a CRUD repository based on database/sql with jackc/pgx (via pgx/v5/stdlib). It embeds enginesql.BaseCRUD which provides the full r3.CRUD implementation.

func NewPgxCRUD

func NewPgxCRUD[T any, ID comparable](db *sql.DB, opts ...r3.Option) *PgxCRUD[T, ID]

NewPgxCRUD creates a new pgx-based CRUD repository. Models should use `db:"column_name"` struct tags for column mapping. The primary key field should be tagged with `db:"id,pk"` (defaults to "id").

Accepts optional r3.Option values for framework-level configuration.

func (*PgxCRUD[T, ID]) DB

func (r *PgxCRUD[T, ID]) DB() *sql.DB

DB returns the underlying *sql.DB for advanced usage.

func (*PgxCRUD[T, ID]) Raw

func (r *PgxCRUD[T, ID]) Raw() *enginesql.BaseRaw[T, ID]

Raw returns the BaseRaw escape hatch for custom queries.

type PgxRaw deprecated

type PgxRaw[T any, ID any] struct {
	*enginesql.BaseRaw[T, ID]
}

PgxRaw is a thin wrapper around enginesql.BaseRaw for backward compatibility. It provides the same Query/QueryRow/Exec methods.

Deprecated: Use enginesql.BaseRaw directly via PgxCRUD.Raw().

func NewPgxRaw

func NewPgxRaw[T any, ID comparable](db *sql.DB) *PgxRaw[T, ID]

NewPgxRaw creates a new PgxRaw instance.

func (*PgxRaw[T, ID]) DB

func (r *PgxRaw[T, ID]) DB() *sql.DB

DB returns the underlying *sql.DB for fully custom usage.

func (*PgxRaw[T, ID]) Exec

func (r *PgxRaw[T, ID]) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

Exec executes a raw SQL query that does not return rows (INSERT, UPDATE, DELETE).

func (*PgxRaw[T, ID]) Query

func (r *PgxRaw[T, ID]) Query(ctx context.Context, query string, args ...any) ([]T, error)

Query executes a raw SQL query and scans results into a slice of T. The query should use $1, $2, ... PostgreSQL-style placeholders.

func (*PgxRaw[T, ID]) QueryRow

func (r *PgxRaw[T, ID]) QueryRow(ctx context.Context, query string, args ...any) (T, error)

QueryRow executes a raw SQL query expected to return a single row and scans it into T.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL