2018-01-27 01:50:16 +08:00
|
|
|
#pragma once
|
|
|
|
|
2017-09-06 19:39:13 +08:00
|
|
|
#include <fstream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <glog/logging.h>
|
|
|
|
|
|
|
|
#include "communication/bolt/client.hpp"
|
|
|
|
#include "communication/bolt/v1/decoder/decoded_value.hpp"
|
2018-01-15 21:03:07 +08:00
|
|
|
#include "io/network/endpoint.hpp"
|
2017-09-06 19:39:13 +08:00
|
|
|
#include "io/network/socket.hpp"
|
|
|
|
|
|
|
|
using SocketT = io::network::Socket;
|
2018-01-15 21:03:07 +08:00
|
|
|
using EndpointT = io::network::Endpoint;
|
2017-09-06 19:39:13 +08:00
|
|
|
using ClientT = communication::bolt::Client<SocketT>;
|
|
|
|
using QueryDataT = communication::bolt::QueryData;
|
|
|
|
using communication::bolt::DecodedValue;
|
|
|
|
|
|
|
|
class BoltClient {
|
|
|
|
public:
|
2018-01-15 21:03:07 +08:00
|
|
|
BoltClient(const std::string &address, uint16_t port,
|
2017-09-14 03:20:03 +08:00
|
|
|
const std::string &username, const std::string &password,
|
|
|
|
const std::string & = "") {
|
2017-09-06 19:39:13 +08:00
|
|
|
SocketT socket;
|
2017-12-12 19:25:15 +08:00
|
|
|
EndpointT endpoint(address, port);
|
2017-09-06 19:39:13 +08:00
|
|
|
|
|
|
|
if (!socket.Connect(endpoint)) {
|
|
|
|
LOG(FATAL) << "Could not connect to: " << address << ":" << port;
|
|
|
|
}
|
|
|
|
|
|
|
|
client_ = std::make_unique<ClientT>(std::move(socket), username, password);
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryDataT Execute(const std::string &query,
|
|
|
|
const std::map<std::string, DecodedValue> ¶meters) {
|
|
|
|
return client_->Execute(query, parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Close() { client_->Close(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<ClientT> client_;
|
|
|
|
};
|