#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum ProcedureForm {
PlPgSql,
MySql,
TSql,
SnowflakeScripting,
Databricks,
ClickHouse,
GoogleSql,
#[default]
Agnostic,
Custom(&'static str),
Unsupported(&'static str),
}
impl ProcedureForm {
#[must_use]
pub const fn refusal(self) -> Option<&'static str> {
match self {
ProcedureForm::Unsupported(orientation) => Some(orientation),
_ => None,
}
}
#[must_use]
pub const fn custom_grammar(self) -> Option<&'static str> {
match self {
ProcedureForm::Custom(grammar) => Some(grammar),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum ScalarFunctionForm {
#[default]
PostgreSql,
DuckDb,
TSql,
ClickHouse,
Snowflake,
MySql,
Databricks,
GoogleSql,
Redshift,
Custom(&'static str),
Unsupported(&'static str),
}
impl ScalarFunctionForm {
#[must_use]
pub const fn refusal(self) -> Option<&'static str> {
match self {
ScalarFunctionForm::Unsupported(orientation) => Some(orientation),
_ => None,
}
}
#[must_use]
pub const fn custom_grammar(self) -> Option<&'static str> {
match self {
ScalarFunctionForm::Custom(grammar) => Some(grammar),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum TableFunctionForm {
#[default]
PostgreSql,
DuckDb,
GoogleSql,
TSql,
ClickHouse,
Snowflake,
Databricks,
Unsupported(&'static str),
Custom(&'static str),
}
impl TableFunctionForm {
#[must_use]
pub const fn refusal(self) -> Option<&'static str> {
match self {
TableFunctionForm::Unsupported(orientation) => Some(orientation),
_ => None,
}
}
#[must_use]
pub const fn custom_grammar(self) -> Option<&'static str> {
match self {
TableFunctionForm::Custom(grammar) => Some(grammar),
_ => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_defaults_are_the_agnostic_procedure_and_the_postgres_functions() {
assert_eq!(ProcedureForm::default(), ProcedureForm::Agnostic);
assert_eq!(ScalarFunctionForm::default(), ScalarFunctionForm::PostgreSql);
assert_eq!(TableFunctionForm::default(), TableFunctionForm::PostgreSql);
}
#[test]
fn only_the_unsupported_form_carries_refusal_wording() {
assert_eq!(TableFunctionForm::PostgreSql.refusal(), None);
assert_eq!(TableFunctionForm::GoogleSql.refusal(), None);
assert_eq!(
TableFunctionForm::Unsupported("my engine has none").refusal(),
Some("my engine has none")
);
}
#[test]
fn a_custom_grammar_is_not_a_refusal_on_any_of_the_three() {
assert_eq!(ProcedureForm::Custom("PL/SQL").refusal(), None);
assert_eq!(ScalarFunctionForm::Custom("PL/SQL").refusal(), None);
assert_eq!(TableFunctionForm::Custom("PL/SQL").refusal(), None);
}
#[test]
fn only_the_custom_form_names_a_grammar() {
assert_eq!(ProcedureForm::Custom("PL/SQL").custom_grammar(), Some("PL/SQL"));
assert_eq!(ScalarFunctionForm::Custom("PL/SQL").custom_grammar(), Some("PL/SQL"));
assert_eq!(TableFunctionForm::Custom("PL/SQL").custom_grammar(), Some("PL/SQL"));
assert_eq!(ProcedureForm::TSql.custom_grammar(), None);
assert_eq!(ScalarFunctionForm::Redshift.custom_grammar(), None);
assert_eq!(TableFunctionForm::DuckDb.custom_grammar(), None);
assert_eq!(ProcedureForm::Unsupported("none here").custom_grammar(), None);
}
#[test]
fn the_scalar_function_form_can_refuse_in_its_own_words() {
assert_eq!(
ScalarFunctionForm::Unsupported("no scalar function here").refusal(),
Some("no scalar function here")
);
assert_eq!(ScalarFunctionForm::PostgreSql.refusal(), None);
}
}