r3gorm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGormQuerier

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

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

func NewGormCRUD[T any, ID comparable](db *gorm.DB, opts ...r3.Option) *GormCRUD[T, ID]

NewGormCRUD creates a new GORM-based CRUD repository.

Accepts optional r3.Option values for framework-level configuration.

func (*GormCRUD[T, ID]) BeginTx

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

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

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

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

func (*GormCRUD[T, ID]) Create

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

func (*GormCRUD[T, ID]) DB

func (r *GormCRUD[T, ID]) DB() *gorm.DB

DB returns the underlying *gorm.DB for advanced usage.

func (*GormCRUD[T, ID]) Delete

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

func (*GormCRUD[T, ID]) Get

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

func (*GormCRUD[T, ID]) HardDelete

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

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

func (*GormCRUD[T, ID]) List

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

func (*GormCRUD[T, ID]) Patch

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

func (*GormCRUD[T, ID]) Raw

func (r *GormCRUD[T, ID]) Raw() *GormRaw[T, ID]

Raw returns the GormRaw escape hatch for custom queries.

func (*GormCRUD[T, ID]) Restore

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

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

func (*GormCRUD[T, ID]) Update

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

type GormRaw

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

GormRaw is a gorm wrapper that allows call any gorm request. Is considered to be embedded in GormCRUD.

func NewGormRaw

func NewGormRaw[T any, ID comparable](db *gorm.DB) *GormRaw[T, ID]

func (*GormRaw[T, ID]) Find

func (r *GormRaw[T, ID]) Find(ctx context.Context, cb func(*gorm.DB) *gorm.DB) ([]T, error)

func (*GormRaw[T, ID]) Scan

func (r *GormRaw[T, ID]) Scan(ctx context.Context, cb func(*gorm.DB) *gorm.DB, dest any) error

Jump to

Keyboard shortcuts

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