2017-08-24 21:23:33 +08:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
#include <glog/logging.h>
|
|
|
|
|
|
|
|
#include "communication/bolt/client.hpp"
|
2018-01-15 21:03:07 +08:00
|
|
|
#include "io/network/endpoint.hpp"
|
2018-05-29 17:13:13 +08:00
|
|
|
#include "io/network/utils.hpp"
|
2017-08-28 16:51:19 +08:00
|
|
|
#include "utils/timer.hpp"
|
2017-08-24 21:23:33 +08:00
|
|
|
|
|
|
|
DEFINE_string(address, "127.0.0.1", "Server address");
|
2018-01-15 21:03:07 +08:00
|
|
|
DEFINE_int32(port, 7687, "Server port");
|
2017-08-24 21:23:33 +08:00
|
|
|
DEFINE_string(username, "", "Username for the database");
|
|
|
|
DEFINE_string(password, "", "Password for the database");
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
google::InitGoogleLogging(argv[0]);
|
|
|
|
|
|
|
|
// TODO: handle endpoint exception
|
2018-05-29 17:13:13 +08:00
|
|
|
io::network::Endpoint endpoint(io::network::ResolveHostname(FLAGS_address),
|
2018-03-27 23:59:40 +08:00
|
|
|
FLAGS_port);
|
|
|
|
communication::bolt::Client client;
|
2017-08-24 21:23:33 +08:00
|
|
|
|
2018-03-27 23:59:40 +08:00
|
|
|
if (!client.Connect(endpoint, FLAGS_username, FLAGS_password)) return 1;
|
2017-08-24 21:23:33 +08:00
|
|
|
|
|
|
|
std::cout << "Memgraph bolt client is connected and running." << std::endl;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
std::string s;
|
|
|
|
std::getline(std::cin, s);
|
|
|
|
if (s == "") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
try {
|
2017-08-28 16:51:19 +08:00
|
|
|
utils::Timer t;
|
2017-08-24 21:23:33 +08:00
|
|
|
auto ret = client.Execute(s, {});
|
2017-08-28 16:51:19 +08:00
|
|
|
auto elapsed = t.Elapsed().count();
|
|
|
|
std::cout << "Wall time:\n " << elapsed << std::endl;
|
2017-08-24 21:23:33 +08:00
|
|
|
|
|
|
|
std::cout << "Fields:" << std::endl;
|
|
|
|
for (auto &field : ret.fields) {
|
|
|
|
std::cout << " " << field << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "Records:" << std::endl;
|
2017-08-28 16:51:19 +08:00
|
|
|
for (int i = 0; i < static_cast<int>(ret.records.size()); ++i) {
|
2017-08-24 21:23:33 +08:00
|
|
|
std::cout << " " << i << std::endl;
|
|
|
|
for (auto &value : ret.records[i]) {
|
|
|
|
std::cout << " " << value << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "Metadata:" << std::endl;
|
|
|
|
for (auto &data : ret.metadata) {
|
|
|
|
std::cout << " " << data.first << " : " << data.second << std::endl;
|
|
|
|
}
|
2017-08-28 16:51:19 +08:00
|
|
|
} catch (const communication::bolt::ClientQueryException &e) {
|
2017-08-24 21:23:33 +08:00
|
|
|
std::cout << "Client received exception: " << e.what() << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|