# rsql [![ci](https://github.com/theseus-rs/rsql/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/theseus-rs/rsql/actions/workflows/ci.yml) [![Documentation](https://docs.rs/rsql_core/badge.svg)](https://docs.rs/rsql_core) [![Code Coverage](https://codecov.io/gh/theseus-rs/rsql/branch/main/graph/badge.svg)](https://codecov.io/gh/theseus-rs/rsql) [![Latest version](https://img.shields.io/crates/v/rsql_cli.svg)](https://crates.io/crates/rsql_cli) [![Github All Releases](https://img.shields.io/github/downloads/theseus-rs/rsql/total.svg)](https://theseus-rs.github.io/rsql/rsql_cli/) [![License](https://img.shields.io/crates/l/rsql_cli)](https://github.com/theseus-rs/rsql_cli#license) [![Semantic Versioning](https://img.shields.io/badge/%E2%9A%99%EF%B8%8F_SemVer-2.0.0-blue)](https://semver.org/spec/v2.0.0.html) > A modern, feature-rich command line SQL interface for data `rsql` is a powerful and user-friendly command line SQL client that works with over 20 different data sources and formats. Whether you're working with databases, files, or cloud services, `rsql` provides a consistent and intuitive interface for all your data querying needs. ## Highlights - **Universal SQL Interface**: Query databases, files, and cloud services with standard SQL - **Rich Interactive Experience**: Syntax highlighting, auto-completion, and command history - **Multiple Output Formats**: ASCII tables, JSON, CSV, HTML, and more - **Extensive Data Source Support**: PostgreSQL, MySQL, SQLite, DuckDB, Parquet, CSV, Excel, and many more - **Compression Support**: Automatically handles compressed files (gzip, brotli, etc.) - **Embedded Database**: Run PostgreSQL queries without external setup - **Multilingual**: Interface available in 40+ languages [demo.webm](https://github.com/user-attachments/assets/613fdefb-753a-4bb2-acd2-66539d4f2068) ## Quick Start ### Installation **Linux / MacOS:** ```shell curl --proto '=https' --tlsv1.2 -LsSf https://github.com/theseus-rs/rsql/releases/latest/download/rsql_cli-installer.sh | sh ``` or [Homebrew](https://brew.sh/): ```shell brew install rsql ``` **Windows:** ```shell irm https://github.com/theseus-rs/rsql/releases/latest/download/rsql_cli-installer.ps1 | iex ``` **Cargo** ```shell cargo install rsql_cli ``` For detailed installation instructions, visit the [rsql documentation](https://theseus-rs.github.io/rsql/rsql_cli/). ### Basic Usage **Interactive Mode:** ```shell # Connect to a database rsql --url "postgresql://user:pass@localhost/mydb" # Query a CSV file rsql --url "csv://data.csv" # Use DuckDB for in-memory analytics rsql --url "duckdb://" ``` **Execute Single Query:** ```shell # Run a query and exit rsql --url "sqlite://database.db" -- "SELECT * FROM users LIMIT 10" # Query a Parquet file rsql --url "parquet://data.parquet" -- "SELECT column1, COUNT(*) FROM table GROUP BY column1" ``` ## Supported Data Sources ### Databases - **ClickHouse** (`clickhouse://`) - **CockroachDB** (`cockroachdb://`) - **CrateDB** (`cratedb://`) - **DuckDB** (`duckdb://`) - High-performance analytics - **DynamoDB** (`dynamodb://`) - **LibSQL/Turso** (`libsql://`) - **MySQL** / **MariaDB** (`mysql://` / `mariadb://`) - **PostgreSQL** (`postgresql://` / `postgres://`) - Including embedded PostgreSQL - **Redshift** (`redshift://`) - **ScyllaDB** (`scylladb://`) - Including Scylla Cloud TLS and private Client Routes - **Snowflake** (`snowflake://`) - **SQL Server** (`sqlserver://`) - **SQLite** (`sqlite://` / `rusqlite://`) ### File Formats - **Arrow** (`arrow://`) - In-memory columnar format - **Avro** (`avro://`) - Binary serialization format - **CSV/TSV** (`csv://` / `tsv://`) - Comma/tab-separated values - **Excel** (`excel://`) - .xlsx and .xls files - **Fixed Width** (`fwf://`) - Fixed-width format - **JSON/JSONL** (`json://` / `jsonl://`) - JSON documents - **ODS** (`ods://`) - OpenDocument Spreadsheet - **ORC** (`orc://`) - Optimized row columnar format - **Parquet** (`parquet://`) - Columnar storage format - **XML** (`xml://`) - XML documents - **YAML** (`yaml://`) - YAML documents ### Cloud & Remote - **FlightSQL** (`flightsql://`) - Apache Arrow Flight SQL - **HTTP/HTTPS** (`http://` / `https://`) - Remote files - **S3** (`s3://`) - Amazon S3 and S3-compatible storage ### Compression Automatically handles: Gzip, Brotli, Bzip2, LZ4, XZ, Zstd ## Common Use Cases ### Database Operations ```shell # Connect to PostgreSQL rsql --url "postgresql://user:pass@localhost/mydb" # Use embedded PostgreSQL (no external setup required) rsql --url "postgresql://?embedded=true" # SQLite file rsql --url "sqlite://database.db" # ScyllaDB keyspace rsql --url "scylladb://localhost:9042/my_keyspace" ``` ### File Analysis ```shell # Analyze CSV data rsql --url "csv://sales.csv" -- "SELECT region, SUM(revenue) FROM table GROUP BY region" # Query Excel spreadsheet rsql --url "excel://report.xlsx" -- "SELECT * FROM table WHERE amount > 1000" # Analyze Parquet files rsql --url "parquet://logs.parquet" -- "SELECT date, COUNT(*) FROM table GROUP BY date" ``` ### Data Transformation ```shell # Convert CSV to JSON rsql --url "csv://input.csv" --format json -- "SELECT * FROM input" # Query compressed files rsql --url "csv://data.csv.gz" -- "SELECT column1, column2 FROM data" # Combine multiple formats rsql --url "duckdb://" -- " SELECT * FROM read_csv_auto('file1.csv') UNION ALL SELECT * FROM read_parquet('file2.parquet') " ``` ## Advanced Features ### Output Formats Control output with `--format`: - `ascii` - ASCII table (default) - `csv` - Comma-separated values - `html` - HTML table - `json` - JSON format - `markdown` - Markdown table - `xml` - XML format - `yaml` - YAML format - And more... ### Configuration ```shell # Set default format rsql --url "sqlite://db.sqlite" --format json # Custom delimiter for CSV output rsql --url "postgresql://..." --format csv --delimiter ";" # Expanded output for wide tables rsql --url "..." --format expanded ``` ## Examples ### File Format Examples **CSV with custom options:** ```shell rsql --url "csv://data.csv?has_header=true&skip_rows=1" ``` **Fixed-width file:** ```shell rsql --url "fwf://data.txt?widths=10,20,15&headers=id,name,email" ``` **Delimited file with custom separator:** ```shell rsql --url "delimited://data.txt?separator=|&has_header=true" ``` ### Database Examples **PostgreSQL with SSL:** ```shell rsql --url "postgresql://user:pass@localhost/db?sslmode=require" ``` **MySQL with charset:** ```shell rsql --url "mysql://user:pass@localhost/db?charset=utf8mb4" ``` ## Features | Feature | Description | |-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Data Sources | Arrow, Avro, ClickHouse, CockroachDB, CrateDB, CSV, Delimited, DuckDB, DynamoDB, Excel, FlightSQL, FWF, JSON, JSONL, LibSQL (Turso), MariaDB, MySQL, ODS, ORC, Parquet, PostgreSQL, Redshift, ScyllaDB, Snowflake, SQLite3, SQL Server, TSV, XML, YAML | | Compression | Brotli, Bzip2, Gzip, LZ4, XZ, Zstd | | Syntax Highlighting | ✅ Full SQL syntax highlighting | | Result Highlighting | ✅ Color output for better readability | | Query Auto-completion | ✅ Smart completion for SQL keywords and table names | | History | ✅ Command history with search | | SQL File Execution | ✅ Execute .sql files directly | | Embedded PostgreSQL | ✅ No external PostgreSQL installation required | | Output Formats | ascii, csv, expanded, html, json, jsonl, markdown, plain, psql, sqlite, tsv, unicode, xml, yaml | | Localized Interface | 40+ languages¹ | | Key Bindings | emacs, vi | ¹ Computer translations; human translations welcome ## Connection URLs | Driver | URL | |--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | arrow (polars) | `arrow://` | | avro (polars) | `avro://` | | brotli¹ | `brotli://` | | bzip2¹ | `bzip2://` | | clickhouse | `clickhouse://[:]@[:]/[?access_token=][&scheme=]` | | cockroachdb (sqlx) | `cockroachdb://[:]@[:]/` | | cratedb (sqlx) | `cratedb://[:]@[:]/` | | csv (polars) | `csv://[?has_header=]["e=][&skip_rows=]` | | delimited (polars) | `delimited://[?separator=][&has_header=]["e=][&skip_rows=]` | | duckdb | `duckdb://[]` | | dynamodb | `dynamodb://[:@][:]>[?region=][&session_token=][&scheme=]` | | excel | `excel://[?has_header=][&skip_rows=]` | | file¹ | `file://` | | flightsql | `flightsql://]@[:][?scheme=]` | | fwf | `fwf://?widths=[&headers=]` | | gzip¹ | `gzip://` | | http¹ | `http://[?_headers=]` | | https¹ | `https://[?_headers=]` | | json (polars) | `json://` | | jsonl (polars) | `jsonl://` | | libsql² | `libsql://?[][&file=][&auth_token=]` | | lz4¹ | `lz4://` | | mariadb (sqlx) | `mariadb://[:]@[:]/` | | mysql (sqlx) | `mysql://[:]@[:]/` | | ods | `ods://[?has_header=][&skip_rows=]` | | orc | `orc://` | | parquet (polars) | `parquet://` | | postgres | `postgres://[:]@[:]/?` | | postgresql (sqlx) | `postgresql://[:]@[:]/?` | | redshift (sqlx) | `redshift://[:]@[:]/` | | rusqlite | `rusqlite://[]` | | s3¹ | `s3://[:@][:]//[?region=][&session_token=][&force_path_style=(true\|false)][&scheme=]` | | scylladb | `scylladb://[:@][:]/[][?node=:][&datacenter=][&sslmode=][&ssl_ca=][&ssl_cert=&ssl_key=][&client_route=]` | | snowflake | `snowflake://[:]@.snowflakecomputing.com/[?private_key_file=pkey_file&public_key_file=pubkey_file]` | | sqlite (sqlx) | `sqlite://[]` | | sqlserver | `sqlserver://[[:]@][:][/][?ApplicationName=][&encrypt=(true\|false\|yes\|no\|DANGER_PLAINTEXT)][&TrustServerCertificate=(true\|false\|yes\|no)][&TrustServerCertificateCA=][&IntegratedSecurity=(true\|false\|yes\|no)]` | | tsv (polars) | `tsv://[?has_header=]["e=][&skip_rows=]` | | xml | `xml://` | | xz¹ | `xz://` | | yaml | `yaml://` | | zstd¹ | `zstd://` | ¹ the driver will attempt to detect the type of file and automatically use the appropriate driver. ² `libsql` needs to be enabled with the `libsql` feature flag; it is disabled by default as it conflicts with `rusqlite`. ## License Licensed under either of: - Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or ) - MIT license ([LICENSE-MIT](LICENSE-MIT) or ) ## Contributing Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. --- **Need help?** Check out the [documentation](https://theseus-rs.github.io/rsql/rsql_cli/) or [open an issue](https://github.com/theseus-rs/rsql/issues) on GitHub.