Older/Database/Database.h

49 lines
1.1 KiB
C
Raw Normal View History

2023-12-30 00:15:03 +08:00
#ifndef __DATABASE_H__
#define __DATABASE_H__
2024-07-10 22:37:40 +08:00
#include "HomeBox.h"
2023-12-30 01:19:36 +08:00
#include "Singleton.h"
2024-01-03 22:44:36 +08:00
#include "Task.h"
2023-12-30 00:15:03 +08:00
#include <string>
2024-11-26 22:58:54 +08:00
namespace Wt {
namespace Dbo {
class SqlConnectionPool;
}
} // namespace Wt
2024-07-30 22:17:55 +08:00
class VisitAnalysis {
public:
std::string url;
int pageViewCount = 0;
int uniqueVisitorCount = 0;
2024-08-06 09:48:25 +08:00
int lastViewTime = 0;
2024-07-30 22:17:55 +08:00
};
2023-12-30 01:19:36 +08:00
struct sqlite3;
2024-11-26 22:58:54 +08:00
class Session;
2023-12-30 01:19:36 +08:00
2023-12-30 00:15:03 +08:00
class Database {
2023-12-30 01:19:36 +08:00
friend class Amass::Singleton<Database>;
2023-12-30 00:15:03 +08:00
public:
2023-12-30 01:19:36 +08:00
~Database();
2024-11-26 22:58:54 +08:00
std::unique_ptr<Session> session();
2023-12-30 00:15:03 +08:00
bool open(const std::string &path);
2024-11-26 22:58:54 +08:00
void updateVisitCount(const std::string &url, const std::string &visitorUuid, const std::string &userAgent, int64_t time);
2024-07-30 23:17:42 +08:00
void clearVisitRecord();
2024-07-30 22:17:55 +08:00
VisitAnalysis visitAnalysisData(const std::string &url);
2024-07-30 23:17:42 +08:00
VisitAnalysis siteVisitAnalysisData();
2024-08-05 23:01:19 +08:00
std::list<VisitAnalysis> mostViewedUrls(int size);
2024-08-06 09:48:25 +08:00
std::list<VisitAnalysis> latestViewedUrls(int size);
2024-07-29 00:46:11 +08:00
2023-12-30 01:19:36 +08:00
protected:
void initialize();
private:
2024-11-26 22:58:54 +08:00
std::unique_ptr<Wt::Dbo::SqlConnectionPool> m_sqlConnectionPool;
2023-12-30 01:19:36 +08:00
sqlite3 *m_sqlite3 = nullptr;
2023-12-30 00:15:03 +08:00
};
#endif // __DATABASE_H__