Documentation
¶
Overview ¶
Package repository provides typed PostgreSQL persistence for Soro models.
Index ¶
- type Clock
- type OperationOption
- type Option
- type Repository
- func (r *Repository[T]) All(ctx context.Context) ([]*T, error)
- func (r *Repository[T]) Count(ctx context.Context) (int, error)
- func (r *Repository[T]) Create(ctx context.Context, entity *T, options ...OperationOption) error
- func (r *Repository[T]) DB(ctx context.Context) bun.IDB
- func (r *Repository[T]) Delete(ctx context.Context, id uuid.UUID, options ...OperationOption) error
- func (r *Repository[T]) Exists(ctx context.Context, id uuid.UUID) (bool, error)
- func (r *Repository[T]) Find(ctx context.Context, id uuid.UUID) (*T, error)
- func (r *Repository[T]) FindBy(ctx context.Context, field string, value any) (*T, error)
- func (r *Repository[T]) First(ctx context.Context) (*T, error)
- func (r *Repository[T]) ForceDelete(ctx context.Context, id uuid.UUID, options ...OperationOption) error
- func (r *Repository[T]) OnlyDeleted() *Repository[T]
- func (r *Repository[T]) Query(ctx context.Context) *bun.SelectQuery
- func (r *Repository[T]) Restore(ctx context.Context, id uuid.UUID, options ...OperationOption) error
- func (r *Repository[T]) Save(ctx context.Context, entity *T, options ...OperationOption) error
- func (r *Repository[T]) Transaction(ctx context.Context, fn func(context.Context, *Repository[T]) error) error
- func (r *Repository[T]) Update(ctx context.Context, entity *T, options ...OperationOption) error
- func (r *Repository[T]) WithDeleted() *Repository[T]
- type UUIDGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OperationOption ¶
type OperationOption func(*operationSettings)
func SkipAllHooks ¶
func SkipAllHooks() OperationOption
SkipAllHooks deliberately bypasses every lifecycle hook. Validation still runs.
func SkipHooks ¶
func SkipHooks(stages ...lifecycle.Stage) OperationOption
SkipHooks deliberately bypasses only the named lifecycle stages.
func WithLifecycleMetadata ¶
func WithLifecycleMetadata(metadata map[string]any) OperationOption
WithLifecycleMetadata adds operation-local data visible to hooks.
type Option ¶
type Option func(*settings)
func WithUUIDGenerator ¶
func WithUUIDGenerator(generator UUIDGenerator) Option
type Repository ¶
type Repository[T any] struct { // contains filtered or unexported fields }
func New ¶
func New[T any](db *database.DB, options ...Option) *Repository[T]
New constructs a typed repository. An invalid model contract is reported by every operation, keeping normal construction compatible with one-value use.
func (*Repository[T]) Create ¶
func (r *Repository[T]) Create(ctx context.Context, entity *T, options ...OperationOption) error
func (*Repository[T]) DB ¶
func (r *Repository[T]) DB(ctx context.Context) bun.IDB
DB exposes the current Bun executor. It is a bun.Tx when ctx carries a Soro transaction.
func (*Repository[T]) Delete ¶
func (r *Repository[T]) Delete(ctx context.Context, id uuid.UUID, options ...OperationOption) error
func (*Repository[T]) ForceDelete ¶
func (r *Repository[T]) ForceDelete(ctx context.Context, id uuid.UUID, options ...OperationOption) error
func (*Repository[T]) OnlyDeleted ¶
func (r *Repository[T]) OnlyDeleted() *Repository[T]
func (*Repository[T]) Query ¶
func (r *Repository[T]) Query(ctx context.Context) *bun.SelectQuery
Query returns a Bun query with the repository's deletion scope applied.
func (*Repository[T]) Restore ¶
func (r *Repository[T]) Restore(ctx context.Context, id uuid.UUID, options ...OperationOption) error
func (*Repository[T]) Save ¶
func (r *Repository[T]) Save(ctx context.Context, entity *T, options ...OperationOption) error
func (*Repository[T]) Transaction ¶
func (r *Repository[T]) Transaction(ctx context.Context, fn func(context.Context, *Repository[T]) error) error
func (*Repository[T]) Update ¶
func (r *Repository[T]) Update(ctx context.Context, entity *T, options ...OperationOption) error
func (*Repository[T]) WithDeleted ¶
func (r *Repository[T]) WithDeleted() *Repository[T]
type UUIDGenerator ¶
Click to show internal directories.
Click to hide internal directories.