Skip to content
Open
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
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ arrow-schema = "59.3.0"
clap = { version = "4.6.7", features = ["derive"] }
comfy-table = "8.0.1"
nu-ansi-term = "0.50.3"
parquet = { version = "59.3.0", default-features = false, features = ["arrow", "snap"] }
reedline = "0.52.0"
syntect = "5.3.0"
terminal-colorsaurus = "1.0.3"
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A command-line tool for querying databases via [ADBC](https://arrow.apache.org/a
- **Interactive SQL shell** - Execute SQL queries with command history and intuitive navigation
- **Syntax highlighting** - SQL queries highlighted for improved readability
- **Formatted output** - Results displayed in clean, aligned tables with dynamic column width
- **File export** - Export query results to JSON, CSV, or Arrow IPC files
- **File export** - Export query results to JSON, JSON lines, CSV, Arrow IPC, or Parquet files
- **Fast and lightweight** - Built in Rust for high performance and minimal resource usage

## Installation
Expand Down Expand Up @@ -107,8 +107,11 @@ Execute a query and output the result to a file:

```sh
databow --driver duckdb --query "SELECT 42 AS the_answer" --output result.json
databow --driver duckdb --query "SELECT 42 AS the_answer" --output result.jsonl
databow --driver duckdb --query "SELECT 42 AS the_answer" --output result.csv
databow --driver duckdb --query "SELECT 42 AS the_answer" --output result.arrow
databow --driver duckdb --query "SELECT 42 AS the_answer" --output result.arrows
databow --driver duckdb --query "SELECT 42 AS the_answer" --output result.parquet
```

## Reference
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ databow is a command-line tool for querying databases.
- **Interactive SQL shell** - Execute SQL queries with command history and intuitive navigation
- **Syntax highlighting** - SQL queries highlighted for improved readability
- **Formatted output** - Results displayed in clean, aligned tables with dynamic column width
- **File export** - Export query results to JSON, CSV, or Arrow IPC files
- **File export** - Export query results to JSON, JSON lines, CSV, Arrow IPC, or Parquet files
- **Fast and lightweight** - Built in Rust for high performance and minimal resource usage
13 changes: 8 additions & 5 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ databow --driver duckdb --query "SELECT 42 AS the_answer" --output result.json

The output format is inferred from the file extension:

| Extension | Format |
|-----------------|-----------|
| `.json` | JSON |
| `.csv` | CSV |
| `.arrow`, `.ipc`| Arrow IPC |
| Extension | Format |
|-----------------|------------------|
| `.json` | JSON |
| `.jsonl` | JSON lines |
| `.csv` | CSV |
| `.arrow`, `.ipc`| Arrow IPC file |
| `.arrows` | Arrow IPC stream |
| `.parquet` | Parquet |

## --help

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ $ databow --profile warehouse --file query.sql
└───────────────────┘
```

Instead of printing query results to stdout, the [`--output` argument](/reference/#-output) can be used to write results to JSON, CSV, or Arrow IPC files:
Instead of printing query results to stdout, the [`--output` argument](/reference/#-output) can be used to write results to JSON, JSON lines, CSV, Arrow IPC file, Arrow IPC stream, or Parquet files:

```console
$ databow --profile warehouse --query "SELECT * FROM penguins" --output penguins.csv
Expand Down
32 changes: 30 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2026 Columnar Technologies Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::output::OutputFormat;
use crate::table::TableMode;
use clap::{Arg, ArgAction, Command, value_parser};
use std::path::PathBuf;
Expand Down Expand Up @@ -84,7 +85,8 @@ pub fn parse_args() -> AppConfig {
Arg::new("output")
.long("output")
.help("Write result to file")
.value_name("file"),
.value_name("file")
.value_parser(parse_output_path),
];
let command = Command::new("databow")
.version(env!("CARGO_PKG_VERSION"))
Expand Down Expand Up @@ -163,7 +165,7 @@ pub fn parse_args() -> AppConfig {
.copied()
.unwrap_or_default();

let output_path = matches.get_one::<String>("output").map(PathBuf::from);
let output_path = matches.get_one::<PathBuf>("output").cloned();
if output_path.is_some() && matches!(query_source, QuerySource::Interactive) {
eprintln!("Error: --output cannot be used in interactive mode");
exit(1);
Expand All @@ -177,6 +179,12 @@ pub fn parse_args() -> AppConfig {
}
}

fn parse_output_path(s: &str) -> Result<PathBuf, String> {
let path = PathBuf::from(s);
OutputFormat::from_path(&path)?;
Ok(path)
}

fn uri_has_driver_scheme(uri: &str) -> bool {
let Some(idx) = uri.find(':') else {
return false;
Expand All @@ -202,6 +210,26 @@ fn parse_option(option: &str) -> Result<(String, String), String> {
mod tests {
use super::*;

#[test]
fn test_parse_output_path_valid() {
assert_eq!(
parse_output_path("out.parquet").unwrap(),
PathBuf::from("out.parquet")
);
}

#[test]
fn test_parse_output_path_unsupported_extension() {
let err = parse_output_path("out.xyz").unwrap_err();
assert!(err.contains("Unsupported file extension"));
}

#[test]
fn test_parse_output_path_no_extension() {
let err = parse_output_path("out").unwrap_err();
assert!(err.contains("no file extension"));
}

#[test]
fn test_connection_source_direct() {
let source = ConnectionSource::Direct {
Expand Down
Loading
Loading