WIP. Improved database cleanup + various db fixes

This commit is contained in:
emeric
2014-08-07 15:29:54 +02:00
parent 5bdabec325
commit 2fbb1a7260
15 changed files with 274 additions and 128 deletions
+6
View File
@@ -38,5 +38,11 @@ Artist::getAll(Wt::Dbo::Session& session, int offset, int size)
return session.find<Artist>().offset(offset).limit(size);
}
Wt::Dbo::collection<Artist::pointer>
Artist::getAllOrphans(Wt::Dbo::Session& session)
{
return session.query< Wt::Dbo::ptr<Artist> >("select a from artist a LEFT OUTER JOIN Track t ON a.id = t.artist_id WHERE t.id IS NULL");
}
} // namespace Database
+6 -3
View File
@@ -31,8 +31,10 @@ class Artist
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, int size = -1);
static Wt::Dbo::collection<pointer> getAllOrphans(Wt::Dbo::Session& session);
const std::string& getName(void) const { return _name; }
const Wt::Dbo::collection< Wt::Dbo::ptr<Track> >& getTracks(void) const { return _tracks;}
// Create
static pointer create(Wt::Dbo::Session& session, const std::string& name);
@@ -70,7 +72,7 @@ class Release
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getById(Wt::Dbo::Session& session, id_type id);
static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAllOrphans(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::vector<Artist::id_type> artistIds, int offset = -1, int size = -1);
// Create
@@ -78,7 +80,7 @@ class Release
std::string getName() const { return _name; }
bool isNone(void) const;
Wt::Dbo::collection<Wt::Dbo::ptr<Track> > getTracks(void) const { return _tracks;}
const Wt::Dbo::collection<Wt::Dbo::ptr<Track> >& getTracks(void) const { return _tracks;}
boost::posix_time::time_duration getDuration(void) const;
@@ -110,7 +112,7 @@ class Genre
// Find utility
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset, std::size_t size);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset = -1, std::size_t size = -1);
// Create utility
static pointer create(Wt::Dbo::Session& session, const std::string& name);
@@ -118,6 +120,7 @@ class Genre
// Accessors
const std::string& getName(void) const { return _name; }
bool isNone(void) const;
const Wt::Dbo::collection< Wt::Dbo::ptr<Track> >& getTracks() const { return _tracks;}
template<class Action>
void persist(Action& a)
+12 -3
View File
@@ -44,10 +44,19 @@ MediaDirectory::getAll(Wt::Dbo::Session& session)
return std::vector<MediaDirectory::pointer>(res.begin(), res.end());
}
MediaDirectory::pointer
MediaDirectory::getByPath(Wt::Dbo::Session& session, boost::filesystem::path p)
std::vector<MediaDirectory::pointer>
MediaDirectory::getByType(Wt::Dbo::Session& session, Type type)
{
return session.find<MediaDirectory>().where("path = ?").bind( p.string() );
Wt::Dbo::collection< MediaDirectory::pointer > res = session.find<MediaDirectory>().where("type = ?").bind (type);
return std::vector<MediaDirectory::pointer>(res.begin(), res.end());
}
MediaDirectory::pointer
MediaDirectory::get(Wt::Dbo::Session& session, boost::filesystem::path p, Type type)
{
return session.find<MediaDirectory>().where("path = ?").where("type = ?").bind( p.string()).bind(type);
}
} // namespace Database
+2 -1
View File
@@ -76,7 +76,8 @@ class MediaDirectory
// Accessors
static pointer create(Wt::Dbo::Session& session, boost::filesystem::path p, Type type);
static std::vector<MediaDirectory::pointer> getAll(Wt::Dbo::Session& session);
static pointer getByPath(Wt::Dbo::Session& session, boost::filesystem::path p);
static std::vector<MediaDirectory::pointer> getByType(Wt::Dbo::Session& session, Type type);
static pointer get(Wt::Dbo::Session& session, boost::filesystem::path p, Type type);
static void eraseAll(Wt::Dbo::Session& session);
+7
View File
@@ -73,5 +73,12 @@ Release::getDuration(void) const
return res;
}
Wt::Dbo::collection<Release::pointer>
Release::getAllOrphans(Wt::Dbo::Session& session)
{
return session.query< Wt::Dbo::ptr<Release> >("select r from release r LEFT OUTER JOIN Track t ON r.id = t.release_id WHERE t.id IS NULL");
}
} // namespace Database