refactor: updates delete method to return affected rows count
This commit is contained in:
@@ -69,8 +69,11 @@ func (r *baseRepository[T]) GetAll() ([]T, error) {
|
|||||||
return entities, nil
|
return entities, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *baseRepository[T]) Delete(id int) error {
|
func (r *baseRepository[T]) Delete(id int) (int64, error) {
|
||||||
query := r.BuildQuery("DELETE %s WHERE id = ? LIMIT 1")
|
query := r.BuildQuery("DELETE %s WHERE id = ? LIMIT 1")
|
||||||
_, err := r.db.Exec(query, id)
|
res, err := r.db.Exec(query, id)
|
||||||
return err
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return res.RowsAffected()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ type Repository[T any] interface {
|
|||||||
BuildQuery(s string) string
|
BuildQuery(s string) string
|
||||||
GetByID(id int) (*T, error)
|
GetByID(id int) (*T, error)
|
||||||
GetAll() ([]T, error)
|
GetAll() ([]T, error)
|
||||||
Delete(id int) error
|
Delete(id int) (int64, error)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user