data

package
v0.0.0-...-0dc4125 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FetchEagerMode = "eager"
	FetchLazyMode  = "lazy"
)

Variables

View Source
var NotFoundError = errors.New("not found")

Functions

func LazyLoadNow

func LazyLoadNow[T any](name string, lazyLoader LazyLoadable) (T, error)

func NewDummyTransactionManager

func NewDummyTransactionManager() *dummyTransactionManager

Types

type Association

type Association struct {
	Name        string
	PtrToEntity any
	ID          any
	ForeignKey  string
	Type        AssociationType
	FetchMode   FetchMode
}

type AssociationType

type AssociationType int
const (
	BelongTo AssociationType = iota + 1
	HasOne
	HasMany
	ManyToMany
)

type DTO

type DTO[M any] interface {
	To() M
	From(m M) any
}

type DtoWrapFindByRepository

type DtoWrapFindByRepository[D DTO[M], M any, E DTO[S], S any] struct {
	// contains filtered or unexported fields
}

func NewDtoWrapFindByRepository

func NewDtoWrapFindByRepository[D DTO[M], M any, E DTO[S], S any](dtoRepository FindByRepository[D, E]) *DtoWrapFindByRepository[D, M, E, S]

func (*DtoWrapFindByRepository[D, M, E, S]) FindBy

func (d *DtoWrapFindByRepository[D, M, E, S]) FindBy(ctx context.Context, name string, byEntity S) ([]M, error)

type DtoWrapRepository

type DtoWrapRepository[D DTO[M], M any, ID comparable] struct {
	// contains filtered or unexported fields
}

func NewDtoWrapRepository

func NewDtoWrapRepository[D DTO[M], M any, ID comparable](dtoRepository Repository[D, ID]) *DtoWrapRepository[D, M, ID]

func (*DtoWrapRepository[D, M, ID]) Create

func (d *DtoWrapRepository[D, M, ID]) Create(ctx context.Context, entity M) (M, error)

func (*DtoWrapRepository[D, M, ID]) Delete

func (d *DtoWrapRepository[D, M, ID]) Delete(ctx context.Context, entity M) error

func (*DtoWrapRepository[D, M, ID]) FindOne

func (d *DtoWrapRepository[D, M, ID]) FindOne(ctx context.Context, id ID) (M, error)

func (*DtoWrapRepository[D, M, ID]) Update

func (d *DtoWrapRepository[D, M, ID]) Update(ctx context.Context, entity M) (M, error)

type FetchMode

type FetchMode string

func ToFetchMode

func ToFetchMode(m string) FetchMode

type FindByRepository

type FindByRepository[T any, S any] interface {
	FindBy(ctx context.Context, name string, byEntity S) ([]T, error)
}

type GormFindByRepository

type GormFindByRepository[T any, S any, ID comparable] struct {
	*GormRepository[T, ID]
}

func NewGormFindByRepository

func NewGormFindByRepository[T any, S any, ID comparable](gormRepository *GormRepository[T, ID]) *GormFindByRepository[T, S, ID]

func (*GormFindByRepository[T, S, ID]) FindBy

func (u *GormFindByRepository[T, S, ID]) FindBy(ctx context.Context, name string, byEntity S) ([]T, error)

type GormRepository

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

func NewGormRepository

func NewGormRepository[T any, ID comparable](transactionManager TransactionManager) *GormRepository[T, ID]

func (*GormRepository[T, ID]) Create

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

func (*GormRepository[T, ID]) Delete

func (u *GormRepository[T, ID]) Delete(ctx context.Context, entity T) error

func (*GormRepository[T, ID]) FindBy

func (u *GormRepository[T, ID]) FindBy(ctx context.Context, name string, byEntity any) ([]T, error)

func (*GormRepository[T, ID]) FindOne

func (u *GormRepository[T, ID]) FindOne(ctx context.Context, id ID) (T, error)

func (*GormRepository[T, ID]) GetLazyLoadFuncOfBelongTo

func (u *GormRepository[T, ID]) GetLazyLoadFuncOfBelongTo(ctx context.Context, ptrToEntity any, id any) func() (any, error)

GetLazyLoadFuncOfBelongTo returns entity returning function

func (*GormRepository[T, ID]) GetLazyLoadFuncOfHasMany

func (u *GormRepository[T, ID]) GetLazyLoadFuncOfHasMany(ctx context.Context, ptrToEntity any, foreignKey string, foreignKeyValue any) func() (any, error)

GetLazyLoadFuncOfHasMany returns slice of entity returning function

func (*GormRepository[T, ID]) GetLazyLoadFuncOfHasOne

func (u *GormRepository[T, ID]) GetLazyLoadFuncOfHasOne(ctx context.Context, ptrToEntity any, foreignKey string, foreignKeyValue any) func() (any, error)

GetLazyLoadFuncOfHasOne returns entity returning function

func (*GormRepository[T, ID]) GetLazyLoadFuncOfManyMany

func (u *GormRepository[T, ID]) GetLazyLoadFuncOfManyMany(ctx context.Context, ptrToParent any, ptrToChildren any, associationName string, foreignKey string, foreignKeyValue any) func() (any, error)

GetLazyLoadFuncOfManyMany returns slice of entity returning function

func (*GormRepository[T, ID]) Update

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

type GormTransactionManager

type GormTransactionManager struct {
	// contains filtered or unexported fields
}

func NewGormTransactionManager

func NewGormTransactionManager(db *gorm.DB) *GormTransactionManager

func (*GormTransactionManager) Do

func (*GormTransactionManager) Get

type InMemoryRepository

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

func NewInMemoryRepository

func NewInMemoryRepository[T any, ID comparable](transactionManager TransactionManager) *InMemoryRepository[T, ID]

func (*InMemoryRepository[T, ID]) Create

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

func (*InMemoryRepository[T, ID]) Delete

func (u *InMemoryRepository[T, ID]) Delete(ctx context.Context, entity T) error

func (*InMemoryRepository[T, ID]) FindBy

func (u *InMemoryRepository[T, ID]) FindBy(ctx context.Context, name string, byEntity any) ([]T, error)

func (*InMemoryRepository[T, ID]) FindOne

func (u *InMemoryRepository[T, ID]) FindOne(ctx context.Context, id ID) (T, error)

func (*InMemoryRepository[T, ID]) Update

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

type Lazy

type Lazy[T any] interface {
	Get() T
}

type LazyLoad

type LazyLoad[T any] struct {
	// contains filtered or unexported fields
}

func LazyLoadFn

func LazyLoadFn[T any](load func() (any, error)) *LazyLoad[T]

func LazyLoadValue

func LazyLoadValue[T any](v T) *LazyLoad[T]

func (*LazyLoad[T]) Get

func (l *LazyLoad[T]) Get() T

type LazyLoadable

type LazyLoadable interface {
	NewInstance()
	SetLoadFunc(name string, fn func() (any, error))
	HasLoadFunc(name string) bool
	DeleteLoadFunc(name string)
	Load(name string, emptyEntity any) (any, error) // Load returns entity
	Entities() []string
}

type LazyLoader

type LazyLoader struct {
	// contains filtered or unexported fields
}

func (*LazyLoader) DeleteLoadFunc

func (l *LazyLoader) DeleteLoadFunc(entity string)

func (*LazyLoader) Entities

func (l *LazyLoader) Entities() []string

func (*LazyLoader) HasLoadFunc

func (l *LazyLoader) HasLoadFunc(entity string) bool

func (*LazyLoader) Load

func (l *LazyLoader) Load(name string, emptyEntity any) (any, error)

func (*LazyLoader) NewInstance

func (l *LazyLoader) NewInstance()

func (*LazyLoader) SetLoadFunc

func (l *LazyLoader) SetLoadFunc(entity string, fn func() (any, error))

type Repository

type Repository[T any, ID comparable] interface {
	FindOne(ctx context.Context, id ID) (T, error)
	Create(ctx context.Context, entity T) (T, error)
	Update(ctx context.Context, entity T) (T, error)
	Delete(ctx context.Context, entity T) error
}

type TransactionManager

type TransactionManager interface {
	Do(ctx context.Context, f func(ctx context.Context) error) error
	Get(ctx context.Context) any
}

Jump to

Keyboard shortcuts

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