An opinionated SQL formatter for consistent, read-at-a-glance SQL.
- Formats SQL queries with customizable indentation
- Supports common SQL elements:
- SELECT
- WHERE
- GROUP BY
- aliasing
- table and schema referencing
- binary ops
- Feature-flag based SQL dialect delineation!
Add sqler to your project's deps:
sqler = "0.1.0"
use sqler::{Config, format_sql};
let sql = "SELECT id, name AS full_name FROM users WHERE age > 18";
// use default configuration
let config = Config::default();
match format_sql(sql, &config) {
Ok(formatted) => println!("{}", formatted),
Err(e) => eprintln!("Error: {}", e),
}
You can customize the following formatting behavior:
use sqler::Config;
let config = Config {
indent_char: " ".to_string(),
indent_width: 2,
max_line_length: 120,
};
- Clone the repo
- Build the project:
cargo build --release
- Install rustup, cargo, and rust
- Clone the repo
- Build the project:
cargo build -p sqler-cli
- Install the cli globally
cargo install --path sqler-cli
- Echo in sql code to format:
echo "SELECT id AS user_id, name, * FROM users WHERE age > 25" | sqler