mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 10:50:38 +02:00
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <QSql>
|
|
#include <QSqlDatabase>
|
|
#include <QSqlQuery>
|
|
#include <QSqlError>
|
|
|
|
#include <QVariant>
|
|
#include <QDebug>
|
|
#include "subject.h"
|
|
#include "token.h"
|
|
#include <QDateTime>
|
|
|
|
|
|
class DatabaseManager : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
DatabaseManager(const QString& host, const QString& dbName, const QString& user, const QString& password, const bool& dryMode = false);
|
|
|
|
int saveSubject(const std::shared_ptr<Subject>& subject, const QString& table);
|
|
int saveToken(const std::shared_ptr<Token>& token, const QString& table);
|
|
void saveSubjectAttributes(const std::shared_ptr<Subject>& subject, const QString& table);
|
|
void setDeleted(const QString& id, const QString& table, quint64 time);
|
|
|
|
void dropTables();
|
|
void createTables();
|
|
|
|
quint64 getLastSync();
|
|
void updateLastSync(quint64 lastSync);
|
|
quint64 getNow();
|
|
|
|
QSqlQuery getUpdatedTokens();
|
|
QSqlQuery getToken(const QString& id);
|
|
|
|
void setLastUpdate(const QString& id, quint64 lastUpdate);
|
|
|
|
void log(const QString &msg);
|
|
QString getSubjectNameByTokenId(const QString &tokenId);
|
|
QString getSubjectNameById(const QString &id);
|
|
bool checkDeletedToken(const QString &id);
|
|
|
|
bool isOpen();
|
|
|
|
|
|
private:
|
|
bool checkIfExists(const QString& id, const QString& table);
|
|
bool executeQuery(QSqlQuery &query, const QString &statement = QString());
|
|
QString getLastQuery(const QSqlQuery &query) const;
|
|
|
|
signals:
|
|
void error();
|
|
|
|
private:
|
|
QSqlDatabase db;
|
|
bool dryMode = false;
|
|
bool opened = false;
|
|
};
|