Documentation
¶
Overview ¶
Package r3gorm provides an r3.CRUD[T, ID] driver backed by GORM.
Driver: gorm.io/gorm Source: https://gorm.io
Supported r3 features:
- Full CRUD (Create, Get, List, Update, Patch, Delete)
- Filters, Sorts, Pagination via the r3 SQL dialect
- Preloads via GORM's Preload()
- Soft-delete via GORM's Unscoped()
- Restore and HardDelete via the features/softdelete SoftDeleter interface
- Transactions via the r3.Transactor interface
- Thread-safe default queries (SetDefaultListQuery, SetDefaultGetQuery)
- Raw escape hatch (GormRaw) for custom gorm.DB usage
Index ¶
- func NewGormQuerier[T any, ID comparable](db *gorm.DB, opts ...r3.Option) r3.Querier[T, ID]
- type GormCRUD
- func (r *GormCRUD[T, ID]) Aggregate(ctx context.Context, qarg ...r3.Query) ([]r3.AggregateRow, error)
- func (r *GormCRUD[T, ID]) BeginTx(ctx context.Context) (r3.TxCRUD[T, ID], error)
- func (r *GormCRUD[T, ID]) Count(ctx context.Context, qarg ...r3.Query) (int64, error)
- func (r *GormCRUD[T, ID]) Create(ctx context.Context, entity T) (T, error)
- func (r *GormCRUD[T, ID]) DB() *gorm.DB
- func (r *GormCRUD[T, ID]) Delete(ctx context.Context, id ID) error
- func (r *GormCRUD[T, ID]) Get(ctx context.Context, id ID, qarg ...r3.Query) (T, error)
- func (r *GormCRUD[T, ID]) HardDelete(ctx context.Context, id ID) error
- func (r *GormCRUD[T, ID]) List(ctx context.Context, qarg ...r3.Query) ([]T, int64, error)
- func (r *GormCRUD[T, ID]) Patch(ctx context.Context, entity T, fields r3.Fields) (T, error)
- func (r *GormCRUD[T, ID]) Raw() *GormRaw[T, ID]
- func (r *GormCRUD[T, ID]) Restore(ctx context.Context, id ID) error
- func (r *GormCRUD[T, ID]) Update(ctx context.Context, entity T) (T, error)
- type GormRaw
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGormQuerier ¶
NewGormQuerier creates a read-only GORM-based repository. Returns r3.Querier — a compile-time guarantee of read-only access.
Types ¶
type GormCRUD ¶
type GormCRUD[T any, ID comparable] struct { enginesql.DefaultsManager Config r3.Config // contains filtered or unexported fields }
GormCRUD is a CRUD repository based on gorm.DB.
func NewGormCRUD ¶
NewGormCRUD creates a new GORM-based CRUD repository.
Accepts optional r3.Option values for framework-level configuration.
func (*GormCRUD[T, ID]) Aggregate ¶ added in v0.0.3
func (r *GormCRUD[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 (*GormCRUD[T, ID]) BeginTx ¶
BeginTx starts a GORM transaction and returns an r3.TxCRUD scoped to it. The caller must call Commit or Rollback on the returned TxCRUD.
func (*GormCRUD[T, ID]) HardDelete ¶
HardDelete permanently removes a record, bypassing GORM's soft-delete.