Skip to content

CsvCrate

Reads and writes items from a CSV file. Each row is a record, with the first row as the header.

import crate.collection.csv;
auto products = new CsvCrate!Product("data/products.csv");
router.crateSetup!RestApi.add(products);
  • Storage: Flat CSV file on disk
  • Header: First line defines field names
  • ID: Uses _id field if present, otherwise line number
  • Reads: Parses the entire file on each query
  • Writes: Rewrites the file on insert/update/delete

Supports dot-notation for nested structs:

_id,name,position.type,position.lat,position.lng
1,Headquarters,Point,52.5,13.4

Maps to:

{
"_id": "1",
"name": "Headquarters",
"position": { "type": "Point", "lat": 52.5, "lng": 13.4 }
}
  • Importing/exporting flat data
  • Small, rarely-written datasets
  • Quick prototyping without a database

Not suited for concurrent writes or large datasets — the entire file is read and rewritten on every operation.