pgLab/pglab/OpenDatabase.h
eelke a88af1ac11 Improved connection error handling.
Just returning a boolean is too limiting. Using expection instead to easily pass on error message.
2018-12-23 08:43:43 +01:00

40 lines
1.2 KiB
C++

#ifndef OPENDATABASE_H
#define OPENDATABASE_H
#include "ConnectionConfig.h"
#include "Expected.h"
#include <memory>
class PgDatabaseCatalog;
class TypeSelectionItemModel;
/** Instances of this class represent a single database on which atleast one
* window is opened. This class is used to track details about that database.
*/
class OpenDatabase {
public:
using OpenDatabaseSPtr = std::shared_ptr<OpenDatabase>;
static Expected<OpenDatabaseSPtr> createOpenDatabase(const ConnectionConfig &cfg);
// using on_createResult_callback = std::function<void(Expected<std::shared_ptr<Pgsql::Result>>)>;
// void asyncCreateOpenDatabase(const ConnectionConfig &cfg, on_createResult_callback);
OpenDatabase(const OpenDatabase &) = delete;
OpenDatabase& operator=(const OpenDatabase &) = delete;
~OpenDatabase();
std::shared_ptr<PgDatabaseCatalog> catalog();
TypeSelectionItemModel* typeSelectionModel();
const ConnectionConfig& config() const { return m_config; }
private:
ConnectionConfig m_config;
std::shared_ptr<PgDatabaseCatalog> m_catalog;
TypeSelectionItemModel *m_typeSelectionModel = nullptr;
OpenDatabase(const ConnectionConfig& cfg);
void Init();
};
#endif // OPENDATABASE_H