|
2 | 2 |
|
3 | 3 |   [](https://github.com/opengemini/opengemini-client-cpp/releases)
|
4 | 4 |
|
| 5 | +> ⚠️ **This repository is in pre-alpha stage, so not yet feature-complete. And the API has not been frozen, it may be changed on the course of the development.** |
5 | 6 |
|
6 | 7 | English | [简体中文](README_CN.md)
|
7 | 8 |
|
8 | 9 | `opengemini-client-cpp` is a C++ client for OpenGemini
|
9 | 10 |
|
10 |
| -> ⚠️ **This repository is in pre-alpha stage, so not yet feature-complete. And the API has not been frozen, it may be changed on the course of the development.** |
| 11 | +--- |
11 | 12 |
|
12 |
| -## Design Doc |
| 13 | +- [Design Doc](#design-doc) |
| 14 | +- [About OpenGemini](#about-opengemini) |
| 15 | +- [Prerequisites](#prerequisites) |
| 16 | +- [Integration](#integration) |
| 17 | + - [CMake FetchContent](#cmake-fetchcontent) |
| 18 | + - [CMake FindPackage](#cmake-findpackage) |
| 19 | + - [Header-Only](#header-only) |
| 20 | +- [Quick Start](#quick-start) |
| 21 | +- [Build From Source](#build-from-source) |
| 22 | +- [Configuration](#configuration) |
13 | 23 |
|
| 24 | +## Design Doc |
14 | 25 | [OpenGemini Client Design Doc](https://github.com/openGemini/openGemini.github.io/blob/main/src/guide/develop/client_design.md)
|
15 | 26 |
|
16 | 27 | ## About OpenGemini
|
17 |
| - |
18 | 28 | OpenGemini is a cloud-native distributed time series database, find more information [here](https://github.com/openGemini/openGemini)
|
| 29 | + |
| 30 | +## Prerequisites |
| 31 | +- **Building Environment** |
| 32 | + - A compatible operating system: Linux, macOS, Windows |
| 33 | + - A C++ compiler toolset that supports at least C++17 standard: GCC, Clang, MSVC |
| 34 | + - [CMake](https://cmake.org/) 3.12 or later |
| 35 | + - [Doxygen](https://www.doxygen.nl/) (*optional*, for generating documents) |
| 36 | +- **Dependencies** |
| 37 | + - [Boost](https://github.com/boostorg/boost) 1.81 or later |
| 38 | + - [{fmt}](https://github.com/fmtlib/fmt) |
| 39 | + - [JSON](https://github.com/nlohmann/json) |
| 40 | + - [OpenSSL](https://github.com/openssl/openssl) (*optional*, for using TLS protocol) |
| 41 | + - [GoogleTest](https://github.com/google/googletest) (*optional*, for building unit tests) |
| 42 | + |
| 43 | +## Integration |
| 44 | +### CMake FetchContent |
| 45 | +It is recommended to integrate with OpenGeminiCxx using CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html). |
| 46 | + |
| 47 | +The library, along with any necessary dependencies(**excluding OpenSSL**), will be downloaded automatically, so you don't need to handle it yourself. |
| 48 | + |
| 49 | +You can including the following lines in your `CMakeLists.txt`: |
| 50 | +``` |
| 51 | +include(FetchContent) |
| 52 | +FetchContent_Declare(OpenGeminiCxx |
| 53 | + GIT_REPOSITORY https://github.com/openGemini/opengemini-client-cpp |
| 54 | + GIT_TAG main |
| 55 | +) |
| 56 | +FetchContent_MakeAvailable(OpenGeminiCxx) |
| 57 | +``` |
| 58 | + |
| 59 | +This will export the target `OpenGeminiCxx::Client` which you can link against to your own target like this: |
| 60 | +``` |
| 61 | +add_executable(YourApp main.cpp) |
| 62 | +target_link_libraries(YourApp PRIVATE OpenGeminiCxx::Client) |
| 63 | +``` |
| 64 | + |
| 65 | +### CMake FindPackage |
| 66 | +You can also use CMake's `find_package()` function to integrate the library into your project. |
| 67 | + |
| 68 | +This means you need to [build and install](#build-from-source) OpenGeminiCxx on your system first. |
| 69 | + |
| 70 | +Then you can add the following lines in your `CMakeLists.txt`: |
| 71 | +``` |
| 72 | +find_package(OpenGeminiCxx REQUIRED) |
| 73 | +``` |
| 74 | + |
| 75 | +This will export the target `OpenGeminiCxx::Client` which you can link against to your own target like this: |
| 76 | +``` |
| 77 | +add_executable(YourApp main.cpp) |
| 78 | +target_link_libraries(YourApp PRIVATE OpenGeminiCxx::Client) |
| 79 | +``` |
| 80 | + |
| 81 | +### Header-Only |
| 82 | +> **Note:** Although OpenGeminiCxx can be use as a header-only library, we still recommend use the compiled library for improved build times. |
| 83 | +
|
| 84 | +Download the [OpenGeminiCxx](https://github.com/openGemini/opengemini-client-cpp/releases), then add `/path/to/opengemini-client-cpp/include` to your project's including directories. |
| 85 | + |
| 86 | +You may also need to link against any necessary dependencies to your program manually, then you can include it directly in your source code with: |
| 87 | +``` |
| 88 | +#include <opengemini/Client.hpp> |
| 89 | +``` |
| 90 | + |
| 91 | +## Quick Start |
| 92 | +Below are a few examples show how to use some of the main features of the library. For more example code, please check out `examples` directory; |
| 93 | +### Query data from the server |
| 94 | +```cpp |
| 95 | +#include <iostream> |
| 96 | + |
| 97 | +#include <opengemini/Client.hpp> |
| 98 | +#include <opengemini/ClientConfigBuilder.hpp> |
| 99 | + |
| 100 | +int main(int argc, char** argv) |
| 101 | +{ |
| 102 | + // Constructs an openGemini client object. |
| 103 | + opengemini::Client client{ opengemini::ClientConfigBuilder() |
| 104 | + // At least one server endpoint needed. |
| 105 | + .AppendAddress({ "127.0.0.1", 8086 }) |
| 106 | + .Finalize() }; |
| 107 | + |
| 108 | + // Performs a query request and print the result, the operation will |
| 109 | + // block until completes or an exception is thrown. |
| 110 | + auto result = client.Query({ |
| 111 | + "ExampleDatabase", |
| 112 | + "select * from ExampleMeasurement", |
| 113 | + }); |
| 114 | + std::cout << result << std::endl; |
| 115 | + |
| 116 | + return 0; |
| 117 | +} |
| 118 | +``` |
| 119 | +### Write points to the server |
| 120 | +```cpp |
| 121 | +#include <iostream> |
| 122 | +
|
| 123 | +#include <opengemini/Client.hpp> |
| 124 | +#include <opengemini/ClientConfigBuilder.hpp> |
| 125 | +
|
| 126 | +int main(int argc, char** argv) |
| 127 | +{ |
| 128 | + // Constructs an openGemini client object. |
| 129 | + opengemini::Client client{ opengemini::ClientConfigBuilder() |
| 130 | + // At least one server endpoint needed. |
| 131 | + .AppendAddress({ "127.0.0.1", 8086 }) |
| 132 | + .Finalize() }; |
| 133 | +
|
| 134 | + // Writes single point to server, the operation will |
| 135 | + // block until completes or an exception is thrown. |
| 136 | + client.Write("ExampleDatabase", |
| 137 | + { |
| 138 | + "ExampleMeasurement", |
| 139 | + { |
| 140 | + { "Weather", "sunny" }, |
| 141 | + { "Humidity", 521 }, |
| 142 | + { "Temperature", 38.1 }, |
| 143 | + }, |
| 144 | + std::chrono::system_clock::now(), |
| 145 | + }); |
| 146 | + return 0; |
| 147 | +} |
| 148 | +``` |
| 149 | + |
| 150 | +## Build From Source |
| 151 | +Make sure all required build tools and dependencies **are installed** on your system, then you can download and build the OpenGeminiCxx library: |
| 152 | +``` |
| 153 | +$ git clone https://github.com/openGemini/opengemini-client-cpp.git |
| 154 | +$ cd opengemini-client-cpp && mkdir build && cd build |
| 155 | +$ cmake .. |
| 156 | +$ make -j |
| 157 | +$ make install |
| 158 | +``` |
| 159 | + |
| 160 | +If you want to enable TLS support, you can configure with `OPENGEMINI_ENABLE_SSL_SUPPORT` option: |
| 161 | +``` |
| 162 | +$ cmake -DOPENGEMINI_ENABLE_SSL_SUPPORT=ON .. |
| 163 | +``` |
| 164 | + |
| 165 | +You can also control generation of unit tests with `OPENGEMINI_BUILD_TESTING` option: |
| 166 | +``` |
| 167 | +$ cmake -DOPENGEMINI_BUILD_TESTING=ON .. |
| 168 | +``` |
| 169 | + |
| 170 | +For details of all the options see [CMake Options](#cmake-options). |
| 171 | + |
| 172 | +## Configuration |
| 173 | +### CMake Options |
| 174 | +|Option|Description|Default Value| |
| 175 | +|:---|:---|:---| |
| 176 | +|OPENGEMINI_ENABLE_SSL_SUPPORT|Enable OpenSSL support for using TLS (**OpenSSL required**)|OFF| |
| 177 | +|OPENGEMINI_BUILD_DOCUMENTATION|Build API documentation (**Doxygen required**)|OFF| |
| 178 | +|OPENGEMINI_BUILD_TESTING|Build unit tests (**GoogleTest required**)|OFF| |
| 179 | +|OPENGEMINI_BUILD_SHARED_LIBS|Build shared libraries instead of static ones. Only has effect if option `OPENGEMINI_BUILD_HEADER_ONLY_LIBS` is `OFF`| OFF| |
| 180 | +|OPENGEMINI_BUILD_EXAMPLE|Build examples|OFF| |
| 181 | +|OPENGEMINI_BUILD_HEADER_ONLY_LIBS|Build as header-only library|OFF| |
| 182 | +|OPENGEMINI_GENERATE_INSTALL_TARGET|Generate the install target, should not be set to `ON` if `OPENGEMINI_USE_FETCHCONTENT` is also `ON`|ON<br>(if is root project)| |
| 183 | +|OPENGEMINI_USE_FETCHCONTENT|Automatically using FetchContent if dependencies not found|OFF<br>(if is root project)| |
0 commit comments