//
// Created by Krad on 2021/10/11.
//

#ifndef GUI_SQLHELPER_H
#define GUI_SQLHELPER_H

class QSqlDatabase;
#include "CenterAlignSqlTableModel.h"
#include <QSqlQueryModel>
#include <QString>
#include <QHash>

class SQLHelper {
public:
    static bool Open();
    static bool Open(QSqlDatabase* base);
    static void Close();
    static void QueryFirst(QString sql, QMap<QString,QVariant>& result, QMap<QString,QVariant>* params = nullptr);
    static int QueryCount(QString sql, QMap<QString,QVariant>* params = nullptr);
    static int ExecuteNoQuery(QString sql, QMap<QString,QVariant>* params = nullptr);
    static void QueryMap(QString sql, QMap<QString,QVariant>& result, QMap<QString,QVariant>* params = nullptr);
    static QSqlQueryModel* QueryModel(QString queryName);
    static QSqlQueryModel* QueryModel(QString queryName, QString sql, QMap<QString,QVariant>* params = nullptr);
    static QSqlTableModel* getTable(const QString & tableName);
private:
    static QSqlDatabase*  defaultDatabase;
    static QHash<QString,QSqlQueryModel*>* cache;
};


#endif //GUI_SQLHELPER_H
