49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#ifndef __DATABASE_H__
|
|
#define __DATABASE_H__
|
|
|
|
#include "HomeBox.h"
|
|
#include "Singleton.h"
|
|
#include "Task.h"
|
|
#include <string>
|
|
|
|
namespace Wt {
|
|
namespace Dbo {
|
|
class SqlConnectionPool;
|
|
}
|
|
} // namespace Wt
|
|
|
|
class VisitAnalysis {
|
|
public:
|
|
std::string url;
|
|
int pageViewCount = 0;
|
|
int uniqueVisitorCount = 0;
|
|
int lastViewTime = 0;
|
|
};
|
|
|
|
struct sqlite3;
|
|
class Session;
|
|
|
|
class Database {
|
|
friend class Amass::Singleton<Database>;
|
|
|
|
public:
|
|
~Database();
|
|
std::unique_ptr<Session> session();
|
|
bool open(const std::string &path);
|
|
|
|
void updateVisitCount(const std::string &url, const std::string &visitorUuid, const std::string &userAgent, int64_t time);
|
|
void clearVisitRecord();
|
|
VisitAnalysis visitAnalysisData(const std::string &url);
|
|
VisitAnalysis siteVisitAnalysisData();
|
|
std::list<VisitAnalysis> mostViewedUrls(int size);
|
|
std::list<VisitAnalysis> latestViewedUrls(int size);
|
|
|
|
protected:
|
|
void initialize();
|
|
|
|
private:
|
|
std::unique_ptr<Wt::Dbo::SqlConnectionPool> m_sqlConnectionPool;
|
|
sqlite3 *m_sqlite3 = nullptr;
|
|
};
|
|
|
|
#endif // __DATABASE_H__
|