use std::borrow::Cow;
use sqlparser::{ast::Statement, dialect::MsSqlDialect, parser::Parser};
pub(crate) struct SqlServerIntrospectionFlavour;
impl super::IntrospectionFlavour for SqlServerIntrospectionFlavour {
fn format_view_definition(&self, definition: &str) -> String {
let dialect = MsSqlDialect {};
let stmt = Parser::new(&dialect)
.try_with_sql(definition)
.and_then(|mut p| p.parse_statement());
let definition = match stmt {
Ok(Statement::CreateView { query, .. }) => Cow::Owned(format!("{query};")),
_ => Cow::Borrowed(definition),
};
let opts = sqlformat::FormatOptions {
uppercase: true,
..Default::default()
};
sqlformat::format(&definition, &Default::default(), opts)
}
}