Skip to content

Commit

Permalink
Merge pull request #9 from ataklychev/master
Browse files Browse the repository at this point in the history
Add method CrudRepository.ListCount
  • Loading branch information
mnvx authored Nov 7, 2024
2 parents 7717db9 + f044c10 commit 93d7daf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crud_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type CrudRepositoryInterface interface {
PluckBy(fieldNames []string) (map[string]int64, error)
ListAll() ([]InterfaceEntity, error)
List(parameters ListParametersInterface) ([]InterfaceEntity, error)
ListCount(parameters ListParametersInterface) (int64, error)
Create(item InterfaceEntity) InterfaceEntity
CreateOrUpdateMany(item InterfaceEntity, columns []string, values []map[string]interface{}, onConflict string) error
Update(item InterfaceEntity) InterfaceEntity
Expand Down Expand Up @@ -235,6 +236,17 @@ func (c CrudRepository) List(parameters ListParametersInterface) ([]InterfaceEnt
return data, NormalizeErr(err)
}

func (c CrudRepository) ListCount(parameters ListParametersInterface) (int64, error) {
query, err := c.ListQueryBuilder.ListQuery(parameters)
if err != nil {
return 0, err
}
var count int64
item := reflect.New(reflect.TypeOf(c.GetModel()).Elem()).Interface()
err = query.Model(item).Count(&count).Error
return count, err
}

func (c CrudRepository) Create(item InterfaceEntity) InterfaceEntity {
c.Db.Create(item)
return item
Expand Down

0 comments on commit 93d7daf

Please sign in to comment.