db.h 2.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/***
Pix  Copyright (C) 2018  Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

 This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
***/

#ifndef DB_H
#define DB_H

#include <QObject>
#include <QString>
#include <QStringList>
#include <QList>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlRecord>
#include <QSqlDriver>
#include <QFileInfo>
#include <QDir>
#include <QVariantMap>

#include "../utils/owl.h"
39 40 41 42 43 44
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#else
#include <MauiKit/fmh.h>
#endif

45 46 47 48

class DB : public QObject
{
    Q_OBJECT
49

50 51
private:
    explicit DB(QObject *parent = nullptr);
52
    ~DB();
53

54 55 56
    static DB* instance;
    QString name;
    QSqlDatabase m_db;
57

58 59
public:
    static DB *getInstance();
60
    /* utils*/
61
    bool checkExistance(const QString &tableName, const QString &searchId, const QString &search);
62
    FMH::MODEL_LIST getDBData(const QString &queryTxt);
63 64 65
    QSqlQuery getQuery(const QString &queryTxt);

    bool insert(const QString &tableName, const QVariantMap &insertData);
66
    bool update(const QString &tableName, const QVariantMap &updateData, const QVariantMap &where);
67
    bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id);
Camilo Higuita's avatar
Camilo Higuita committed
68
    bool remove(const QString &tableName, const QVariantMap &removeData);
69

70 71 72 73
protected:
    void openDB(const QString &name);
    void prepareCollectionDB() const;

74 75 76 77 78 79
signals:

public slots:
};

#endif // DB_H