Skip to main content

Crate banshee_format

Crate banshee_format 

Source
Expand description

CST-based SQL formatter following sqlstyle.guide conventions.

This crate provides SQL formatting that preserves the structure of the original code while applying consistent style rules.

§Stability

Pre-1.0. The intended public surface is the format / format_sqlstyle / format_with_pgformatter entry points, the edit helpers (format_edits, format_range, diff_edits, TextEdit) and the config types (FormatConfig, PgFormatterConfig, …). Printer internals may change without a semver bump.

§Features

  • River alignment for keyword alignment
  • Configurable keyword case (UPPER, lower, Preserve)
  • Leading or trailing comma style
  • Proper indentation for subqueries and CTEs
  • Comment preservation
  • Error node preservation (malformed SQL preserved as-is)

§Usage

use banshee_format::{format, FormatConfig};

let sql = "select id,name from users where active=true";
let formatted = format(sql, &FormatConfig::sqlstyle());

println!("{}", formatted);
// Output:
//     SELECT id
//          , name
//       FROM users
//      WHERE active = TRUE

Re-exports§

pub use config::CommaStyle;
pub use config::FormatConfig;
pub use config::FormatStyle;
pub use config::IdentifierCase;
pub use config::IndentStyle;
pub use config::KeywordCase;
pub use edits::TextEdit;
pub use edits::diff_edits;
pub use edits::format_edits;
pub use edits::format_range;
pub use format::format;
pub use pg_format::PgPrinter;
pub use pg_formatter::CaseOption;
pub use pg_formatter::PgFormatterConfig;
pub use pg_formatter::PgFormatterError;
pub use printer::Printer;
pub use validate::FormatError;
pub use validate::FormatResult;
pub use validate::ValidationReport;
pub use validate::check_idempotent;
pub use validate::count_tokens;
pub use validate::format_pgformatter_validated;
pub use validate::format_validated;
pub use validate::normalize;
pub use validate::semantically_equal;
pub use validate::validate_comprehensive;
pub use validate::validate_format;

Modules§

config
Format configuration for SQL formatting.
edits
Edit-producing formatting.
format
SQL formatting implementation.
pg_format
pgFormatter-style SQL formatting implementation.
pg_formatter
pgFormatter-compatible configuration.
printer
Core printer for SQL formatting output.
rules
Formatting rules for SQL.
validate
Formatter validation to ensure formatting preserves query semantics.

Functions§

format_compact
Formats SQL using compact style.
format_pgformatter
Formats SQL using pgFormatter-compatible defaults.
format_sqlstyle
Formats SQL using sqlstyle.guide defaults.
format_with_pgformatter
Formats SQL using pgFormatter configuration.