Storm ArtistRepository and PropertyRepository complete.

This commit is contained in:
Deluan
2020-01-10 16:13:07 -05:00
committed by Deluan Quintão
parent aebb960831
commit 0ca691b37f
11 changed files with 92 additions and 27 deletions
+12 -2
View File
@@ -34,12 +34,18 @@ func (r *stormRepository) Exists(id string) (bool, error) {
return err != storm.ErrNotFound, nil
}
func (r *stormRepository) getID(record interface{}) string {
v := reflect.ValueOf(record).Elem()
id := v.FieldByName("ID").String()
return id
}
func (r *stormRepository) purgeInactive(ids []string) (deleted []string, err error) {
query := Db().Select(q.Not(q.In("ID", ids)))
// Collect IDs that will be deleted
err = query.Each(r.bucket, func(record interface{}) error {
v := reflect.ValueOf(record).Elem()
id := v.FieldByName("ID").String()
id := r.getID(record)
deleted = append(deleted, id)
return nil
})
@@ -47,6 +53,10 @@ func (r *stormRepository) purgeInactive(ids []string) (deleted []string, err err
return nil, err
}
if len(deleted) == 0 {
return
}
err = query.Delete(r.bucket)
if err != nil {
return nil, err