Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/maxcountryman/forma

🐚 An opinionated SQL formatter.
https://github.com/maxcountryman/forma

format-sql formatter pretty-printer sql sql-formatter

Last synced: 14 days ago
JSON representation

🐚 An opinionated SQL formatter.

Awesome Lists containing this project

README

        


forma 🐚


An opinionated SQL formatter.





Coverage Status










## 📦 Install

The binary may be installed via `cargo`:

```
$ cargo install forma
```

Further the companion library `formation` may be required as a dependency:

```toml
[dependencies]
formation = "0.3.0"
```

## 🤸 Usage

> ⚠️ `forma` should be considered alpha quality, with several known, and many
more unknown deficiencies. **Use at your own risk!**

Give `forma` some SQL via a file path or stdin and you'll get back formatted
SQL.

```
$ echo "SELECT * FROM users" | forma
select * from users;
```

To format a SQL file, simply give `forma` the file path.

```
$ forma path/to/some/sql/example.sql
```

And if you'd prefer to not actually format the SQL but know if formatting
would happen then use the `--check` flag.

The binary is a thin wrapper around the `formation` library, which can be used
in your own applications to format SQL.

```rust
use formation::format;
let sql = "SELECT * FROM users;";
assert_eq!(
format(sql, false, 100).unwrap(),
vec!["select * from users;\n".to_owned()]
);
```

## 🚧 TODOs

- [ ] Comprehensive `Statement` variant support (currently only `Query`)
- [ ] Support for comments (these will be eaten by the formatter!)
- [ ] Parameterized dialects