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.
|
|
|
|
|
2018-03-27 23:59:40 +08:00
|
|
|
#pragma once
|
2018-01-27 01:50:16 +08:00
|
|
|
|
2017-09-06 19:39:13 +08:00
|
|
|
#include <fstream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "communication/bolt/client.hpp"
|
2018-07-24 21:11:18 +08:00
|
|
|
#include "communication/bolt/v1/value.hpp"
|
2018-01-15 21:03:07 +08:00
|
|
|
#include "io/network/endpoint.hpp"
|
2021-01-21 22:47:56 +08:00
|
|
|
#include "utils/logging.hpp"
|
2017-09-06 19:39:13 +08:00
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
using EndpointT = memgraph::io::network::Endpoint;
|
|
|
|
using ContextT = memgraph::communication::ClientContext;
|
|
|
|
using ClientT = memgraph::communication::bolt::Client;
|
|
|
|
using QueryDataT = memgraph::communication::bolt::QueryData;
|
|
|
|
using memgraph::communication::bolt::Value;
|
2017-09-06 19:39:13 +08:00
|
|
|
|
|
|
|
class BoltClient {
|
|
|
|
public:
|
2021-02-18 22:32:43 +08:00
|
|
|
BoltClient(const std::string &address, uint16_t port, const std::string &username, const std::string &password,
|
2018-06-20 23:44:47 +08:00
|
|
|
const std::string & = "", bool use_ssl = false)
|
|
|
|
: context_(use_ssl), client_(context_) {
|
2017-12-12 19:25:15 +08:00
|
|
|
EndpointT endpoint(address, port);
|
2017-09-06 19:39:13 +08:00
|
|
|
|
2018-06-20 23:44:47 +08:00
|
|
|
if (!client_.Connect(endpoint, username, password)) {
|
2021-01-21 22:47:56 +08:00
|
|
|
LOG_FATAL("Could not connect to: {}", endpoint);
|
2017-09-06 19:39:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
QueryDataT Execute(const std::string &query, const std::map<std::string, Value> ¶meters) {
|
2018-06-20 23:44:47 +08:00
|
|
|
return client_.Execute(query, parameters);
|
2017-09-06 19:39:13 +08:00
|
|
|
}
|
|
|
|
|
2018-06-20 23:44:47 +08:00
|
|
|
void Close() { client_.Close(); }
|
2017-09-06 19:39:13 +08:00
|
|
|
|
|
|
|
private:
|
2018-06-20 23:44:47 +08:00
|
|
|
ContextT context_;
|
|
|
|
ClientT client_;
|
2017-09-06 19:39:13 +08:00
|
|
|
};
|