Skip to content

Commit e143c5d

Browse files
committed
reverting the demo
1 parent bd4ef5f commit e143c5d

File tree

1 file changed

+47
-44
lines changed

1 file changed

+47
-44
lines changed

src/demo/main.cpp

+47-44
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
2+
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
13
#include <influxdb_raw_db_utf8.h>
24
#include <influxdb_simple_api.h>
35
#include <influxdb_line.h>
@@ -6,49 +8,50 @@
68
#include <iostream>
79
#include <thread>
810
#include <chrono>
9-
#include <time.h>
10-
#include <unistd.h>
11-
#include <sys/time.h>
1211

1312
using namespace influxdb::api;
14-
using namespace std;
15-
16-
int main(int argc, char *argv[]) {
17-
try {
18-
int keyNum = 0;
19-
20-
influxdb::async_api::simple_db async_api("http://localhost:8086", "bluewhale");
21-
22-
struct timeval begin;
23-
gettimeofday(&begin, NULL);
24-
25-
while (1) {
26-
struct timeval tv,td;
27-
gettimeofday(&tv, NULL);
28-
long time = (long long) (tv.tv_sec) * 1000000000 + tv.tv_usec * 1000;
29-
30-
influxdb::api::key_value_pairs tags;
31-
influxdb::api::key_value_pairs fields;
32-
string g_app_name = "test";
33-
string rankID = "1";
34-
std::cout << "key num: " << keyNum << std::endl;
35-
tags.add("appName", g_app_name);
36-
tags.add("svrID", rankID);
37-
fields.add("value", keyNum);
38-
async_api.insert(line("t_lr_key", tags, fields));
39-
40-
gettimeofday(&td, NULL);
41-
std::cout << "cost time " << (td.tv_sec - tv.tv_sec) * 1000000 + (td.tv_usec - tv.tv_usec) << std::endl;
42-
43-
std::cout << "current time " << (td.tv_sec - begin.tv_sec) / 60 << std::endl << std::endl;
44-
keyNum++;
45-
sleep(1);
46-
}
47-
48-
}
49-
catch (std::exception const &e) {
50-
std::cerr << e.what() << std::endl;
51-
}
52-
53-
return 0;
54-
}
13+
14+
int main(int argc, char* argv[])
15+
{
16+
try
17+
{
18+
const char* url = "http://localhost:8086";
19+
influxdb::raw::db_utf8 db(url, "demo");
20+
influxdb::api::simple_db api(url, "demo");
21+
influxdb::async_api::simple_db async_api(url, "demo");
22+
23+
api.drop();
24+
api.create();
25+
26+
// {"results":[{"series":[{"columns":["name"],"name":"databases","values":[["_internal"],["mydb"]]}]}]}
27+
std::cout << db.get("show databases") << std::endl;
28+
29+
async_api.insert(line("test", key_value_pairs(), key_value_pairs("value", 41)));
30+
api.insert(line("test", key_value_pairs(), key_value_pairs("value", 42)));
31+
32+
std::this_thread::sleep_for(std::chrono::milliseconds(101));
33+
34+
// {"results":[{"series":[{"columns":["time","value"],"name":"test","values":[["2016-10-28T22:11:22.8110348Z",42]]}]}]}
35+
std::cout << db.get("select * from demo..test") << std::endl;
36+
37+
// or if the async call passes through:
38+
// {"results":[{"series":[{"name":"test","columns":["time","value"],
39+
// "values":[["2016-12-09T20:24:18.8239801Z",42],["2016-12-09T20:24:18.9026688Z",41]]}]}]}
40+
41+
api.drop();
42+
43+
// multiple lines formatted for one synchronous call:
44+
// multiple,v1=1i
45+
// multiple,v2=2i
46+
std::cout << line
47+
("multiple", key_value_pairs("v1", 1), key_value_pairs())
48+
("multiple", key_value_pairs("v2", 2), key_value_pairs())
49+
.get() << std::endl;
50+
}
51+
catch (std::exception const& e)
52+
{
53+
std::cerr << e.what() << std::endl;
54+
}
55+
56+
return 0;
57+
}

0 commit comments

Comments
 (0)