Documentation ¶
Index ¶
- type Repository
- type SQL
- func (r *SQL[E, K]) Create(ctx context.Context, entity E) (E, error)
- func (r *SQL[E, K]) CreateBulk(ctx context.Context, entities []E) ([]E, error)
- func (r *SQL[E, K]) Find(ctx context.Context, ids []K) ([]E, error)
- func (r *SQL[E, K]) Get(ctx context.Context, id K) (E, error)
- func (r *SQL[E, K]) Remove(ctx context.Context, id K) (E, error)
- func (r *SQL[E, K]) RemoveBulk(ctx context.Context, ids []K) ([]E, error)
- func (r *SQL[E, K]) Update(ctx context.Context, id K, entity E) (E, error)
- func (r *SQL[E, K]) UpdateBulk(ctx context.Context, ids []K, entity E) ([]E, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Repository ¶
type Repository[E any, K comparable] interface { // Create creates an entity in a persistence layer. Create(ctx context.Context, entity E) (E, error) // CreateBulk creates a set of entities in a persistence layer. CreateBulk(ctx context.Context, entities []E) ([]E, error) // Get returns an entity from a persistence layer identified by its ID. It returns an error if the entity doesn't exist. Get(ctx context.Context, id K) (E, error) // Find returns a set of entities from a persistence layer identified by their ID. It returns // an empty slice if no records were found. Find(ctx context.Context, ids []K) ([]E, error) // Update updates an entity. Update(ctx context.Context, id K, entity E) (E, error) // UpdateBulk updates multiple entities with values of entity. UpdateBulk(ctx context.Context, ids []K, entity E) ([]E, error) // Remove removes the given id from the persistence layer. Remove(ctx context.Context, id K) (E, error) // RemoveBulk removes a set of elements from the persistence layer. RemoveBulk(ctx context.Context, ids []K) ([]E, error) }
Repository contains a set of methods to interact with a persistence layer. The E parameter represents an entity model. The K parameter represent the primary key.
func NewRepositorySQL ¶
func NewRepositorySQL[E any, K comparable](db *gorm.DB) Repository[E, K]
NewRepositorySQL initializes a new implementation of Repository using an SQL ORM: gorm.
type SQL ¶
type SQL[E any, K comparable] struct { // contains filtered or unexported fields }
SQL implements Repository using gorm.
func (*SQL[E, K]) CreateBulk ¶
CreateBulk creates a set of entities in a persistence layer.
func (*SQL[E, K]) Find ¶
Find returns a set of entities from a persistence layer identified by their IDs. It returns an empty slice if no records were found.
func (*SQL[E, K]) Get ¶
Get returns an entity from a persistence layer identified by its ID. It returns an error if the entity doesn't exist.
func (*SQL[E, K]) RemoveBulk ¶
RemoveBulk removes a set of elements from the persistence layer.