D8What it costs the developer
Can we upload a spreadsheet?
Every client asks eventually. It looks like an afternoon until you meet column mapping, partial failure, forty thousand rows and the one date the parser hates.
What actually goes wrong
The afternoon version reads a CSV and inserts rows. The real version maps columns from a header nobody standardised, validates each row, reports row 17 without discarding rows 1 to 16, handles a file larger than memory, and tells the user what to fix.
Export has the same shape: it must honour the filters the user is looking at, or the numbers in the file disagree with the numbers on the screen.
What Grit does about it
- Every generated resource gets CSV import and Excel export, with a dry run that validates before anything is written and per-row errors rather than one failure for the file.
- Export honours the filters currently applied to the list.
- Both are ordinary Go in your project: internal/handlers/<resource>_import.go and its service half.
The commands
Generated with the resource
grit generate resource Invoice --fields "number:string, total:money"
Large imports, bounded
IMPORT_CONCURRENCY=4 grit start
What it does not do
Column mapping is matched from the header. A file whose columns are named in another language, or not named at all, needs a mapping you write.
