rust-sql-extractor
A Rust library and CLI tool for extracting structured data from SQL databases (MSSQL) to Delta Lake, Parquet, CSV, and JSON formats.
Features
- Metadata Extraction — Discover schemas, tables, columns, primary/foreign keys, indexes, CDC, and Change Tracking status
- Extraction Advisor — Recommends optimal extraction strategy (CDC, Change Tracking, Watermark, or Full) per table
- Data Extraction — Stream data to Delta Lake, CSV, or JSON Lines with resumable state
- Catalog Management — Persistent metadata and extraction configuration
- Scheduled Extractions — Cron-based recurring extraction jobs with per-schedule table selection
Installation
Prerequisites
- Rust 1.75+ (install via rustup)
- Access to a SQL Server database
Install CLI from Source
# Clone the repository
git clone https://github.com/ArthurSteijn/rust-sql-extractor.git
cd rust-sql-extractor
# Install with all features
cargo install --path . --features mssql,delta,ui
The binary sql-extractor will be installed to ~/.cargo/bin/ (should be in your PATH).
Build Without Installing
Configuration
Set your connection string via environment variable:
$env:MSSQL_CONN = "Server=tcp:your-server.database.windows.net,1433;Database=yourdb;User ID=user;Password=pass;TrustServerCertificate=False;Connection Timeout=30;"
Or use a .env file (copy from .env.example).
CLI Usage
# Show help
sql-extractor --help
# Extract metadata to JSON files
sql-extractor metadata --format json --output ./metadata
# Display metadata as tables
sql-extractor metadata
# Generate extraction recommendations
sql-extractor advise
# Extract specific tables to Delta format
sql-extractor extract --tables "SalesLT.Customer,SalesLT.Product" --format delta
# Extract to CSV
sql-extractor extract --tables "SalesLT.Customer" --format csv --output ./exports
# Launch the web UI (alias: `ui`)
sql-extractor start --port 8080
# Run the headless scheduler (no browser UI)
sql-extractor schedule
# Run the headless scheduler with API access
sql-extractor schedule --api --port 8080
Global Options
| Option | Default | Description |
|---|---|---|
--connection |
$MSSQL_CONN |
Database connection string |
--output, -o |
./output |
Output directory for extracted data |
--catalog-dir |
./catalog |
Directory for persistent catalog state |
Library Usage
See EXAMPLES.md for code examples.
Development
# Format code
cargo fmt
# Lint
cargo clippy --all-targets --all-features -- -D warnings
# Run unit tests
cargo test
# Run integration tests (requires MSSQL_CONN)
cargo test --features mssql,delta -- --nocapture
Demo Database Seeding
To generate ongoing small INSERT, UPDATE, and DELETE changes in the demo SalesLT database (both Watermark and CDC tables) for testing incremental extraction:
# Default: run for 30 minutes, applying small batches every 15 seconds
.\scripts\seed-demo.ps1
# Check target tables without writing
.\scripts\seed-demo.ps1 -DryRun
# Remove all seeded rows when done
.\scripts\seed-demo.ps1 -Cleanup
See DEMO_SEEDING.md for all options and standalone T-SQL usage.
License
MIT