repository

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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

func (r *BaseRepository[T]) Exists(ctx context.Context, id string) (bool, error)

Exists verifica si una entidad existe por ID

func (*BaseRepository[T]) FindAll

func (r *BaseRepository[T]) FindAll(ctx context.Context, offset, limit int) ([]T, int64, error)

FindAll obtiene todas las entidades con paginación

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

func (r *BaseRepository[T]) Transaction(ctx context.Context, fn func(*gorm.DB) error) error

Transaction ejecuta operaciones dentro de una transacción

func (*BaseRepository[T]) Update

func (r *BaseRepository[T]) Update(ctx context.Context, entity T) error

Update actualiza una entidad existente

type Entity

type Entity interface {
	GetID() string
	SetID(id string)
	GetCreatedAt() time.Time
	GetUpdatedAt() time.Time
	SetCreatedAt(time.Time)
	SetUpdatedAt(time.Time)
	TableName() string
}

Entity interface que deben implementar todas las entidades

Jump to

Keyboard shortcuts

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