2017-12-09 20:21:22 +01:00
|
|
|
|
#include "OpenDatabase.h"
|
2018-12-16 10:17:59 +01:00
|
|
|
|
#include "catalog/PgDatabaseCatalog.h"
|
2017-08-26 11:45:50 +02:00
|
|
|
|
#include "Pgsql_Connection.h"
|
2018-12-16 10:17:59 +01:00
|
|
|
|
#include "model/TypeSelectionItemModel.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2017-12-25 10:31:58 +01:00
|
|
|
|
Expected<OpenDatabase::OpenDatabaseSPtr> OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2018-12-23 08:43:43 +01:00
|
|
|
|
return Expected<OpenDatabase::OpenDatabaseSPtr>::fromCode(
|
|
|
|
|
|
[&cfg] () -> auto {
|
|
|
|
|
|
OpenDatabaseSPtr odb(new OpenDatabase(cfg));
|
|
|
|
|
|
odb->Init();
|
|
|
|
|
|
return odb;
|
|
|
|
|
|
});
|
|
|
|
|
|
// catch (const PgException &ex) {
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// return Expected<OpenDatabaseSPtr>::fromException(
|
|
|
|
|
|
// std::runtime_error("Failed to get database information"));
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-25 10:31:58 +01:00
|
|
|
|
OpenDatabase::OpenDatabase(const ConnectionConfig& cfg)
|
|
|
|
|
|
: m_config(cfg)
|
2018-11-25 09:05:01 +01:00
|
|
|
|
, m_catalog(std::make_shared<PgDatabaseCatalog>())
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 15:38:32 +01:00
|
|
|
|
OpenDatabase::~OpenDatabase() = default;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2018-12-23 08:43:43 +01:00
|
|
|
|
void OpenDatabase::Init()
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2017-02-04 11:55:49 +01:00
|
|
|
|
Pgsql::Connection conn;
|
|
|
|
|
|
auto kw = m_config.getKeywords();
|
|
|
|
|
|
auto vals = m_config.getValues();
|
2018-12-23 08:43:43 +01:00
|
|
|
|
conn.connect(kw, vals, 0);
|
|
|
|
|
|
m_catalog->loadAll(conn, nullptr);
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
2017-02-04 11:55:49 +01:00
|
|
|
|
|
2018-11-25 09:05:01 +01:00
|
|
|
|
std::shared_ptr<PgDatabaseCatalog> OpenDatabase::catalog()
|
2017-02-04 11:55:49 +01:00
|
|
|
|
{
|
2018-11-25 09:05:01 +01:00
|
|
|
|
return m_catalog;
|
2017-02-04 11:55:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-07 21:39:45 +01:00
|
|
|
|
TypeSelectionItemModel* OpenDatabase::typeSelectionModel()
|
2017-02-04 11:55:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (m_typeSelectionModel == nullptr) {
|
|
|
|
|
|
m_typeSelectionModel = new TypeSelectionItemModel(nullptr);
|
2018-11-25 09:05:01 +01:00
|
|
|
|
m_typeSelectionModel->setTypeList(m_catalog->types());
|
2017-02-04 11:55:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
return m_typeSelectionModel;
|
|
|
|
|
|
}
|