123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #pragma once
- #ifndef TSDB_CPP_HPP
- #define TSDB_CPP_HPP
- #include <cstdio>
- #include <cstring>
- #include <memory>
- #include <string_view>
- #include <vector>
- #ifdef _WIN32
- #define TSDB_EXPORT __declspec(dllexport)
- #else
- #define TSDB_EXPORT
- #endif
- namespace tsdb_cpp {
- /// @brief A point in time series database.
- struct point {
- const std::string& name_;
- double value_;
- long long nanoseconds_;
- point(const std::string& name, double value, long long nanoseconds) : name_(name), value_(value), nanoseconds_(nanoseconds) {}
- };
- struct tsdb_batch_insertion {
- struct impl;
- ~tsdb_batch_insertion();
- tsdb_batch_insertion(tsdb_batch_insertion&& other);
- /// @brief Closes the batch. Will also commit the batch if it has not been committed yet.
- /// It is recommended to always call this method before dropping the object.
- void close();
- void add_point(std::string_view name, double value, long long nanoseconds);
- private:
- friend struct tsdb_entry;
- friend struct tsdb_entry_impl;
- tsdb_batch_insertion(std::unique_ptr<impl> impl);
- std::unique_ptr<impl> impl_;
- };
- struct tsdb_entry_impl;
- /// @brief A time series database.
- struct tsdb_entry {
- tsdb_entry(std::string_view remote, uint16_t port = 9000);
- ~tsdb_entry();
- tsdb_entry(tsdb_entry&& other);
- void close();
- void create_table();
- void create_memory_table();
- void drop_table();
- void drop_memory_table();
- // By default creates a local table (`tsdb_cpp`) and a distributed table (`tsdb_cpp_dist`) with the same schema.
- void create_dist_table(std::string_view cluster_name);
- /// @brief Sets the async insert buffer size. 0 means synchronous insert.
- /// WARN: With async insertion, you lose the ability to catch exceptions from the server.
- /// Backpressure is handled in a best-effort manner.
- void set_async_insert_buffer_size(size_t size);
- size_t get_async_insert_buffer_size() const;
- void set_active_table(std::string_view table_name);
- void set_metric_name(std::string_view metric_name);
- void insert_point(const point& p);
- void insert_points(const std::vector<point>& points);
- void insert_point(std::string_view name, double value, long long nanoseconds);
- tsdb_batch_insertion new_batch_insert();
- private:
- std::unique_ptr<tsdb_entry_impl> impl_;
- };
- } // namespace tsdb_cpp
- #endif // TSDB_CPP_HPP
|