Skip to content

CSV generation

nxcsv compiles a delimited source file through a Mustache template into one artifact. Nexus Forge invokes it through an explicit command template. SQL output comes from the selected artifact template and helper, not an inferred format.

Build with nxbuild and Nexus Pascal from the Nexus root. The recipe uses the shared installation settings in NXBuild.Environment.nxscript beside the executable and writes to <Development.OutputRoot>/NexusCSV/<cpu>-<os>/<configuration>.

On Linux:

nxbuild /action=build /project=projects/csv/NexusCSV.nxproject
../../worktree/nexus/NexusCSV/x86_64-linux/Debug/nxcsv \
  /input=../nexus-lab/examples/data/csv/data/lookup/STATE.csv \
  /template=projects/csv/templates/SQL.mustache \
  /output=../../worktree/nexus/state.sql /name=STATE_TBL

On Windows:

nxbuild /action=build /project=projects/csv/NexusCSV.nxproject
& ../../worktree/nexus/NexusCSV/x86_64-win64/Debug/nxcsv.exe `
  /input=../nexus-lab/examples/data/csv/data/lookup/STATE.csv `
  /template=projects/csv/templates/SQL.mustache `
  /output=../../worktree/nexus/state.sql /name=STATE_TBL

Required switches are /input, /template, and /output. /name defaults to the input file stem; /delimiter=comma is the default and /delimiter=tab is supported. Delimiter selection is explicit, not inferred from the filename. Paths are relative to the process working directory. Quote the whole /name=value argument when it contains spaces. The output parent must exist; Nexus Forge packages prepare declared artifact parents. Exit status is zero on success and nonzero on failure.

The first record supplies field names. Empty or duplicate names, malformed quoting, and rows with the wrong number of columns fail compilation. Quoted delimiters, doubled quotes, empty cells, and comma/tab input retain the existing reader behavior. Multiline quoted fields are not supported. Every value remains text; there is no implicit SQL conversion, schema lookup, database connection, or type inference.

Templates receive:

{"DataSource":{"_nx":{"Name":"STATE_TBL","Source":"states.csv"},
 "Fields":["CODE","NAME"],"Records":[["CA","California"]]}}

Ordinary templates use raw values. The explicit helper {{{sql .}}} emits one SQL string literal, including surrounding quotes and doubled apostrophes. O'Brien becomes 'O''Brien'; an empty value becomes '', never NULL. Use this helper only where a SQL string value is intended. It does not quote identifiers.

projects/csv/config/CSV.nxscript supplies the partial CompileCSV configuration. The Nexus Forge Template constructs the command; templates/SQL.mustache is the artifact template supplied to nxcsv, relative to projects/csv. Source, SourceTemplate, and Output are native tool arguments relative to the task working directory. Compiler defaults to nxcsv on PATH and can be supplied explicitly.

The example CSV task is ../nexus-lab/examples/data/csv/Lookup.Forge.nxscript. Put the built executable directory on PATH and run that Nexus Forge document. It writes generated/state.sql on each run.