launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.52k stars 1.28k forks source link

Autoformat sqlx macros #3517

Open musjj opened 2 months ago

musjj commented 2 months ago

Is your feature request related to a problem? Please describe. Currently, SQL query strings can not be auto-formatted.

Describe the solution you'd like Add an auto-format command to the CLI.

Describe alternatives you've considered Format all queries manually.

Additional context As an precedence, Dioxus provides a fmt command in their CLI that can autoformat all rsx! macro invocations: https://github.com/DioxusLabs/dioxus/pull/454.

abonander commented 2 months ago

I'd love to have this! As you might imagine, though, it would be quite the lift.

abonander commented 2 months ago

You can also usually get some assistance from the IDE here. For example, in RustRover if you apply SQL language injection to the string literal, you can open the string in a new editor tab and do "reformat code" there.

syphar commented 2 months ago

Regarding IDE support: with neovim you can also make it work via:

musjj commented 2 months ago

Found a relevant issue: https://github.com/launchbadge/sqlx/issues/2866. Re-using sqlfluff for this would be nice, though I'm not sure how this would work.

There's also sqruff, a native Rust port of sqlfluff made by the guys behind quary. Being written in Rust might make it easier to integrate to the CLI.