wp-data-fmt
wp-data-fmt is the formatting layer that powers WarpParse style connectors.
It turns wp_model_core::model::DataRecord instances into text so they can be
sent to logs, key/value stores, SQL databases, or snapshot tests. The crate
provides concrete formatters (JSON, CSV, KV, raw, ProtoText, SQL) as well as a
FormatType enum that makes it easy to pick a formatter at runtime from a
TextFmt definition.
Highlights
- Works directly with the strongly typed
wp_model_coredata model. - Consistent escaping rules across JSON, CSV, KV, ProtoText, SQL, and raw text outputs.
- Helpers such as
SqlInsertfor generatingINSERT, batch inserts, table schemas, and UPSERT statements from existing records. - Snapshot-friendly output that is covered by integration tests for each supported format.
Installation
Add the crate through Cargo:
[]
= "0.1"
= "0.7"
Quick start
use NaiveDateTime;
use ;
use ;
use ;
let record = DataRecord ;
let fmt = from;
let line = fmt.format_record;
assert_eq!;
Because every formatter implements the DataFormat trait, the same snippet can
be reused for CSV (FormatType::from(&TextFmt::Csv)), KV, raw, ProtoText, or
custom SQL encodings.
SQL helpers
When you already have a DataRecord named record (and possibly a
Vec<DataRecord> called records) from your ingestion pipeline, SqlInsert
implements DataFormat and adds convenience methods:
use SqlInsert;
let sql = new_with_json.format_record;
// INSERT INTO "nginx_logs" ("ip", "time", ...) VALUES (...);
let batch_sql = new_with_json.format_batch;
let schema = new_with_json.generate_create_table;
let upsert = new_with_json.format_upsert;
Development
This repository follows the Elastic License 2.0 (see Cargo.toml for details).