refactor: modularize source — format, args, sqlite, loader, modes#146
Merged
refactor: modularize source — format, args, sqlite, loader, modes#146
Conversation
…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.
…ard XML validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #145. Decomposes the 2308-line
main.ziggod file into focused modules over 5 phases, all green on tests and linter.Modules introduced
src/format.zigInputFormat/OutputFormatenums withparse(),LoadOpts/WriteOptstypes,OutputWriterstateful dispatch,writeFieldsrc/args.zigSqlPipeError,ParsedArgs/ColumnsArgs/ValidateArgs/SampleArgs/ArgsResult,parseArgs,printUsagesrc/sqlite.zigColumnType,openDb,createTable,prepareInsertStmt,fatalSqlWithContext,getTableColumns,levenshteinDistance, …src/loader.zigisInteger,isReal,inferTypes),parseHeader,insertRowTyped,loadCsvInput, progress helperssrc/modes/columns.zigrunColumns—--columnsmode for all input formatssrc/modes/validate.zigrunValidate—--validatemode for all input formatssrc/modes/sample.zigrunSample—--samplemode for CSV/TSVResult
src/main.zig: 2308 → 403 lines (83% reduction). It now contains onlyrun,execQuery,fatal, andmain.Adding a new output format now requires touching only
format.zig(add a case toOutputWriter.begin/writeRow/end). Adding a new input format requires touchingformat.zig+ one mode file per operational mode.Commits
feat: introduce format.zig with InputFormat, OutputFormat, and OutputWriterrefactor: extract CLI argument types and parseArgs into args.zigrefactor: consolidate SQLite helpers and ColumnType into sqlite.zigrefactor: extract CSV loader and type inference into loader.zigrefactor: extract runColumns, runValidate, runSample into src/modes/