Skip to content

writeRecordsToCsvFile

writeRecordsToCsvFile(records, outputPath, columns): Promise<{ recordCount: number; }>

Defined in: packages/simply-core/src/csv/createCsvFileWriter.ts:103

Stream every record from an async iterable straight into a CSV file via a single stream.pipeline() — source -> a counting pass-through -> csv-stringify -> the file. Use this instead of createCsvFileWriter when every record from a source goes to the same file unconditionally (e.g. dumping a query’s results to disk); pipeline() wires up backpressure and error/completion handling for you, so there’s no manual write-loop or write()/end() bookkeeping. For per-record branching (e.g. routing records to one of several files based on some condition) or writes from concurrent producers, use createCsvFileWriter directly instead.

AsyncIterable<Record<string, unknown>>

The records to write, consumed in order as they’re yielded.

string

The filesystem path to write the CSV file to.

string[]

The column names to use for the header row and field ordering.

Promise<{ recordCount: number; }>

The total number of records written.