Documentation
¶
Overview ¶
Package r3gopg is an r3.CRUD[T, ID] driver backed by go-pg v10 (github.com/go-pg/pg/v10), a PostgreSQL ORM. It maps preloads onto go-pg's Relation(), IncludeTrashed onto AllWithDeleted() (needs a pg:",soft_delete" tag), and exposes Restore/HardDelete. Map fields with `pg` tags.
Notes:
- go-pg is in maintenance mode; the authors recommend Bun (see https://github.com/go-pg/pg#bun).
- go-pg does NOT wrap database/sql; it owns its pool (*pg.DB). For a *sql.DB (e.g. goose migrations), open a separate connection.
- For aggregate / custom-shape rows use Raw().Scan() into a dedicated struct; Raw().Find() scans into []T and go-pg rejects unknown columns.
Index ¶
- func NewGoPgQuerier[T any, ID comparable](db *pg.DB, opts ...r3.Option) r3.Querier[T, ID]
- type GoPgCRUD
- func (r *GoPgCRUD[T, ID]) Aggregate(ctx context.Context, qarg ...r3.Query) ([]r3.AggregateRow, error)
- func (r *GoPgCRUD[T, ID]) BeginTx(ctx context.Context) (r3.TxCRUD[T, ID], error)
- func (r *GoPgCRUD[T, ID]) Count(ctx context.Context, qarg ...r3.Query) (int64, error)
- func (r *GoPgCRUD[T, ID]) Create(ctx context.Context, entity T) (T, error)
- func (r *GoPgCRUD[T, ID]) Delete(ctx context.Context, id ID) error
- func (r *GoPgCRUD[T, ID]) Get(ctx context.Context, id ID, qarg ...r3.Query) (T, error)
- func (r *GoPgCRUD[T, ID]) HardDelete(ctx context.Context, id ID) error
- func (r *GoPgCRUD[T, ID]) List(ctx context.Context, qarg ...r3.Query) ([]T, int64, error)
- func (r *GoPgCRUD[T, ID]) Patch(ctx context.Context, entity T, fields r3.Fields) (T, error)
- func (r *GoPgCRUD[T, ID]) PgDB() *pg.DB
- func (r *GoPgCRUD[T, ID]) Raw() *GoPgRaw[T, ID]
- func (r *GoPgCRUD[T, ID]) Restore(ctx context.Context, id ID) error
- func (r *GoPgCRUD[T, ID]) Update(ctx context.Context, entity T) (T, error)
- type GoPgRaw
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGoPgQuerier ¶
NewGoPgQuerier builds a read-only go-pg repository (r3.Querier enforces it).
Types ¶
type GoPgCRUD ¶
type GoPgCRUD[T any, ID comparable] struct { enginesql.DefaultsManager Config r3.Config // contains filtered or unexported fields }
GoPgCRUD is a go-pg repository. It holds orm.DB (not *pg.DB) so the same code runs against a transaction.
func NewGoPgCRUD ¶
NewGoPgCRUD builds a go-pg-based repository.
func (*GoPgCRUD[T, ID]) Aggregate ¶ added in v0.0.3
func (r *GoPgCRUD[T, ID]) Aggregate(ctx context.Context, qarg ...r3.Query) ([]r3.AggregateRow, error)
Aggregate computes grouped aggregates over the records matching the query. See r3.Aggregator for the query semantics.
func (*GoPgCRUD[T, ID]) BeginTx ¶
BeginTx starts a go-pg transaction and returns an r3.TxCRUD scoped to it. The caller must call Commit or Rollback on the returned TxCRUD.
func (*GoPgCRUD[T, ID]) HardDelete ¶
HardDelete permanently removes a record, bypassing go-pg's soft-delete.
func (*GoPgCRUD[T, ID]) PgDB ¶
PgDB returns the underlying *pg.DB for advanced usage. Panics if GoPgCRUD is operating inside a transaction.
type GoPgRaw ¶
GoPgRaw is the go-pg escape hatch, exposing any go-pg query via Find/Scan callbacks.
func NewGoPgRaw ¶
func NewGoPgRaw[T any, ID comparable](db orm.DB) *GoPgRaw[T, ID]
NewGoPgRaw creates a new GoPgRaw instance.