UniSet 2.32.1
ClickHouseInterface.h
1/*
2 * Copyright (c) 2020 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16//----------------------------------------------------------------------------
17#ifndef ClickHouseInterface_H_
18#define ClickHouseInterface_H_
19// ---------------------------------------------------------------------------
20#include <string>
21#include <vector>
22#include <memory>
23#include <clickhouse-cpp/client.h>
24#include <clickhouse-cpp/block.h>
25#include <DBInterface.h>
26// -------------------------------------------------------------------------
27namespace uniset
28{
29 // ----------------------------------------------------------------------------
31 public DBNetInterface
32 {
33 public:
34
37
38 virtual bool nconnect( const std::string& host, const std::string& user,
39 const std::string& pswd, const std::string& dbname,
40 unsigned int port = 9000) override;
41 virtual bool close() override;
42 virtual bool isConnection() const override;
43 virtual bool ping() const override;
44
45 virtual const std::string lastQuery() override;
46
47 // Unsupport types: Array,Nullable,Tuple, idx
48 virtual DBResult query( const std::string& q ) override;
49
50 // supported all types
51 const std::vector<clickhouse::Block> bquery( const std::string& q );
52
53 bool execute( const std::string& q );
54 bool insert( const std::string& tblname, const clickhouse::Block& data );
55
56 virtual const std::string error() override;
57
58 bool reconnect(const std::string& host, const std::string& user,
59 const std::string& pswd, const std::string& dbname,
60 unsigned int port = 9000);
61
62 void setOptions( int sendRetries, bool pingBeforeQuery );
63
64 // unsupported
65 virtual bool insert( const std::string& q ) override
66 {
67 return false;
68 }
69 virtual double insert_id() override
70 {
71 return -1;
72 }
73
74 protected:
75
76 private:
77 DBResult makeResult( const clickhouse::Block& res );
78 void appendResult( DBResult& ret, const clickhouse::Block& block );
79
80 std::unique_ptr<clickhouse::Client> db;
81 std::string lastQ;
82 std::string lastE;
83
84 int sendRetries = { 2 };
85 bool pingBeforeQuery = { true };
86 };
87 // ----------------------------------------------------------------------------------
88} // end of namespace uniset
89// ----------------------------------------------------------------------------
90#endif
91// ----------------------------------------------------------------------------------
Definition ClickHouseInterface.h:32
Definition DBInterface.h:37
Definition DBInterface.h:52
Definition Calibration.h:27