ClickHouse/dbms/src/Storages/StorageMySQL.h

66 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
#include "config_core.h"
#if USE_MYSQL
2017-12-27 21:45:05 +00:00
#include <ext/shared_ptr_helper.h>
#include <Storages/IStorage.h>
#include <mysqlxx/Pool.h>
2017-12-13 16:46:57 +00:00
namespace DB
{
2017-12-26 21:34:06 +00:00
/** Implements storage in the MySQL database.
* Use ENGINE = mysql(host_port, database_name, table_name, user_name, password)
* Read only.
*/
2017-12-27 21:45:05 +00:00
class StorageMySQL : public ext::shared_ptr_helper<StorageMySQL>, public IStorage
{
2019-08-26 19:07:29 +00:00
friend struct ext::shared_ptr_helper<StorageMySQL>;
public:
2017-12-26 21:34:06 +00:00
StorageMySQL(
const std::string & database_name_,
const std::string & table_name_,
2019-08-03 11:02:40 +00:00
mysqlxx::Pool && pool_,
const std::string & remote_database_name_,
const std::string & remote_table_name_,
const bool replace_query_,
const std::string & on_duplicate_clause_,
const ColumnsDescription & columns_,
2019-08-24 21:20:20 +00:00
const ConstraintsDescription & constraints_,
2019-08-03 11:02:40 +00:00
const Context & context_);
2017-12-26 21:34:06 +00:00
std::string getName() const override { return "MySQL"; }
std::string getTableName() const override { return table_name; }
std::string getDatabaseName() const override { return database_name; }
2017-12-26 21:34:06 +00:00
BlockInputStreams read(
const Names & column_names,
const SelectQueryInfo & query_info,
const Context & context,
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
unsigned num_streams) override;
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
private:
friend class StorageMySQLBlockOutputStream;
std::string table_name;
std::string database_name;
2017-12-26 21:34:06 +00:00
std::string remote_database_name;
std::string remote_table_name;
bool replace_query;
std::string on_duplicate_clause;
2017-12-26 21:34:06 +00:00
mysqlxx::Pool pool;
Context global_context;
};
2017-12-26 21:34:06 +00:00
}
#endif