Skip to content

Commit 9cf3cee

Browse files
committed
#20 adding correct bool insertion via the line protocol
1 parent 0ec7eff commit 9cf3cee

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ A batching api leans towards thousands inserts per second. Behind the scenes, th
1313

1414
## Status
1515

16-
Build and test ok on Win10/Ubuntu64/OSX.
17-
18-
Feel free to contribute, as the progress is rather sporadic due to lack of spare time.
16+
- Build and test ok on Win10/Ubuntu64/OSX.
17+
- Feel free to contribute, as the progress is rather sporadic due to lack of spare time.
18+
- tested with InfluxDB v1.2.4, v1.7.5, v1.7.6
1919

2020
## Synchronous insertion
2121

src/influxdb-cpp-rest/influxdb_line.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ namespace influxdb {
4848
template<
4949
class V,
5050
typename std::enable_if<
51-
std::is_integral<V>::value
51+
std::is_integral<V>::value &&
52+
(! std::is_same<bool, V>::value)
5253
>::type* = nullptr
5354
>
5455
key_value_pairs& add(std::string const& key, V const& value) {
@@ -61,6 +62,23 @@ namespace influxdb {
6162
return *this;
6263
}
6364

65+
template<
66+
class V,
67+
typename std::enable_if<
68+
std::is_integral<V>::value &&
69+
( std::is_same<bool, V>::value)
70+
>::type* = nullptr
71+
>
72+
key_value_pairs& add(std::string const& key, V const& value) {
73+
::influxdb::utility::throw_on_invalid_identifier(key);
74+
75+
add_comma_if_necessary();
76+
77+
format_to(res, "{}={}", key, value);
78+
79+
return *this;
80+
}
81+
6482
template<
6583
class V,
6684
typename std::enable_if<

src/test/simple_api_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ TEST_CASE_METHOD(simple_connected_test, "inserting values using the simple api",
109109
CHECK(res.contains("hello world!"));
110110
}
111111

112+
TEST_CASE_METHOD(simple_connected_test, "inserting boolean values", "[connected]") {
113+
db.insert(line("boolean_test", key_value_pairs("mytag", true), key_value_pairs("value", false)));
114+
db.insert(line("boolean_test", key_value_pairs("mytag", false), key_value_pairs("value", true)));
115+
116+
wait_for([] {return false; },3);
117+
118+
auto res = result("boolean_test");
119+
CHECK(res.contains("true"));
120+
CHECK(res.contains("false"));
121+
// tags are not booleans, thus quoted
122+
CHECK(res.contains("\"true\""));
123+
CHECK(res.contains("\"false\""));
124+
}
112125

113126
TEST_CASE_METHOD(simple_connected_test, "inserting multiple lines in one call") {
114127
auto l = line

0 commit comments

Comments
 (0)