1 | #pragma once |
2 | |
3 | #include "config_core.h" |
4 | #if USE_MYSQL |
5 | |
6 | #include <ext/shared_ptr_helper.h> |
7 | |
8 | #include <Storages/IStorage.h> |
9 | #include <mysqlxx/Pool.h> |
10 | |
11 | |
12 | namespace DB |
13 | { |
14 | |
15 | /** Implements storage in the MySQL database. |
16 | * Use ENGINE = mysql(host_port, database_name, table_name, user_name, password) |
17 | * Read only. |
18 | */ |
19 | class StorageMySQL : public ext::shared_ptr_helper<StorageMySQL>, public IStorage |
20 | { |
21 | friend struct ext::shared_ptr_helper<StorageMySQL>; |
22 | public: |
23 | StorageMySQL( |
24 | const std::string & database_name_, |
25 | const std::string & table_name_, |
26 | mysqlxx::Pool && pool_, |
27 | const std::string & remote_database_name_, |
28 | const std::string & remote_table_name_, |
29 | const bool replace_query_, |
30 | const std::string & on_duplicate_clause_, |
31 | const ColumnsDescription & columns_, |
32 | const ConstraintsDescription & constraints_, |
33 | const Context & context_); |
34 | |
35 | std::string getName() const override { return "MySQL" ; } |
36 | std::string getTableName() const override { return table_name; } |
37 | std::string getDatabaseName() const override { return database_name; } |
38 | |
39 | BlockInputStreams read( |
40 | const Names & column_names, |
41 | const SelectQueryInfo & query_info, |
42 | const Context & context, |
43 | QueryProcessingStage::Enum processed_stage, |
44 | size_t max_block_size, |
45 | unsigned num_streams) override; |
46 | |
47 | BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override; |
48 | |
49 | private: |
50 | friend class StorageMySQLBlockOutputStream; |
51 | std::string table_name; |
52 | std::string database_name; |
53 | |
54 | std::string remote_database_name; |
55 | std::string remote_table_name; |
56 | bool replace_query; |
57 | std::string on_duplicate_clause; |
58 | |
59 | mysqlxx::Pool pool; |
60 | Context global_context; |
61 | }; |
62 | |
63 | } |
64 | |
65 | #endif |
66 | |