vantage-csv
CSV backend for the Vantage data framework.
Implements TableSource so that Table<Csv, E> works alongside
Table<SurrealDB, E> (or any other backend) for read operations.
Type system
Like SurrealDB's AnySurrealType (backed by CBOR), vantage-csv defines
AnyCsvType (backed by String) via the vantage_type_system! macro.
Column definitions on the table drive type-safe parsing:
let table = new
.
.
.
.;
When reading a CSV row, each field is parsed according to its column type:
"300"+ column typei64→AnyCsvType { value: "300", variant: Int }"true"+ column typebool→AnyCsvType { value: "true", variant: Bool }"hello"+ no column defined →AnyCsvType { value: "hello", variant: String }
Values can be extracted type-safely:
let price: i64 = record..unwrap;
let name: String = record..unwrap;
Usage
use Csv;
use Table;
use ReadableValueSet;
let csv = new;
let products = new
.
.
.;
let all = products.list.await?;
Each table reads from {base_dir}/{table_name}.csv. The first row is treated
as headers and every subsequent row becomes a record.
ID column
By default the id column is used as the record identifier. Override with:
let csv = new.with_id_column;
If the CSV has no matching column, row indices (starting at 0) are used instead.
Embedded JSON
Object/array fields can be stored as quoted JSON strings in CSV:
id,name,inventory
1,Widget,"{""stock"":50}"
Define the column as serde_json::Value to parse it:
table.
Read-only
CSV is a read-only data source. Write operations (insert, replace,
patch, delete) return errors at runtime.
License
MIT OR Apache-2.0