Return counter from DeleteByPath

This commit is contained in:
Deluan
2020-07-12 11:48:57 -04:00
parent e55397fcdc
commit dc8368c89c
4 changed files with 7 additions and 7 deletions
+2 -3
View File
@@ -124,14 +124,13 @@ func (r mediaFileRepository) Delete(id string) error {
}
// DeleteByPath delete from the DB all mediafiles that are direct children of path
func (r mediaFileRepository) DeleteByPath(path string) error {
func (r mediaFileRepository) DeleteByPath(path string) (int64, error) {
path = filepath.Clean(path)
del := Delete(r.tableName).
Where(And{Like{"path": filepath.Join(path, "%")},
Eq{fmt.Sprintf("substr(path, %d) glob '*%s*'", len(path)+2, string(os.PathSeparator)): 0}})
log.Debug(r.ctx, "Deleting mediafiles by path", "path", path)
_, err := r.executeSQL(del)
return err
return r.executeSQL(del)
}
func (r mediaFileRepository) Search(q string, offset int, size int) (model.MediaFiles, error) {
+1 -1
View File
@@ -82,7 +82,7 @@ var _ = Describe("MediaRepository", func() {
id3 := "3333"
Expect(mr.Put(&model.MediaFile{ID: id3, Path: P("/abc/" + id3 + ".mp3")})).To(BeNil())
Expect(mr.DeleteByPath(P("/abc"))).To(BeNil())
Expect(mr.DeleteByPath(P("/abc"))).To(Equal(int64(1)))
Expect(mr.Get(id1)).ToNot(BeNil())
Expect(mr.Get(id2)).ToNot(BeNil())