r3pgx

package
v0.1.5 Latest Latest
Warning

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

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

Documentation

Overview

Package r3pgx is a raw-SQL r3.CRUD[T, ID] driver backed by jackc/pgx (github.com/jackc/pgx/v5) in database/sql compatibility mode (pgx/v5/stdlib), so it runs through database/sql while keeping pgx's connection and type support.

It builds SQL by reflection and scans into structs tagged `db:"col,pk"`; no ORM, so no preloads and no soft-delete (IncludeTrashed, Restore, HardDelete are unavailable). Table names derive from the struct name (CamelCase -> snake_case, pluralized); nullable columns need pointer fields. The r3 SQL dialect emits `?` placeholders, converted to Postgres `$1, $2, ...` internally. Transactions via r3.Transactor; reach the *sql.DB through Raw().DB for CTEs and the like.

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 builds a read-only repository (r3.Querier enforces it).

Types

type PgxCRUD

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

PgxCRUD is a pgx repository (via pgx/v5/stdlib); enginesql.BaseCRUD supplies the r3.CRUD impl.

func NewPgxCRUD

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

NewPgxCRUD builds a repository. Map columns with `db:"column_name"` and mark the PK with `db:"id,pk"` (defaults to "id").

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 wraps enginesql.BaseRaw.

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