Skip to main content

sql_to_csv/
cli.rs

1use std::path::PathBuf;
2
3use clap::Parser;
4
5/// Fast, parallel SQL dump to CSV/TSV converter.
6///
7/// Extracts data from SQL dumps (MySQL, PostgreSQL, SQL Server, Oracle, SQLite)
8/// into clean CSV/TSV files — one per table. Optionally generates PostgreSQL DDL.
9/// Auto-detects the source dialect, or specify it with --dialect.
10#[derive(Parser, Debug)]
11#[command(name = "sql-to-csv", version, about)]
12pub struct Cli {
13    /// Input SQL dump file (.sql or .sql.gz)
14    pub input: PathBuf,
15
16    /// Output directory
17    pub out_dir: PathBuf,
18
19    /// Source SQL dialect (auto-detected if not specified)
20    ///
21    /// Supported: mysql, postgresql (pg), mssql (sqlserver), oracle, sqlite
22    #[arg(long)]
23    pub dialect: Option<String>,
24
25    /// Overwrite output directory if it already exists
26    #[arg(long, short = 'f')]
27    pub force: bool,
28
29    /// Only emit DDL (schema.sql), no data files
30    #[arg(long)]
31    pub schema_only: bool,
32
33    /// Only emit data files, skip DDL conversion
34    #[arg(long)]
35    pub data_only: bool,
36
37    /// Comma-separated allowlist of table names to extract
38    #[arg(long, value_delimiter = ',')]
39    pub tables: Option<Vec<String>>,
40
41    /// Number of parallel workers (default: number of CPU cores)
42    #[arg(long)]
43    pub workers: Option<usize>,
44
45    /// Rotate/shard CSV every N rows per table
46    #[arg(long)]
47    pub shard_rows: Option<usize>,
48
49    /// Disable DDL conversion (skip schema.sql generation)
50    #[arg(long)]
51    pub no_postgres_ddl: bool,
52
53    /// Parse and count rows only, without writing output
54    #[arg(long)]
55    pub dry_run: bool,
56
57    /// NULL marker string for CSV output (default: \N)
58    #[arg(long, default_value = "\\N")]
59    pub null_marker: String,
60
61    /// Output TSV (tab-separated) instead of CSV
62    #[arg(long)]
63    pub tsv: bool,
64
65    /// CSV delimiter character (ignored if --tsv is set)
66    #[arg(long, default_value = ",")]
67    pub delimiter: String,
68}
69
70/// Return the clap Command for man page / completion generation.
71#[allow(dead_code)]
72pub fn command() -> clap::Command {
73    <Cli as clap::CommandFactory>::command()
74}