1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #ifndef __DB_H__
- #define __DB_H__
- #include <QPair>
- #include <QMap>
- #include <QString>
- #include <QSqlQuery>
- #include <QSqlError>
- #include "src/database/dbinfo.h"
- #include "debug.h"
- #include "src/experimental/UserInput.h"
- //#include "Decl.h"
- #include "Entry.h"
- namespace experimental {
- /// [F] ideas for functions of db class:
- /// https://github.com/fiffty-50/openpilotlog/wiki/New-DB-class-brainstorming
- /*!
- * \brief The DB class encapsulates the SQL database by providing fast access
- * to hot database data.
- */
- class DataBase {
- private:
- QStringList tableNames;
- QMap<QString, QStringList> tableColumns;
- static DataBase* instance;
- DataBase() = default;
- signals:
- void commitSuccessful();
- void commitUnsuccessful(QString message);
- public:
- // Ensure DB is not copiable or assignable
- DataBase(const DataBase&) = delete;
- void operator=(const DataBase&) = delete;
- static DataBase* getInstance();
- /*!
- * \brief Connect to the database and populate database information.
- */
- bool connect();
- /*!
- * \brief closes the database connection.
- */
- bool disconnect();
- /*!
- * \brief Checks if an entry exists in the database, based on position data
- */
- bool exists(Entry entry);
- /*!
- * \brief commits an entry to the database, calls either insert or update,
- * based on position data
- */
- bool commit(Entry entry);
- /*!
- * \brief Create new entry in the databse based on UserInput
- */
- bool insert(Entry newEntry);
- /*!
- * \brief Updates entry in database from existing entry tweaked by the user.
- */
- bool update(Entry updated_entry);
- /*!
- * \brief deletes an entry from the database.
- */
- bool remove(Entry entry);
- };
- /*!
- * \brief Convinience function that returns instance of DataBase.
- * Instead of this:
- * DataBase::getInstance().commit(...)
- * Write this:
- * DB().commit(...)
- */
- DataBase* DB();
- } // namespace experimental
- #endif
|