An open API service indexing awesome lists of open source software.

https://github.com/takeokunn/rs-sql-indent

A Rust-based SQL formatter and indenter
https://github.com/takeokunn/rs-sql-indent

formatter rust sql

Last synced: 16 days ago
JSON representation

A Rust-based SQL formatter and indenter

Awesome Lists containing this project

README

          

# rs-sql-indent

A fast, opinionated SQL formatter CLI tool written in Rust.

![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)

## Features

- Token-stream based formatting -- no AST parsing, no external dependencies
- Four formatting styles: **Basic**, **Streamline**, **Aligned**, and **Dataops**
- Uppercase/lowercase keyword control
- Zero-copy lexer for fast execution
- Reads from stdin -- works with pipes and redirects
- [Playground](https://takeokunn.github.io/rs-sql-indent/) -- try it in your browser via WebAssembly

## Install

```sh
cargo install --git https://github.com/takeokunn/rs-sql-indent.git
```

## Usage

```sh
echo "select id, name from users where active = true" | rs-sql-indent
```

```sh
rs-sql-indent < query.sql
```

### Options

| Flag | Description |
| ----------------- | ----------------------------------------------------------------------- |
| `--style ` | Formatting style: `basic` (default), `streamline`, `aligned`, `dataops` |
| `--lowercase` | Output keywords in lowercase |

```sh
echo "select id, name from users" | rs-sql-indent --style aligned
echo "select id, name from users" | rs-sql-indent --style streamline
```

## Formatting Styles

**Basic** (default) -- 4-space indent, uppercase, trailing comma:

```sql
SELECT
id,
name,
email
FROM
users
WHERE
active = TRUE
ORDER BY
name
```

**Streamline** -- 2-space indent, trailing comma:

```sql
SELECT
id,
name,
email
FROM
users
WHERE
active = TRUE
ORDER BY
name
```

**Aligned** -- right-aligned keywords, uppercase, leading comma:

```sql
SELECT id
, name
, email
FROM users
WHERE active = TRUE
ORDER BY name
```

**Dataops** -- 4-space indent, uppercase, leading comma:

```sql
SELECT
id
, name
, email
FROM
users
WHERE
active = TRUE
ORDER BY
name
```

## Build

```sh
cargo build --release
```

## License

MIT -- see [LICENSE](LICENSE) for details.