Documentation
¶
Index ¶
- type BaseEntity
- type BaseRepository
- func (r *BaseRepository[T]) Create(ctx context.Context, entity T) error
- func (r *BaseRepository[T]) Delete(ctx context.Context, id string) error
- func (r *BaseRepository[T]) Exists(ctx context.Context, id string) (bool, error)
- func (r *BaseRepository[T]) FindAll(ctx context.Context, offset, limit int) ([]T, int64, error)
- func (r *BaseRepository[T]) FindByCondition(ctx context.Context, condition string, args ...interface{}) ([]T, error)
- func (r *BaseRepository[T]) FindByID(ctx context.Context, id string) (T, error)
- func (r *BaseRepository[T]) GetDB() *gorm.DB
- func (r *BaseRepository[T]) Transaction(ctx context.Context, fn func(*gorm.DB) error) error
- func (r *BaseRepository[T]) Update(ctx context.Context, entity T) error
- type Entity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseEntity ¶
type BaseEntity struct { ID string `json:"id" gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` }
BaseEntity proporciona campos comunes para todas las entidades
func (*BaseEntity) GetCreatedAt ¶
func (e *BaseEntity) GetCreatedAt() time.Time
func (*BaseEntity) GetID ¶
func (e *BaseEntity) GetID() string
func (*BaseEntity) GetUpdatedAt ¶
func (e *BaseEntity) GetUpdatedAt() time.Time
func (*BaseEntity) SetCreatedAt ¶
func (e *BaseEntity) SetCreatedAt(t time.Time)
func (*BaseEntity) SetID ¶
func (e *BaseEntity) SetID(id string)
func (*BaseEntity) SetUpdatedAt ¶
func (e *BaseEntity) SetUpdatedAt(t time.Time)
type BaseRepository ¶
type BaseRepository[T Entity] struct { // contains filtered or unexported fields }
BaseRepository proporciona operaciones CRUD comunes
func NewBaseRepository ¶
func NewBaseRepository[T Entity](db *gorm.DB, serviceName string) *BaseRepository[T]
NewBaseRepository crea una nueva instancia del repositorio base
func (*BaseRepository[T]) Create ¶
func (r *BaseRepository[T]) Create(ctx context.Context, entity T) error
Create crea una nueva entidad
func (*BaseRepository[T]) Delete ¶
func (r *BaseRepository[T]) Delete(ctx context.Context, id string) error
Delete elimina una entidad por ID
func (*BaseRepository[T]) FindByCondition ¶
func (r *BaseRepository[T]) FindByCondition(ctx context.Context, condition string, args ...interface{}) ([]T, error)
FindByCondition busca entidades que cumplan una condición
func (*BaseRepository[T]) FindByID ¶
func (r *BaseRepository[T]) FindByID(ctx context.Context, id string) (T, error)
FindByID busca una entidad por ID
func (*BaseRepository[T]) GetDB ¶
func (r *BaseRepository[T]) GetDB() *gorm.DB
GetDB retorna la instancia de GORM para queries personalizadas
func (*BaseRepository[T]) Transaction ¶
Transaction ejecuta operaciones dentro de una transacción
Click to show internal directories.
Click to hide internal directories.