Purpose
The **MSSQL Query to CSV** program is a command-line tool written in Rust that connects to a Microsoft SQL Server database, executes a SQL query, and exports the results to a CSV file. It supports configurable delimiters, quote characters, header inclusion, and command-line overrides for flexibility.
Current state
Last touched: 2025-02-10. Functionality and completeness: Single-query export is implemented; retries and tests are not documented.
Next step
Add baseline automated tests to cover critical flows; Add CI pipeline for build/test/lint; Document deployment/runtime environment (or add Dockerfile); Document interfaces (CLI flags, API endpoints, file formats); Add structured logging and basic health checks.
Interfaces
Inputs- TOML config, SQL Server via ODBC DSN
- Configuration files (TOML)
- SQL query text
Reality to Action trace
Reality IngestionContributes in this stage.
Canonical StorageContributes in this stage.
Automation EnginesNot in scope.
Human InterfacesContributes in this stage.
Operational AdoptionContributes in this stage.
Core workflow
TBD. Document the 5-10 steps that define the core workflow.
Operational notes
Constraints and scars
- Limited to SQL Server via ODBC; requires local ODBC driver configuration.
Reliability posture
Failure modes and safe behavior: ODBC connection failures or SQL errors abort the run without writing partial output. Idempotency / retries / batching behavior: Re-running overwrites the output file; no built-in retries.
Observability
- Metrics/health checks: None documented
- Logs: stdout/stderr from CLI; no structured logging noted in README.
Security and privacy
Config files contain credentials; restrict access and avoid committing them.
Dependencies
Upstream- Microsoft SQL Server via ODBC
Ownership
OwnersJosh Barton
UsersJosh Barton (owner)
mssql_query_to_csv
Architecture & Major Components
High-level diagram (text):
- Entry/trigger -> core logic -> outputs (details per docs below)
Entry/trigger
→core logic
→outputs
Entry points: src/main.rs
Top-level folders: src
Key abstractions: Config parsing, ODBC query execution, CSV writer with configurable delimiters and quoting
Setup / Build / Run
- Build system(s): Cargo.
- Install Rust, UnixODBC, and the Microsoft ODBC driver for SQL Server.
- Configure
odbcinst.ini / odbc.ini, then create a config.toml with DSN and SQL. - Build with Cargo and run
mssql_query_to_csv --config config.toml.