https://github.com/nrempel/sleek
Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.
https://github.com/nrempel/sleek
cli command-line command-line-tool formatter sql
Last synced: 6 months ago
JSON representation
Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.
- Host: GitHub
- URL: https://github.com/nrempel/sleek
- Owner: nrempel
- License: mit
- Created: 2023-04-07T20:33:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-15T05:03:39.000Z (over 1 year ago)
- Last Synced: 2025-05-12T01:38:14.807Z (6 months ago)
- Topics: cli, command-line, command-line-tool, formatter, sql
- Language: Rust
- Homepage:
- Size: 55.7 KB
- Stars: 214
- Watchers: 2
- Forks: 20
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- fucking-static-analysis - sleek
- static-analysis - sleek
README
# Sleek ✨
[](https://crates.io/crates/sleek)
[](https://github.com/nrempel/sleek/actions)
[](https://github.com/nrempel/sleek/releases)
Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style
across your SQL code, enhancing readability and productivity.
The heavy lifting is done by the
[sqlformat](https://github.com/shssoichiro/sqlformat-rs) crate.
## Before and After
Here's an example of a SQL query before and after being formatted by Sleek:
### Before
```sql
select id, name, email from users where id in (select user_id from orders where total > 100) and status = 'active'
```
### After
```sql
SELECT
id,
name,
email
FROM
users
WHERE
id IN (
SELECT
user_id
FROM
orders
WHERE
total > 100
)
AND STATUS = 'active'
```
## Features
- Format SQL files using customizable indentation and character case options
- Supports glob patterns, allowing you to format multiple files and patterns
- Check whether your SQL files are already formatted without altering them with
the `--check` flag
## Installation
### Download Compiled Binaries
You can download the compiled binaries for Sleek from the
[GitHub Releases](https://github.com/nrempel/sleek/releases) page. Choose the
binary that corresponds to your operating system and architecture, and place it
in a directory included in your system's `PATH` environment variable.
### Install with Cargo
To install Sleek using Cargo, you'll need to have
[Rust](https://www.rust-lang.org/tools/install) installed on your system. Once
Rust is installed, you can install Sleek with Cargo:
```bash
cargo install sleek
```
## Usage
```bash
sleek [FLAGS] [OPTIONS] ...
```
### Arguments
- `...`: File path(s) to format, supports glob patterns. If no file
paths are provided, reads from stdin.
### Flags
- `-c`, `--check`: Check if the code is already formatted. If not, it will exit
with an error message.
- `-h`, `--help`: Prints help information.
- `-V`, `--version`: Prints version information.
### Options
- `-i`, `--indent_spaces `: Set the number of spaces to use for
indentation (default: 4).
- `-U`, `--uppercase `: Change reserved keywords to ALL CAPS
(default: true).
- `-l`, `--lines_between_queries `: Set the number of
line breaks after a query (default: 2).
## Examples
Format a query from stdin:
```bash
> echo "select * from users" | sleek --uppercase
SELECT
*
FROM
user
```
To check if a query is formatted correctly from stdin:
```bash
> echo "select * from users" | sleek --check
Input is not formatted correctly. Run without --check to format the input.
```
To format a single file with the default options:
```bash
sleek my_query.sql
```
To format multiple files using a glob pattern:
```bash
sleek "queries/*.sql"
```
To format files with custom options:
```bash
sleek --indent_spaces 2 --uppercase false "queries/*.sql"
```
To check if files are already formatted:
```bash
sleek --check "queries/*.sql"
```
## License
This project is available under the MIT License.