Current section
Files
Jump to
Current section
Files
native/sqlformatter/src/lib.rs
use rustler::NifStruct;
use sqlformat::FormatOptions;
use sqlformat::Indent;
use sqlformat::QueryParams;
#[derive(Debug, NifStruct)]
#[module = "SQLFormatter.Opts"]
struct Opts {
indent: u8,
uppercase: bool,
lines_between_queries: u8,
}
#[rustler::nif]
fn format(sql: String, opts: Opts) -> String {
let options = FormatOptions {
indent: Indent::Spaces(opts.indent),
uppercase: opts.uppercase,
lines_between_queries: opts.lines_between_queries,
};
sqlformat::format(sql.as_str(), &QueryParams::default(), options)
}
rustler::init!("Elixir.SQLFormatter.NIF", [format]);