增加了数据库及测试程序

This commit is contained in:
zjk
2025-02-10 16:37:22 +08:00
parent e072f2b9d4
commit 59faa14afb
12 changed files with 326 additions and 82 deletions
+39
View File
@@ -0,0 +1,39 @@
#ifndef SQLITEDB_H
#define SQLITEDB_H
#include <sqlite3.h>
#include <string>
#include <vector>
#include "json/json.h"
// #include <nlohmann/json.hpp>
struct PowerData {
int id;
std::string timestamp;
double voltage;
double current;
double power;
double temperature;
};
class SQLiteDB {
public:
SQLiteDB(const std::string& dbPath);
~SQLiteDB();
void createTables();
void insertPowerData(float voltage, float current, float power, float temperature);
std::vector<PowerData> getPowerData(int limit = 100);
template<typename T>
void insertStructData(const std::string& tableName, const T& data);
private:
sqlite3* m_db;
template<typename T>
std::string serializeStruct(const T& data);
};
#endif // SQLITEDB_H