Documentation
¶
Index ¶
- type GenericRepository
- func (r *GenericRepository[T]) Create(model *T) error
- func (r *GenericRepository[T]) Delete(id interface{}) error
- func (r *GenericRepository[T]) GetAll(scopes ...ScopeWithLog) ([]T, error)
- func (r *GenericRepository[T]) GetByID(id interface{}) (T, error)
- func (r *GenericRepository[T]) Update(model *T) error
- type Repository
- type ScopeWithLog
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GenericRepository ¶
type GenericRepository[T any] struct { // contains filtered or unexported fields }
GenericRepository is a GORM-based implementation of the Repository interface.
func NewGenericRepository ¶
NewGenericRepository creates a new GenericRepository instance using the provided GORM DB.
func (*GenericRepository[T]) Create ¶
func (r *GenericRepository[T]) Create(model *T) error
Create inserts a new model instance into the database within a transaction. It automatically sets the CreatedAt and UpdatedAt fields.
func (*GenericRepository[T]) Delete ¶
func (r *GenericRepository[T]) Delete(id interface{}) error
Delete removes a model instance identified by id within a transaction.
func (*GenericRepository[T]) GetAll ¶
func (r *GenericRepository[T]) GetAll(scopes ...ScopeWithLog) ([]T, error)
GetAll returns all model instances.
func (*GenericRepository[T]) GetByID ¶
func (r *GenericRepository[T]) GetByID(id interface{}) (T, error)
GetByID retrieves a model instance by its identifier.
func (*GenericRepository[T]) Update ¶
func (r *GenericRepository[T]) Update(model *T) error
Update modifies an existing model instance in the database within a transaction. It automatically sets the UpdatedAt field.
type Repository ¶
type Repository[T any] interface { // GetByID retrieves a model instance by its identifier. GetByID(id interface{}) (T, error) // GetAll returns all model instances that match the provided filter. // The filter is a map of field names to their expected values. GetAll(scopes ...ScopeWithLog) ([]T, error) // Create inserts a new model instance into the database. Create(model *T) error // Update modifies an existing model instance in the database. Update(model *T) error // Delete removes a model instance identified by id. Delete(id interface{}) error }
Repository is a generic interface that abstracts data storage operations for a model of type T.