Skip to content

refactor: modularize source — format, args, sqlite, loader, modes#146

Merged
vmvarela merged 6 commits intomasterfrom
issue-145/refactor-format-abstraction
May 8, 2026
Merged

refactor: modularize source — format, args, sqlite, loader, modes#146
vmvarela merged 6 commits intomasterfrom
issue-145/refactor-format-abstraction

Conversation

@vmvarela
Copy link
Copy Markdown
Owner

@vmvarela vmvarela commented May 8, 2026

Summary

Closes #145. Decomposes the 2308-line main.zig god file into focused modules over 5 phases, all green on tests and linter.

Modules introduced

File Lines Responsibility
src/format.zig 276 InputFormat/OutputFormat enums with parse(), LoadOpts/WriteOpts types, OutputWriter stateful dispatch, writeField
src/args.zig 439 SqlPipeError, ParsedArgs/ColumnsArgs/ValidateArgs/SampleArgs/ArgsResult, parseArgs, printUsage
src/sqlite.zig 264 All SQLite helpers: ColumnType, openDb, createTable, prepareInsertStmt, fatalSqlWithContext, getTableColumns, levenshteinDistance, …
src/loader.zig 468 CSV type inference (isInteger, isReal, inferTypes), parseHeader, insertRowTyped, loadCsvInput, progress helpers
src/modes/columns.zig 204 runColumns--columns mode for all input formats
src/modes/validate.zig 323 runValidate--validate mode for all input formats
src/modes/sample.zig 167 runSample--sample mode for CSV/TSV

Result

src/main.zig: 2308 → 403 lines (83% reduction). It now contains only run, execQuery, fatal, and main.

Adding a new output format now requires touching only format.zig (add a case to OutputWriter.begin/writeRow/end). Adding a new input format requires touching format.zig + one mode file per operational mode.

Commits

  • feat: introduce format.zig with InputFormat, OutputFormat, and OutputWriter
  • refactor: extract CLI argument types and parseArgs into args.zig
  • refactor: consolidate SQLite helpers and ColumnType into sqlite.zig
  • refactor: extract CSV loader and type inference into loader.zig
  • refactor: extract runColumns, runValidate, runSample into src/modes/

vmvarela added 5 commits May 8, 2026 12:03
…Writer

Extracts InputFormat and OutputFormat enums (with parse() methods) and the
writeField CSV helper from main.zig into a new src/format.zig module.
Introduces OutputWriter, a stateful struct that dispatches output formatting
across all five formats (csv, tsv, json, ndjson, xml), eliminating the
format-switch inside execQuery. Closes no issue yet; part of #145.
@vmvarela vmvarela added type:chore Maintenance, refactoring, tooling priority:medium Should be done soon size:l Large — 1 to 2 days labels May 8, 2026
@vmvarela vmvarela merged commit 1e7a70a into master May 8, 2026
4 checks passed
@vmvarela vmvarela deleted the issue-145/refactor-format-abstraction branch May 8, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Should be done soon size:l Large — 1 to 2 days type:chore Maintenance, refactoring, tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: extract format abstraction and modularize source

1 participant