forked from jurajmasar/rethink-db-cpp-driver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
connection.hpp
61 lines (43 loc) · 1.31 KB
/
connection.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef RETHINK_DB_DRIVER_CONNECTION
#define RETHINK_DB_DRIVER_CONNECTION
#include "proto/rdb_protocol/ql2.pb.h"
#include <boost/asio.hpp>
#include <string>
#include "rql.hpp"
using namespace std;
using namespace boost::asio;
using namespace com::rethinkdb;
using namespace com::rethinkdb::driver;
namespace com {
namespace rethinkdb {
namespace driver {
class connection : public enable_shared_from_this<connection> {
public:
connection(const string& host, const string& port, const string& database, const string& auth_key);
bool is_connected();
bool reconnect();
bool connect();
void close();
/* -------------------------------------------------------------------- */
void use(const string& db_name);
/* -------------------------------------------------------------------- */
shared_ptr<Response> read_response();
void write_query(const Query& query);
/* -------------------------------------------------------------------- */
shared_ptr<RQL> r();
string database;
private:
string host;
string port;
string auth_key;
bool connection_established;
io_service io_service;
ip::tcp::resolver resolver_;
ip::tcp::socket socket_;
boost::asio::streambuf request_;
boost::asio::streambuf response_;
};
}
}
}
#endif