- To begin with, we suggest first building the library to ensure you have all the tooling and build dependencies set up just right by following the build instructions
- Then read the guide for including this library as a dependency from your project.
Basic Usage
Authentication & Security
Configuration
HTTP
Array Handling
- Array with byte strides
- Array with element strides
- Array in C-major order
- Custom array type integration
Decimal
When you send data to a table that does not yet exist, QuestDB creates the table automatically and infers column types from the first row. The same applies to brand-new columns added to an existing table: most column types are created on the fly based on the values you send. Decimal columns are the main exception.
Because the client cannot infer the desired scale and precision, QuestDB refuses to auto-create decimal columns.
Define those columns ahead of time with an explicit create table (or alter table add column) statement before you start sending decimal values.
#include <questdb/ingress/line_sender.hpp>
...
auto sender = questdb::ingress::line_sender::from_conf(
"http::addr=localhost:9000;");
See the main client libraries documentation for the full config string params, including authentication, tls, etc.
You can also connect programmatically using the questdb::ingress::opts object.
The line_sender object is responsible for connecting to the network and
sending data.
Use the line_sender_buffer type to construct messages (aka rows, aka records,
aka lines).
To avoid malformed messages, the line_sender_buffer object's methods
must be called in a specific order.
For each row, you need to specify a table name and at least one symbol or column. Symbols must be specified before columns.
You can accumulate multiple lines (rows) with a given buffer and a buffer is
re-usable, but a buffer may only be flushed via the sender after a call to
buffer.at(..) (preferred) or buffer.at_now().
questdb::ingress::line_sender_buffer buffer;
buffer
.table("trades")
.symbol("symbol", "ETH-USD")
.column("price", "2615.54"_decimal)
.at(timestamp_nanos::now());
// To insert more records, call `buffer.table(..)...` again.
sender.flush(buffer);Diagram of valid call order of the buffer API.
Note that most methods in C++ may throw questdb::ingress::line_sender_error
exceptions. The C++ line_sender_error type inherits from std::runtime_error
and you can obtain an error message description by calling .what() and an
error code calling .code().