增加了数据库及测试程序
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user