Documentation
¶
Overview ¶
Package r3pq provides an r3.CRUD[T, ID] driver backed by lib/pq, the pure Go PostgreSQL driver for database/sql.
Driver: github.com/lib/pq Source: https://github.com/lib/pq
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 ¶
- func NewPqQuerier[T any, ID comparable](db *sql.DB, opts ...r3.Option) r3.Querier[T, ID]
- type PqCRUD
- type PqRawdeprecated
- func (r *PqRaw[T, ID]) DB() *sql.DB
- func (r *PqRaw[T, ID]) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (r *PqRaw[T, ID]) Query(ctx context.Context, query string, args ...any) ([]T, error)
- func (r *PqRaw[T, ID]) QueryRow(ctx context.Context, query string, args ...any) (T, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPqQuerier ¶
NewPqQuerier creates a read-only pq-based repository. Returns r3.Querier — a compile-time guarantee of read-only access.
Types ¶
type PqCRUD ¶
type PqCRUD[T any, ID comparable] struct { *enginesql.BaseCRUD[T, ID] }
PqCRUD is a CRUD repository based on database/sql with lib/pq. It embeds enginesql.BaseCRUD which provides the full r3.CRUD implementation.
func NewPqCRUD ¶
NewPqCRUD creates a new database/sql-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.
type PqRaw
deprecated
PqRaw is a thin wrapper around enginesql.BaseRaw for backward compatibility.
Deprecated: Use enginesql.BaseRaw directly via PqCRUD.Raw().
func NewPqRaw ¶
func NewPqRaw[T any, ID comparable](db *sql.DB) *PqRaw[T, ID]
NewPqRaw creates a new PqRaw instance.