C API¶
The public C API is declared in include/tsedge.h. This page gives the shape of the API and the common call flow. For exact signatures, use the header as the source of truth.
Opening and closing¶
tsedge_opentsedge_close
tsedge_open opens or creates a database directory. tsedge_close flushes pending data and releases the database handle.
Passing NULL to tsedge_close is safe, which makes cleanup paths simpler.
Series management¶
tsedge_create_seriestsedge_delete_seriestsedge_list_seriestsedge_free_series_listtsedge_get_series_handle
Series handles are database-owned and can speed up repeated writes to the same series.
Use names for simple code and handles for hot write paths. A handle stays valid until the series is deleted or the database is closed.
Writing points¶
tsedge_appendtsedge_append_batchtsedge_append_handletsedge_append_batch_handletsedge_flushtsedge_flush_all
Batch writes avoid repeating public validation and series lookup for every point. They are faster than calling tsedge_append in a loop, especially when combined with a series handle.
If a batch fails partway through, accepted points before the error may remain stored. TSEdge does not provide all-or-nothing batch transactions.
Reading and aggregates¶
tsedge_read_rangetsedge_aggregatetsedge_aggregate_windowedtsedge_free_window_aggregates
Range reads stream points through a callback. Aggregates are computed while scanning candidate blocks. Windowed aggregates return compact non-empty time windows.
Use tsedge_read_range when the application needs raw points. Use tsedge_aggregate or tsedge_aggregate_windowed when a summary is enough.
Quota, retention and verification¶
tsedge_set_disk_quotatsedge_get_disk_quotatsedge_enforce_disk_quotatsedge_delete_beforetsedge_verifytsedge_get_series_stats
Retention and quota cleanup work at segment-file granularity. Verification inspects database files without repairing them.
tsedge_verify is useful in tests, diagnostics and maintenance tools. It reports the first structural problem found.
CSV export and errors¶
tsedge_export_csvtsedge_strerror
API calls return integer status codes. TSEDGE_OK means success; negative values indicate validation, I/O, memory, not-found, corruption, quota or internal errors.
Library code does not call exit() and does not print diagnostics. Applications decide how to report or recover from errors.
Minimal example¶
#include <tsedge.h>
#include <stdio.h>
int main(void) {
tsedge_db* db = NULL;
if (tsedge_open("demo_db", &db) != TSEDGE_OK) {
return 1;
}
tsedge_create_series(db, "air.temperature");
tsedge_append(db, "air.temperature", 1, 10.0);
tsedge_append(db, "air.temperature", 2, 20.0);
double avg = 0.0;
tsedge_aggregate(
db,
"air.temperature",
1,
3,
TSEDGE_AGG_AVG,
&avg
);
printf("avg = %.3f\n", avg);
tsedge_close(db);
return 0;
}