Обновление контроллеров и хранилища
This commit is contained in:
@@ -10,12 +10,16 @@ Storage& Storage::Get() {
|
||||
}
|
||||
|
||||
void Storage::Connect(const ConnectionData& connection_data) {
|
||||
std::ostringstream options;
|
||||
options << "dbname = " << connection_data.database
|
||||
std::ostringstream connection;
|
||||
connection << "dbname = " << connection_data.database
|
||||
<< " user = " << connection_data.username
|
||||
<< " password = " << connection_data.password
|
||||
<< " host = " << connection_data.host
|
||||
<< " port = " << connection_data.port;
|
||||
|
||||
Get().connection_ = std::make_unique<pqxx::connection>(options.str());
|
||||
connection_data_ = connection.str();
|
||||
}
|
||||
|
||||
Transaction Storage::CreateTransaction() {
|
||||
return { connection_data_ };
|
||||
}
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
#include <sstream>
|
||||
|
||||
#include <storage/storage.h>
|
||||
#include <storage/transaction.h>
|
||||
|
||||
using namespace storage;
|
||||
|
||||
Transaction::Transaction(const std::string& connection_data)
|
||||
: connection_(std::make_unique<pqxx::connection>(connection_data))
|
||||
, transaction_(std::make_unique<pqxx::work>(*connection_)) {}
|
||||
|
||||
Transaction::~Transaction() {
|
||||
transaction_->commit();
|
||||
}
|
||||
|
||||
Transaction Transaction::Create() {
|
||||
auto& storage = storage::Storage::Get();
|
||||
|
||||
Transaction transaction;
|
||||
transaction.transaction_ = std::make_unique<pqxx::work>(*storage.connection_);
|
||||
|
||||
return transaction;
|
||||
if (connection_ && transaction_) {
|
||||
transaction_->commit();
|
||||
connection_->close();
|
||||
}
|
||||
}
|
||||
|
||||
pqxx::result Transaction::Do(std::string_view query) const {
|
||||
return transaction_->exec(query);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user