Documentation ¶
Index ¶
- type CrudRepository
- func (c *CrudRepository[ID, ENTITY]) Count(ctx context.Context) (count int, err error)
- func (c *CrudRepository[ID, ENTITY]) CountByFilter(ctx context.Context, filter map[string]any) (count int, err error)
- func (c *CrudRepository[ID, ENTITY]) Create(ctx context.Context, entity ENTITY) (id ID, err error)
- func (c *CrudRepository[ID, ENTITY]) Delete(ctx context.Context, filter map[string]any) (err error)
- func (c *CrudRepository[ID, ENTITY]) DeleteAll(ctx context.Context) (err error)
- func (c *CrudRepository[ID, ENTITY]) DeleteByID(ctx context.Context, id ID) (err error)
- func (c *CrudRepository[ID, ENTITY]) DeleteByIDs(ctx context.Context, ids []ID) (err error)
- func (c *CrudRepository[ID, ENTITY]) Exists(ctx context.Context, filter map[string]any) (exists bool, err error)
- func (c *CrudRepository[ID, ENTITY]) ExistsByID(ctx context.Context, id ID) (exists bool, err error)
- func (c *CrudRepository[ID, ENTITY]) ExistsByIDs(ctx context.Context, ids []ID) (exists contract.Dict[ID, bool], err error)
- func (c *CrudRepository[ID, ENTITY]) FindAll(ctx context.Context) (collection contract.Collection[ID, ENTITY], err error)
- func (c *CrudRepository[ID, ENTITY]) FindByFilter(ctx context.Context, filter map[string]any) (collection contract.Collection[ID, ENTITY], err error)
- func (c *CrudRepository[ID, ENTITY]) FindByFilterWithPage(ctx context.Context, filter map[string]any, limit, offset int, ...) (collection contract.Collection[ID, ENTITY], err error)
- func (c *CrudRepository[ID, ENTITY]) FindByID(ctx context.Context, id ID) (entity ENTITY, err error)
- func (c *CrudRepository[ID, ENTITY]) FindByIDs(ctx context.Context, ids []ID) (collection contract.Collection[ID, ENTITY], err error)
- func (c *CrudRepository[ID, ENTITY]) FindByPage(ctx context.Context, limit, offset int, orders ...contract.Order) (collection contract.Collection[ID, ENTITY], err error)
- func (c *CrudRepository[ID, ENTITY]) IDField() string
- func (c *CrudRepository[ID, ENTITY]) IsUnscoped() bool
- func (c *CrudRepository[ID, ENTITY]) SoftDeleteEnabled() bool
- func (c *CrudRepository[ID, ENTITY]) SoftDeleteField() string
- func (c *CrudRepository[ID, ENTITY]) Unscoped() contract.CrudRepository[ID, ENTITY]
- func (c *CrudRepository[ID, ENTITY]) Update(ctx context.Context, filter map[string]any, data map[string]any) (err error)
- func (c *CrudRepository[ID, ENTITY]) UpdateByID(ctx context.Context, id ID, data map[string]any) (err error)
- func (c *CrudRepository[ID, ENTITY]) UpdateNonZero(ctx context.Context, filter map[string]any, entity ENTITY) (err error)
- func (c *CrudRepository[ID, ENTITY]) UpdateNonZeroByID(ctx context.Context, id ID, entity ENTITY) (err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CrudRepository ¶
type CrudRepository[ID comparable, ENTITY contract.ENTITY[ID]] struct { // contains filtered or unexported fields }
Example ¶
defer errors.Recover(func(e error) { log.Fatalf("%+v", e) }) var ctx = context.Background() var db *gorm.DB userRepository := NewUserRepository(db) id, err := userRepository.Create(ctx, &User{ ID: idGen.Generate(), Name: "test", }) errors.Check(err) user, err := userRepository.FindByID(ctx, id) if errors.Is(err, repository.ErrNotFound) { // TODO: handle not found return } errors.Check(err) _ = user
Output:
func NewCrudRepository ¶
func NewCrudRepository[ID comparable, ENTITY contract.ENTITY[ID]](db *gorm.DB) *CrudRepository[ID, ENTITY]
func (*CrudRepository[ID, ENTITY]) Count ¶
func (c *CrudRepository[ID, ENTITY]) Count(ctx context.Context) (count int, err error)
func (*CrudRepository[ID, ENTITY]) CountByFilter ¶
func (*CrudRepository[ID, ENTITY]) Create ¶
func (c *CrudRepository[ID, ENTITY]) Create(ctx context.Context, entity ENTITY) (id ID, err error)
func (*CrudRepository[ID, ENTITY]) DeleteAll ¶
func (c *CrudRepository[ID, ENTITY]) DeleteAll(ctx context.Context) (err error)
func (*CrudRepository[ID, ENTITY]) DeleteByID ¶
func (c *CrudRepository[ID, ENTITY]) DeleteByID(ctx context.Context, id ID) (err error)
func (*CrudRepository[ID, ENTITY]) DeleteByIDs ¶
func (c *CrudRepository[ID, ENTITY]) DeleteByIDs(ctx context.Context, ids []ID) (err error)
func (*CrudRepository[ID, ENTITY]) ExistsByID ¶
func (c *CrudRepository[ID, ENTITY]) ExistsByID(ctx context.Context, id ID) (exists bool, err error)
func (*CrudRepository[ID, ENTITY]) ExistsByIDs ¶
func (*CrudRepository[ID, ENTITY]) FindAll ¶
func (c *CrudRepository[ID, ENTITY]) FindAll(ctx context.Context) (collection contract.Collection[ID, ENTITY], err error)
func (*CrudRepository[ID, ENTITY]) FindByFilter ¶
func (c *CrudRepository[ID, ENTITY]) FindByFilter(ctx context.Context, filter map[string]any) (collection contract.Collection[ID, ENTITY], err error)
func (*CrudRepository[ID, ENTITY]) FindByFilterWithPage ¶
func (*CrudRepository[ID, ENTITY]) FindByID ¶
func (c *CrudRepository[ID, ENTITY]) FindByID(ctx context.Context, id ID) (entity ENTITY, err error)
func (*CrudRepository[ID, ENTITY]) FindByIDs ¶
func (c *CrudRepository[ID, ENTITY]) FindByIDs(ctx context.Context, ids []ID) (collection contract.Collection[ID, ENTITY], err error)
func (*CrudRepository[ID, ENTITY]) FindByPage ¶
func (c *CrudRepository[ID, ENTITY]) FindByPage(ctx context.Context, limit, offset int, orders ...contract.Order) (collection contract.Collection[ID, ENTITY], err error)
func (*CrudRepository[ID, ENTITY]) IDField ¶
func (c *CrudRepository[ID, ENTITY]) IDField() string
func (*CrudRepository[ID, ENTITY]) IsUnscoped ¶
func (c *CrudRepository[ID, ENTITY]) IsUnscoped() bool
func (*CrudRepository[ID, ENTITY]) SoftDeleteEnabled ¶
func (c *CrudRepository[ID, ENTITY]) SoftDeleteEnabled() bool
func (*CrudRepository[ID, ENTITY]) SoftDeleteField ¶
func (c *CrudRepository[ID, ENTITY]) SoftDeleteField() string
func (*CrudRepository[ID, ENTITY]) Unscoped ¶
func (c *CrudRepository[ID, ENTITY]) Unscoped() contract.CrudRepository[ID, ENTITY]
func (*CrudRepository[ID, ENTITY]) UpdateByID ¶
func (*CrudRepository[ID, ENTITY]) UpdateNonZero ¶
func (*CrudRepository[ID, ENTITY]) UpdateNonZeroByID ¶
func (c *CrudRepository[ID, ENTITY]) UpdateNonZeroByID(ctx context.Context, id ID, entity ENTITY) (err error)
Click to show internal directories.
Click to hide internal directories.