repository

package
v0.0.0-...-d364ca2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package repository provides typed PostgreSQL persistence for Soro models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock func() time.Time

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 WithClock

func WithClock(clock Clock) Option

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

func (r *Repository[T]) All(ctx context.Context) ([]*T, error)

func (*Repository[T]) Count

func (r *Repository[T]) Count(ctx context.Context) (int, error)

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

func (r *Repository[T]) Exists(ctx context.Context, id uuid.UUID) (bool, error)

func (*Repository[T]) Find

func (r *Repository[T]) Find(ctx context.Context, id uuid.UUID) (*T, error)

func (*Repository[T]) FindBy

func (r *Repository[T]) FindBy(ctx context.Context, field string, value any) (*T, error)

func (*Repository[T]) First

func (r *Repository[T]) First(ctx context.Context) (*T, 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

type UUIDGenerator func() (uuid.UUID, error)

Jump to

Keyboard shortcuts

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