-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: how can I use the API without linked calls? #8
Comments
Hi, Great to hear from you. Your scene and suggestion is really good. The cue I could give you is the member variant What chain-able call finished is to build Apologize for my busy working these days, otherwise I'll add this feature ASAP. Looking forward to your reply. Thank you, Orca |
Without even needing to look into the source for the datatypes, you could probably just use cpp's auto feature. In pseudocode, something along the lines of
If you need a separate map for tags, you should create an additional loop before the fields loop as well. |
I followed your suggestion, but I got an error message like this. error: use of deleted function 'influxdb_cpp::detail::tag_caller& influxdb_cpp::detail::tag_caller::operator=(const influxdb_cpp::detail::tag_caller&)' Could you help me? |
Do some small modifications. auto& m = influxdb_cpp::builder().meas("imu").tag("track", "Home Testing");
foreach key, value in std::map {
m.field(key, value); // notice this line please
}
...
m.post_http(si, &resp); |
I use the linked call like this:
but compile error:
@orca-zhang @jha Could you help me? |
I came up with a solution using std::optional (C++17). Rather messy, but it gets the job done. void Test(influxdb_cpp::server_info& si)
{
std::unordered_map<std::string, float> kvps;
auto m = influxdb_cpp::builder();
std::optional<std::reference_wrapper<std::decay_t<decltype(m.meas("").field("",""))>>> field;
for (auto it = kvps.begin(); it != kvps.end(); ++it)
{
const auto& key = it->first;
const auto& value = it->second;
if (field.has_value())
field = field->get().field(key.c_str(), value);
else
field = m.meas("imu").tag("track", "Home Testing").field(key.c_str(), value);
}
if (kvps.empty())
return;
field->get().post_http(si);
}
|
When meas_caller will be implemented? |
Same compilation error for me when building the following code:
error: ‘struct influxdb_cpp::detail::tag_caller’ has no member named ‘post_http’ Any incoming fix or workaround for this issue ? |
auto &m = influxdb_cpp::builder().meas("test");
auto & f = m.field("val", 10);
f.post_http(si, &resp); |
I was having trouble with this part. To prevent using deleted references, I recommend using:
|
`
` |
after above, it doesn't act, can you help me? |
As you mentioned, one field is ok, but two or more field is wrong, how to resolve it? |
Hi, I have a similar need.
I hope to implement a caching mechanism to save post_http overhead
Is there any way to achieve this now? |
Hello,
I have history with C and relatively new to C++ and your API is a pattern I have not seen before. I have the test app working fine with the call like:
int ret = influxdb_cpp::builder() .meas("imu") .tag("track", "Home Testing") .field("ax", ax) .field("ay", ay) .field("az", az) .field("gx", gx) .field("gy", gy) .field("gz", gz) .field("yaw", yaw) .field("pitch", pitch) .field("roll", roll) .field("temperature", temperature) .field("pressure", pressure) .field("altitude", altitude) .timestamp( std::chrono::duration_cast<std::chrono::nanoseconds>(clock.now().time_since_epoch()).count() ) .post_http(si, &resp);
but I have a thread pool that handle a queue I have created. The queue contain a generic payload for more than 1 type of measures. The fields and tags are passed in as maps in the format { tag name, tag value}
So therefore I need to iterate over the map and call .field or .tag APIs.
I can't seem to figure out a calling mechanism to support this where I create the builder and then add details to it iterating over my map(s) and then calling the post_http.
Thought I would post this here for some help. In the mean time I will dig deeper to see if I can understand the way your API works.
Thanks, Jeff
The text was updated successfully, but these errors were encountered: