1+ /* * Copyright 2020 Alibaba Group Holding Limited.
2+ *
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+
16+ #include " grape/util.h"
17+
18+ #include < boost/program_options.hpp>
19+ #include < fstream>
20+ #include < iostream>
21+ #include < vector>
22+ #include " flex/engines/graph_db/database/graph_db_session.h"
23+ #include " flex/storages/rt_mutable_graph/schema.h"
24+ #include " flex/third_party/httplib.h"
25+
26+ namespace bpo = boost::program_options;
27+
28+ int main (int argc, char ** argv) {
29+ bpo::options_description desc (" Usage:" );
30+ desc.add_options ()(" help" , " Display help message" )(" version,v" ,
31+ " Display version" )(
32+ " uri,u" , bpo::value<std::string>()->default_value (" 127.0.0.1" ),
33+ " uri of the db" )(" port,p" , bpo::value<int >()->default_value (10000 ),
34+ " port number" );
35+ google::InitGoogleLogging (argv[0 ]);
36+ FLAGS_logtostderr = true ;
37+
38+ bpo::variables_map vm;
39+ bpo::store (bpo::command_line_parser (argc, argv).options (desc).run (), vm);
40+ bpo::notify (vm);
41+
42+ if (vm.count (" help" )) {
43+ std::cout << desc << std::endl;
44+ return 0 ;
45+ }
46+ if (vm.count (" version" )) {
47+ std::cout << " GraphScope/Flex version " << FLEX_VERSION << std::endl;
48+ return 0 ;
49+ }
50+
51+ std::string uri = vm[" uri" ].as <std::string>();
52+ int port = vm[" port" ].as <int >();
53+ httplib::Client cli (uri, port);
54+ setenv (" TZ" , " Asia/Shanghai" , 1 );
55+ tzset ();
56+
57+ while (true ) {
58+ std::cout << " >>> " ;
59+ std::string query;
60+ getline (std::cin, query);
61+ if (query == " exit" ) {
62+ break ;
63+ }
64+ if (query == " " ) {
65+ continue ;
66+ }
67+
68+ query.append (1 , *gs::Schema::CYPHER_READ_DEBUG_PLUGIN_ID_STR);
69+ char input_format =
70+ static_cast <char >(gs::GraphDBSession::InputFormat::kCypherString );
71+ query.append (1 , input_format);
72+ auto res = cli.Post (" /v1/graph/current/query" , query, " text/plain" );
73+ std::string ret = res->body ;
74+ std::cout << ret << std::endl;
75+ }
76+ return 0 ;
77+ }
0 commit comments