use crate::idents::unwrap_expr;
use sqlparser::ast::{Expr, FunctionArg, FunctionArgExpr, FunctionArguments, ObjectName};
pub(super) fn all_pairs(
targets: &[ObjectName],
value: &Expr,
mut match_pair: impl FnMut(&ObjectName, &Expr) -> bool,
) -> bool {
if targets.is_empty() {
return false;
}
match unwrap_expr(value) {
Expr::Tuple(values) => {
targets.len() == values.len()
&& targets
.iter()
.zip(values)
.all(|(target, value)| match_pair(target, value))
}
Expr::Function(function)
if matches!(function.name.0.as_slice(), [part] if part.as_ident()
.is_some_and(|name| name.quote_style.is_none() && name.value.eq_ignore_ascii_case("row"))) =>
{
let FunctionArguments::List(list) = &function.args else {
return false;
};
matches!(function.parameters, FunctionArguments::None)
&& function.filter.is_none()
&& function.over.is_none()
&& function.within_group.is_empty()
&& list.clauses.is_empty()
&& list.duplicate_treatment.is_none()
&& targets.len() == list.args.len()
&& targets.iter().zip(&list.args).all(|(target, argument)| {
matches!(argument, FunctionArg::Unnamed(FunctionArgExpr::Expr(value))
if match_pair(target, value))
})
}
_ => false,
}
}