r3gopg

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGoPgQuerier

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

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

func NewGoPgCRUD[T any, ID comparable](db *pg.DB, opts ...r3.Option) *GoPgCRUD[T, ID]

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

func (r *GoPgCRUD[T, ID]) BeginTx(ctx context.Context) (r3.TxCRUD[T, ID], error)

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]) Count

func (r *GoPgCRUD[T, ID]) Count(ctx context.Context, qarg ...r3.Query) (int64, error)

Count returns the number of records matching the query's filters.

func (*GoPgCRUD[T, ID]) Create

func (r *GoPgCRUD[T, ID]) Create(ctx context.Context, entity T) (T, error)

func (*GoPgCRUD[T, ID]) Delete

func (r *GoPgCRUD[T, ID]) Delete(ctx context.Context, id ID) error

func (*GoPgCRUD[T, ID]) Get

func (r *GoPgCRUD[T, ID]) Get(ctx context.Context, id ID, qarg ...r3.Query) (T, error)

func (*GoPgCRUD[T, ID]) HardDelete

func (r *GoPgCRUD[T, ID]) HardDelete(ctx context.Context, id ID) error

HardDelete permanently removes a record, bypassing go-pg's soft-delete.

func (*GoPgCRUD[T, ID]) List

func (r *GoPgCRUD[T, ID]) List(ctx context.Context, qarg ...r3.Query) ([]T, int64, error)

func (*GoPgCRUD[T, ID]) Patch

func (r *GoPgCRUD[T, ID]) Patch(ctx context.Context, entity T, fields r3.Fields) (T, error)

func (*GoPgCRUD[T, ID]) PgDB

func (r *GoPgCRUD[T, ID]) PgDB() *pg.DB

PgDB returns the underlying *pg.DB for advanced usage. Panics if GoPgCRUD is operating inside a transaction.

func (*GoPgCRUD[T, ID]) Raw

func (r *GoPgCRUD[T, ID]) Raw() *GoPgRaw[T, ID]

Raw returns the GoPgRaw escape hatch for custom queries.

func (*GoPgCRUD[T, ID]) Restore

func (r *GoPgCRUD[T, ID]) Restore(ctx context.Context, id ID) error

Restore un-deletes a soft-deleted record by clearing its soft-delete column.

func (*GoPgCRUD[T, ID]) Update

func (r *GoPgCRUD[T, ID]) Update(ctx context.Context, entity T) (T, error)

Update writes the entity and returns the row as persisted.

type GoPgRaw

type GoPgRaw[T any, ID any] struct {
	// contains filtered or unexported fields
}

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.

func (*GoPgRaw[T, ID]) Find

func (r *GoPgRaw[T, ID]) Find(ctx context.Context, cb func(*orm.Query) *orm.Query) ([]T, error)

Find executes a custom query and returns the results. The callback receives a *orm.Query to build a custom query.

func (*GoPgRaw[T, ID]) Scan

func (r *GoPgRaw[T, ID]) Scan(ctx context.Context, cb func(*orm.Query) *orm.Query, dest any) error

Scan executes a custom query and scans results into the provided destination.

Jump to

Keyboard shortcuts

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