Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.

Overview

Sleek: SQL Formatter

Crates.io GitHub Actions GitHub 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 crate.

Before and After

Here's an example of a SQL query before and after being formatted by Sleek:

Before

select id, name, email from users where id in (select user_id from orders where total > 100) and status = 'active'

After

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 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 installed on your system. Once Rust is installed, you can install Sleek with Cargo:

cargo install sleek

Usage

sleek [FLAGS] [OPTIONS] <file_paths>...

Arguments

  • <file_paths>...: 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 <indent_spaces>: Set the number of spaces to use for indentation (default: 4).
  • -U, --uppercase <uppercase>: Change reserved keywords to ALL CAPS (default: true).
  • -l, --lines_between_queries <lines_between_queries>: Set the number of line breaks after a query (default: 2).

Examples

Format a query from stdin:

> echo "select * from users" | sleek --uppercase
SELECT
    *
FROM
    user

To check if a query is formatted correctly from stdin:

> 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:

sleek my_query.sql

To format multiple files using a glob pattern:

sleek "queries/*.sql"

To format files with custom options:

sleek --indent_spaces 2 --uppercase false "queries/*.sql"

To check if files are already formatted:

sleek --check "queries/*.sql"

License

This project is available under the MIT License.

You might also like...
Eventually consistent values for Rust

Eventuals give you the most up-to-date snapshots of some value. They are like Futures that update over time, continually resolving to an eventually co

gfold is a CLI-driven application that helps you keep track of multiple Git repositories.

gfold is a CLI-driven application that helps you keep track of multiple Git repositories.

A Turing-complete but dead-simple spaced repetition CLI that helps you learn stuff.

Forne — Learn Stuff Forne is a Turing-complete spaced repetition engine to help you learn stuff your way. What does that mean? Well, there are a few p

🔣 nerdfix helps you to find/fix obsolete Nerd Font icons in your project.

🔣 nerdfix nerdfix helps you to find/fix obsolete Nerd Font icons in your project. 💭 Why Nerd Fonts is used in many projects for a beautiful UI. It p

Monorepo for dprint—a pluggable and configurable code formatting platform

dprint Monorepo for dprint—a pluggable and configurable code formatting platform. This project is under active early development. I recommend you chec

🍅 A command-line tool to get and set values in toml files while preserving comments and formatting

tomato Get, set, and delete values in TOML files while preserving comments and formatting. That's it. That's the feature set. I wrote tomato to satisf

 ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK
ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK

ClangQL - Clang AST Query Language ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK.

Tiny CLI tool that helps to visualize iCal file content in the terminal.
Tiny CLI tool that helps to visualize iCal file content in the terminal.

Calio Calio is a tiny CLI tool that helps to visualize iCal file in the terminal. Installation You can either install it via cargo or download the bin

zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.
zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.

zigfi zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets

Comments
  • Integration with NeoVim

    Integration with NeoVim

    Thank you for RIIR - was aware about such plugin in python but didn't want to go through env setup. This looks awesome 🙌

    Do you have any plans for integration with Mason / Nvim package for .sql files formatting ?

    opened by pratikgajjar 2
  • Bump clap from 4.2.1 to 4.2.2

    Bump clap from 4.2.1 to 4.2.2

    Bumps clap from 4.2.1 to 4.2.2.

    Release notes

    Sourced from clap's releases.

    v4.2.2

    [4.2.2] - 2023-04-13

    Internal

    • Update dependencies
    Changelog

    Sourced from clap's changelog.

    [4.2.2] - 2023-04-13

    Internal

    • Update dependencies
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • Trailing newlines

    Trailing newlines

    Hi Nick! Thanks for creating Sleek - it's way, way faster than the formatter that we use at the moment, great work :-)

    The only thing preventing me from switching to it at the moment is the fact that it removes the trailing newline that is usually expected at the end of the file. Most formatters like prettier, rustfmt, etc will insert an empty new line at the end of a file if one is not there.

    Is this something that could be added?

    opened by sdd 1
  • Fix release workflow

    Fix release workflow

    https://github.com/nrempel/sleek/blob/main/.github/workflows/release.yml

    This workflow should build a release binary for every platform and make it available as a Github release when a version tag is pushed. It's not working right now.

    help wanted 
    opened by nrempel 0
Owner
Nick Rempel
Nick Rempel
Helps you keep track of time for team members across different time zones & DST changes

Teamdate Helps you keep track of time for team members across different timezones and other daylight saving changes based off their location. Because

Alex Snaps 7 Jan 9, 2023
A Yocto setup and management tool that helps you keep your environment up-to-date and in-sync with your team

yb (Yocto Buddy) yb is designed to make it easy to setup and (perhaps more importantly) keep Yocto environments up-to-date and in-sync with your team.

null 13 Oct 31, 2022
Social media style compact number formatting for rust.

prettty-num Format integers into a compact social media style format, similar to using Intl.NumberFormat("en", { notation: "compact" }); as a number f

null 5 Aug 17, 2024
Cli tool for git productivity written in Rust and packaged for consumption via NPM

crust ?? cli tool for git productivity written in Rust and packaged for consumption via NPM This repo is identical with @skyneticist/golee in terms of

null 2 Jul 30, 2022
✨ sleek typing tui with visualized results and historical logging

thokr ✨ sleek typing tui with visualized results and historical logging Usage For detailed usage run thokr -h. thokr 0.4.1 sleek typing tui with visua

colby thomas 440 Dec 30, 2022
✨Sleek typing tui written in rust

thokr ✨ sleek typing tui written in rust Installation Cargo $ cargo install thokr Docker $ docker run -it coloradocolby/thokr Arch Linux Install thokr

Colby Thomas 440 Dec 30, 2022
Translation support for mdbook. The plugins here give you a structured way to maintain a translated book.

Gettext Translation Support for mdbook The plugins here makes it easy to translate documentation written in mdbook into multiple languages. Support fo

Google 19 Apr 5, 2023
A Rust CLI tool that helps you enforce Git policies through Git hooks both server and client side

GitPolicyEnforcer This is a command line utility written in Rust, that helps you utilize Git hooks, to enforce various policies. It currently supports

Vagelis Prokopiou 4 Aug 14, 2022
Deadliner helps you keep track of the time left for your deadline by dynamically updating the wallpaper of your desktop with the time left.

Deadliner Watch the YouTube video What's Deadliner? Deadliner is a cross-platform desktop application for setting deadline for a project and keeping t

Deadliner 34 Dec 16, 2022
rpm (Rust project manager) is a tool that helps you to manage your rust projects

rpm rpm (Rust project manager) is a open source tool for managing your rust project in an organized way Installation # make sure you have rust install

Dilshad 4 May 4, 2023