8 #include <common/datatypes/DataSet.h>
12 #include "nebula/client/Connection.h"
21 using ExecuteJsonCallback = std::function<void(std::string &&)>;
27 const std::string &username,
28 const std::string &password,
29 const std::string &timezoneName,
32 : sessionId_(sessionId),
33 conn_(std::move(conn)),
37 timezoneName_(timezoneName),
38 offsetSecs_(offsetSecs),
39 retryConnect_(retryConnect) {}
42 : sessionId_(session.sessionId_),
43 conn_(std::move(session.conn_)),
45 username_(std::move(session.username_)),
46 password_(std::move(session.password_)),
47 timezoneName_(std::move(session.timezoneName_)),
48 offsetSecs_(session.offsetSecs_),
49 retryConnect_(session.retryConnect_) {
50 session.sessionId_ = -1;
51 session.pool_ =
nullptr;
52 session.offsetSecs_ = 0;
54 void operator=(
Session &&session) {
55 sessionId_ = session.sessionId_;
56 username_ = std::move(session.username_);
57 password_ = std::move(session.password_);
58 timezoneName_ = std::move(session.timezoneName_);
59 offsetSecs_ = session.offsetSecs_;
60 session.sessionId_ = -1;
61 session.pool_ =
nullptr;
62 session.offsetSecs_ = 0;
70 void asyncExecute(
const std::string &stmt, ExecuteCallback cb);
73 const std::unordered_map<std::string, Value> ¶meters);
75 void asyncExecuteWithParameter(
const std::string &stmt,
76 const std::unordered_map<std::string, Value> ¶meters,
79 std::string executeJson(
const std::string &stmt);
81 void asyncExecuteJson(
const std::string &stmt, ExecuteJsonCallback cb);
83 std::string executeJsonWithParameter(
const std::string &stmt,
84 const std::unordered_map<std::string, Value> ¶meters);
86 void asyncExecuteJsonWithParameter(
const std::string &stmt,
87 const std::unordered_map<std::string, Value> ¶meters,
88 ExecuteJsonCallback cb);
92 ErrorCode retryConnect();
97 return sessionId_ > 0;
100 const std::string &timeZoneName()
const {
101 return timezoneName_;
104 int32_t timeZoneOffsetSecs()
const {
110 return toLocal(data, offsetSecs_);
114 return resp.errorCode == ErrorCode::E_SESSION_INVALID ||
115 resp.errorCode == ErrorCode::E_SESSION_NOT_FOUND;
119 static void toLocal(
DataSet &data, int32_t offsetSecs);
122 int64_t sessionId_{-1};
125 std::string username_;
126 std::string password_;
128 std::string timezoneName_;
130 bool retryConnect_{
true};
131 std::atomic<bool> connectionIsBroken_{
false};