use std::borrow::Cow;
use crate::schema::DataType;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FunctionKind {
Scalar,
Aggregate,
Window,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Dialect {
Generic,
Postgres,
MySql,
Sqlite,
}
#[derive(Debug, Clone)]
pub struct FunctionDef {
pub names: Vec<Cow<'static, str>>,
pub kind: FunctionKind,
pub min_args: usize,
pub max_args: Option<usize>,
pub param_types: Option<Vec<Option<DataType>>>,
pub return_type: Option<DataType>,
pub supports_distinct: bool,
pub supports_order_by: bool,
pub allows_star: bool,
pub dialects: Vec<Dialect>,
}
impl FunctionDef {
pub fn canonical_name(&self) -> &str {
self.names.first().map_or("", |n| n.as_ref())
}
pub fn accepts_name(&self, name: &str) -> bool {
self.names.iter().any(|n| n.eq_ignore_ascii_case(name))
}
pub fn supports_dialect(&self, dialect: Dialect) -> bool {
self.dialects.is_empty()
|| self.dialects.contains(&Dialect::Generic)
|| self.dialects.contains(&dialect)
}
}