#ifndef DBMANAGER_H
#define DBMANAGER_H

#include "global.h"
#include <QObject>
#include <QSqlDatabase>
#include <QSqlError>
#include <QMap>

class DatabaseManager : public QObject
{
    Q_OBJECT

public:
    explicit DatabaseManager(QObject* parent = nullptr);
    ~DatabaseManager();

    bool addDatabase(const DatabaseConfig& config);
    bool connect(const QString& strConnectionName);
    void disconnect(const QString& strConnectionName);
    QStringList conncetions();//获取所有链接名称

signals:
    void errorOccurred(const QString& strConnectionName, const QSqlError& error); //错误信息信号
    void connectionStatusChanged(const QString& strConnectionName, bool bConnected);

private:
    QMap<QString, DatabaseConfig> m_configs;
    QMap<QString, QSqlDatabase>   m_connections;
};

#endif //DBMANAGER_H
