Have GroovePlayer init music db on creation. Make fields correctly be fk.
This commit is contained in:
@@ -18,8 +18,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "GroovePlayer.h"
|
#include "GroovePlayer.h"
|
||||||
|
#include "db/User.h"
|
||||||
|
#include "db/AudioTrack.h"
|
||||||
|
#include "db/UserAction.h"
|
||||||
|
#include <Wt/WLogger>
|
||||||
|
|
||||||
GroovePlayer::GroovePlayer()
|
GroovePlayer::GroovePlayer(std::string dbFile) : sqliteConnection(dbFile)
|
||||||
{
|
{
|
||||||
|
sqlSession.setConnection(this->sqliteConnection);
|
||||||
|
sqlSession.mapClass<User>("user");
|
||||||
|
sqlSession.mapClass<AudioTrack>("tracks");
|
||||||
|
sqlSession.mapClass<UserAction>("actions");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sqlSession.createTables();
|
||||||
|
} catch(Wt::Dbo::Exception e)
|
||||||
|
{
|
||||||
|
Wt::log("info") << "Using Existing DB.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,17 +20,22 @@
|
|||||||
#ifndef GROOVEPLAYER_H
|
#ifndef GROOVEPLAYER_H
|
||||||
#define GROOVEPLAYER_H
|
#define GROOVEPLAYER_H
|
||||||
|
|
||||||
|
#include <Wt/Dbo/Session>
|
||||||
|
#include <Wt/Dbo/backend/Sqlite3>
|
||||||
|
|
||||||
class GroovePlayer
|
class GroovePlayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static GroovePlayer* getInstance() {
|
static GroovePlayer* getInstance() {
|
||||||
static GroovePlayer instance;
|
static GroovePlayer instance("music.db");
|
||||||
return &instance;
|
return &instance;
|
||||||
};
|
};
|
||||||
GroovePlayer(GroovePlayer const&) = delete;
|
GroovePlayer(GroovePlayer const&) = delete;
|
||||||
void operator=(GroovePlayer const&) = delete;
|
void operator=(GroovePlayer const&) = delete;
|
||||||
private:
|
private:
|
||||||
GroovePlayer();
|
GroovePlayer(std::string dbFile);
|
||||||
|
Wt::Dbo::backend::Sqlite3 sqliteConnection;
|
||||||
|
Wt::Dbo::Session sqlSession;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GROOVEPLAYER_H
|
#endif // GROOVEPLAYER_H
|
||||||
|
|||||||
@@ -31,17 +31,17 @@ class UserAction
|
|||||||
public:
|
public:
|
||||||
enum UAction {Login = 0, Logout = 1, RequestTrack = 2, VoteTrack = 3, UploadTrack = 4, RequestSkip = 5, Pause = 6};
|
enum UAction {Login = 0, Logout = 1, RequestTrack = 2, VoteTrack = 3, UploadTrack = 4, RequestSkip = 5, Pause = 6};
|
||||||
|
|
||||||
User user;
|
Wt::Dbo::ptr<User> user;
|
||||||
UAction action;
|
UAction action;
|
||||||
AudioTrack trackInvolved;
|
Wt::Dbo::ptr<AudioTrack> trackInvolved;
|
||||||
Wt::WDateTime datetime;
|
Wt::WDateTime datetime;
|
||||||
|
|
||||||
template<class Action>
|
template<class Action>
|
||||||
void persist(Action& a)
|
void persist(Action& a)
|
||||||
{
|
{
|
||||||
Wt::Dbo::field(a, user, "user");
|
Wt::Dbo::belongsTo(a, user, "user");
|
||||||
Wt::Dbo::field(a, action, "action");
|
Wt::Dbo::field(a, action, "action");
|
||||||
Wt::Dbo::field(a, trackInvolved, "track");
|
Wt::Dbo::belongsTo(a, trackInvolved, "track");
|
||||||
Wt::Dbo::field(a, datetime, "datetime");
|
Wt::Dbo::field(a, datetime, "datetime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user