How to Use Sleek: Your SQL Formatting Buddy

Sep 16, 2023 | Programming

Welcome to the world of SQL formatting! If you’ve ever felt overwhelmed by the daunting task of keeping your SQL code neat and readable, you’re in the right place. Meet **Sleek**, a command-line interface (CLI) tool designed to help you maintain a consistent style across your SQL code. It elevates your code readability and productivity, making it an essential tool in your programming arsenal.

What is Sleek?

Sleek is a handy CLI tool that leverages the power of the sqlformat crate to format SQL queries effectively. With Sleek, you can easily improve the structure of your SQL files, making your code clearer and more manageable.

Installation Guide

Getting started with Sleek is a breeze! You have multiple options for installation:

  • Download Compiled Binaries: Visit the GitHub Releases page and choose the binary suitable for your operating system. Make sure to place it in a directory that’s included in your system’s PATH environment variable.
  • Install with Cargo: If you have Rust installed, you can easily get Sleek by running the following command:
cargo install sleek

How to Use Sleek

Using Sleek is like having a personal assistant for your SQL. Here’s how you can leverage its features:

Basic Command Structure

The command to run Sleek is simple:

sleek [FLAGS] [OPTIONS] file_paths...

Here’s a breakdown of the essential components:

Arguments

  • file_paths...: Specify the file path(s) you want to format. You can even use glob patterns!

Flags

  • -c, --check: Use this flag to check if your SQL code is already formatted without changing anything.
  • -h, --help: Need assistance? This flag will show you the help information.
  • -V, --version: Discover the version of Sleek you’re using.

Options

  • -i, --indent_spaces indent_spaces: Customize how many spaces you want for indentation (default: 4).
  • -U, --uppercase uppercase: Decide whether to use ALL CAPS for reserved keywords (default: true).
  • -l, --lines_between_queries lines_between_queries: Control the number of line breaks after a query (default: 2).

Before and After: The Magic of Sleek

To illustrate Sleek’s capabilities, let’s take a look at a SQL query before and after formatting:

Before

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

After

sqlSELECT    id,    name,    email
FROM    users
WHERE    id IN (
        SELECT            user_id
        FROM            orders
        WHERE            total  100
    )    AND STATUS = active

Example Use Cases

Let’s explore some scenarios to showcase how Sleek can be utilized:

  • Format a query from stdin with uppercased keywords:
  • echo select * from users | sleek --uppercase
  • Check if a query is formatted correctly:
  • echo select * from users | sleek --check
  • Format a single file with defaults:
  • sleek my_query.sql
  • Format multiple files using glob:
  • sleek queries*.sql
  • Check if files are formatted:
  • sleek --check queries*.sql

Troubleshooting

If you encounter issues while using Sleek, consider the following troubleshooting tips:

  • Ensure your file paths are correct and accessible.
  • Make sure you have the appropriate permissions to modify the files.
  • If you see unexpected formatting, check your indentation and uppercase settings.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox