2022-02-22 20:33:45 +08:00
|
|
|
// Copyright 2022 Memgraph Ltd.
|
2021-10-26 14:53:56 +08:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
2017-08-24 21:23:33 +08:00
|
|
|
#include <gflags/gflags.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");
|
2018-06-20 23:44:47 +08:00
|
|
|
DEFINE_bool(use_ssl, false, "Set to true to connect with SSL to the server.");
|
2021-02-18 22:32:43 +08:00
|
|
|
DEFINE_bool(print_records, true, "Set to false to disable printing of records.");
|
2017-08-24 21:23:33 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::communication::SSLInit sslInit;
|
2018-06-20 23:44:47 +08:00
|
|
|
|
2017-08-24 21:23:33 +08:00
|
|
|
// TODO: handle endpoint exception
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::io::network::Endpoint endpoint(memgraph::io::network::ResolveHostname(FLAGS_address), FLAGS_port);
|
2018-06-20 23:44:47 +08:00
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::communication::ClientContext context(FLAGS_use_ssl);
|
2022-08-26 19:19:27 +08:00
|
|
|
memgraph::communication::bolt::Client client(context);
|
2017-08-24 21:23:33 +08:00
|
|
|
|
2018-10-19 18:28:38 +08:00
|
|
|
client.Connect(endpoint, FLAGS_username, FLAGS_password);
|
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 {
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::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;
|
|
|
|
}
|
|
|
|
|
2019-03-04 21:46:02 +08:00
|
|
|
if (FLAGS_print_records) {
|
|
|
|
std::cout << "Records:" << std::endl;
|
|
|
|
for (int i = 0; i < static_cast<int>(ret.records.size()); ++i) {
|
|
|
|
std::cout << " " << i << std::endl;
|
|
|
|
for (auto &value : ret.records[i]) {
|
|
|
|
std::cout << " " << value << std::endl;
|
|
|
|
}
|
2017-08-24 21:23:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "Metadata:" << std::endl;
|
|
|
|
for (auto &data : ret.metadata) {
|
|
|
|
std::cout << " " << data.first << " : " << data.second << std::endl;
|
|
|
|
}
|
2022-02-22 20:33:45 +08:00
|
|
|
} catch (const memgraph::communication::bolt::ClientQueryException &e) {
|
2017-08-24 21:23:33 +08:00
|
|
|
std::cout << "Client received exception: " << e.what() << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|