use crate::{
cli::{Dialect, Format},
output::OutputFormat,
query::SqlDialect
};
pub fn convert_dialect(dialect: Dialect) -> SqlDialect {
match dialect {
Dialect::Generic => SqlDialect::Generic,
Dialect::Mysql => SqlDialect::MySQL,
Dialect::Postgresql => SqlDialect::PostgreSQL,
Dialect::Sqlite => SqlDialect::SQLite,
Dialect::Clickhouse => SqlDialect::ClickHouse
}
}
pub fn convert_format(format: Format) -> OutputFormat {
match format {
Format::Text => OutputFormat::Text,
Format::Json => OutputFormat::Json,
Format::Yaml => OutputFormat::Yaml,
Format::Sarif => OutputFormat::Sarif
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_convert_dialect_generic() {
assert!(matches!(
convert_dialect(Dialect::Generic),
SqlDialect::Generic
));
}
#[test]
fn test_convert_dialect_mysql() {
assert!(matches!(convert_dialect(Dialect::Mysql), SqlDialect::MySQL));
}
#[test]
fn test_convert_dialect_postgresql() {
assert!(matches!(
convert_dialect(Dialect::Postgresql),
SqlDialect::PostgreSQL
));
}
#[test]
fn test_convert_dialect_sqlite() {
assert!(matches!(
convert_dialect(Dialect::Sqlite),
SqlDialect::SQLite
));
}
#[test]
fn test_convert_dialect_clickhouse() {
assert!(matches!(
convert_dialect(Dialect::Clickhouse),
SqlDialect::ClickHouse
));
}
#[test]
fn test_convert_format_text() {
assert!(matches!(convert_format(Format::Text), OutputFormat::Text));
}
#[test]
fn test_convert_format_json() {
assert!(matches!(convert_format(Format::Json), OutputFormat::Json));
}
#[test]
fn test_convert_format_yaml() {
assert!(matches!(convert_format(Format::Yaml), OutputFormat::Yaml));
}
#[test]
fn test_convert_format_sarif() {
assert!(matches!(convert_format(Format::Sarif), OutputFormat::Sarif));
}
}