Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ exclude = [
name = "sql-splitter"
path = "src/main.rs"

[features]
default = ["duckdb-query", "compression"]
duckdb-query = ["dep:duckdb", "compression"]
compression = ["dep:flate2", "dep:bzip2", "dep:xz2", "dep:zstd"]

[dependencies]
clap = { version = "4", features = ["derive"] }
clap_complete = "4"
Expand All @@ -38,10 +43,10 @@ memchr = "2"
once_cell = "1"
ahash = "0.8"
anyhow = "1"
flate2 = "1"
bzip2 = "0.6"
xz2 = "0.1"
zstd = "0.13"
flate2 = { version = "1", optional = true }
bzip2 = { version = "0.6", optional = true }
xz2 = { version = "0.1", optional = true }
zstd = { version = "0.13", optional = true }
indicatif = "0.18"
rand = "0.10"
smallvec = { version = "1.13", features = ["union"] }
Expand All @@ -53,7 +58,7 @@ serde_yaml_ng = "0.10"
fake = { version = "5", features = ["derive"] }
sha2 = "0.11"
hex = "0.4"
duckdb = { version = "1.10502", features = ["bundled"] }
duckdb = { version = "1.10502", features = ["bundled"], optional = true }
dirs = "6"
rustyline = "17"
schemars = "1"
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ Split large SQL dump files into individual table files. Fast, memory-efficient,
cargo install sql-splitter
```

### Cargo features (library consumers)

`sql-splitter` enables all features by default. To reduce dependency footprint:

```toml
sql-splitter = { version = "1", default-features = false }
```

Optional features:

- `compression` (gzip/bzip2/xz/zstd support)
- `duckdb-query` (enables the `query` command and DuckDB integration)

### From source

```bash
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod glob_util;
pub(crate) mod graph;
pub(crate) mod merge;
mod order;
#[cfg(feature = "duckdb-query")]
mod query;
pub(crate) mod redact;
pub(crate) mod sample;
Expand Down Expand Up @@ -700,6 +701,7 @@ pub enum Commands {
},

/// Query SQL dumps using DuckDB's analytical engine
#[cfg(feature = "duckdb-query")]
#[command(visible_alias = "qy")]
#[command(after_help = "\x1b[1mExamples:\x1b[0m
sql-splitter query dump.sql \"SELECT COUNT(*) FROM users\"
Expand Down Expand Up @@ -1055,6 +1057,7 @@ pub fn run(cli: Cli) -> anyhow::Result<()> {
dry_run,
reverse,
} => order::run(file, output, dialect, check, dry_run, reverse),
#[cfg(feature = "duckdb-query")]
Commands::Query(args) => query::run(args),
Commands::Schema {
output,
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! # Features
//!
//! - **Zero dependencies**: DuckDB is bundled and compiled into sql-splitter
//! - **Bundled engine**: DuckDB is embedded via the optional `duckdb-query` feature
//! - **Multi-dialect support**: MySQL, PostgreSQL, and SQLite dumps
//! - **Memory management**: Auto-switches to disk mode for large dumps
//! - **Caching**: Optional persistent cache for repeated queries
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod analyzer;
pub mod cmd;
pub mod convert;
pub mod differ;
#[cfg(feature = "duckdb-query")]
pub mod duckdb;
pub mod graph;
pub mod json_schema;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod analyzer;
mod cmd;
mod convert;
mod differ;
#[cfg(feature = "duckdb-query")]
mod duckdb;
mod graph;
mod json_schema;
Expand Down
11 changes: 11 additions & 0 deletions src/splitter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,21 @@ impl Compression {
) -> std::io::Result<Box<dyn Read + 'a>> {
Ok(match self {
Compression::None => reader,
#[cfg(feature = "compression")]
Compression::Gzip => Box::new(flate2::read::GzDecoder::new(reader)),
#[cfg(feature = "compression")]
Compression::Bzip2 => Box::new(bzip2::read::BzDecoder::new(reader)),
#[cfg(feature = "compression")]
Compression::Xz => Box::new(xz2::read::XzDecoder::new(reader)),
#[cfg(feature = "compression")]
Compression::Zstd => Box::new(zstd::stream::read::Decoder::new(reader)?),
#[cfg(not(feature = "compression"))]
_ => {
return Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"compressed input requires the `compression` feature",
))
}
})
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/splitter_unit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn test_splitter_data_only() {
}

#[test]
#[cfg(feature = "compression")]
fn test_splitter_gzip_compressed() {
use flate2::write::GzEncoder;
use flate2::Compression as GzCompression;
Expand All @@ -135,6 +136,29 @@ fn test_splitter_gzip_compressed() {
assert!(output_dir.join("users.sql").exists());
}

#[test]
#[cfg(not(feature = "compression"))]
fn test_splitter_compressed_input_requires_feature() {
let temp_dir = TempDir::new().unwrap();
let input_file = temp_dir.path().join("input.sql.gz");
let output_dir = temp_dir.path().join("output");

std::fs::write(
&input_file,
b"\x1f\x8b\x08\x00\\\x06\x03j\x02\xffs\x0eru\x0cqU\x08qt\xf2qU(-N-*V\xd0\xc8LQ\xf0\xf4\x0b\xd1\xb4\xe6\x02\x00^\xb7Dc\x1d\x00\x00\x00",
)
.unwrap();

let splitter = Splitter::new(input_file, output_dir);
let err = match splitter.split() {
Ok(_) => panic!("expected compressed input to fail without `compression` feature"),
Err(err) => err,
};
assert!(err
.chain()
.any(|cause| cause.to_string() == "compressed input requires the `compression` feature"));
}

#[test]
fn test_compression_detection() {
assert_eq!(
Expand Down
Loading