ClickHouse/src/Storages/StorageMongoDB.h
Ivan 495c6e03aa
Replace all Context references with std::weak_ptr (#22297)
* Replace all Context references with std::weak_ptr

* Fix shared context captured by value

* Fix build

* Fix Context with named sessions

* Fix copy context

* Fix gcc build

* Merge with master and fix build

* Fix gcc-9 build
2021-04-11 02:33:54 +03:00

59 lines
1.6 KiB
C++

#pragma once
#include <ext/shared_ptr_helper.h>
#include <Storages/IStorage.h>
#include <Poco/MongoDB/Connection.h>
namespace DB
{
/* Implements storage in the MongoDB database.
* Use ENGINE = mysql(host_port, database_name, table_name, user_name, password)
* Read only.
*/
class StorageMongoDB final : public ext::shared_ptr_helper<StorageMongoDB>, public IStorage
{
friend struct ext::shared_ptr_helper<StorageMongoDB>;
public:
StorageMongoDB(
const StorageID & table_id_,
const std::string & host_,
short unsigned int port_,
const std::string & database_name_,
const std::string & collection_name_,
const std::string & username_,
const std::string & password_,
const ColumnsDescription & columns_,
const ConstraintsDescription & constraints_);
std::string getName() const override { return "MongoDB"; }
Pipe read(
const Names & column_names,
const StorageMetadataPtr & metadata_snapshot,
SelectQueryInfo & query_info,
ContextPtr context,
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
unsigned num_streams) override;
private:
void connectIfNotConnected();
const std::string host;
const short unsigned int port;
const std::string database_name;
const std::string collection_name;
const std::string username;
const std::string password;
std::shared_ptr<Poco::MongoDB::Connection> connection;
bool authentified = false;
std::mutex connection_mutex; /// Protects the variables `connection` and `authentified`.
};
}