(expr: &SqlExpr, qualify: bool)
| 26 | } |
| 27 | |
| 28 | fn convert_expr_inner(expr: &SqlExpr, qualify: bool) -> crate::bridge::expr_eval::SqlExpr { |
| 29 | use crate::bridge::expr_eval::SqlExpr as BExpr; |
| 30 | match expr { |
| 31 | SqlExpr::Column { table, name } => { |
| 32 | // `EXCLUDED.col` references the row proposed for insertion in |
| 33 | // `INSERT ... ON CONFLICT DO UPDATE`. Emit the dedicated |
| 34 | // variant so the upsert handler can resolve against the |
| 35 | // incoming row via `eval_with_excluded`. The table qualifier |
| 36 | // comes in already-normalized (lowercased) from the parser. |
| 37 | if table |
| 38 | .as_deref() |
| 39 | .is_some_and(|t| t.eq_ignore_ascii_case("excluded")) |
| 40 | { |
| 41 | return BExpr::ExcludedColumn(name.clone()); |
| 42 | } |
| 43 | if qualify { |
| 44 | BExpr::Column(nodedb_sql::planner::qualified_name(table.as_deref(), name)) |
| 45 | } else { |
| 46 | BExpr::Column(name.clone()) |
| 47 | } |
| 48 | } |
| 49 | SqlExpr::Literal(v) => BExpr::Literal(sql_value_to_nodedb_value(v)), |
| 50 | SqlExpr::BinaryOp { left, op, right } => BExpr::BinaryOp { |
| 51 | left: Box::new(convert_expr_inner(left, qualify)), |
| 52 | op: match op { |
| 53 | nodedb_sql::types::BinaryOp::Add => crate::bridge::expr_eval::BinaryOp::Add, |
| 54 | nodedb_sql::types::BinaryOp::Sub => crate::bridge::expr_eval::BinaryOp::Sub, |
| 55 | nodedb_sql::types::BinaryOp::Mul => crate::bridge::expr_eval::BinaryOp::Mul, |
| 56 | nodedb_sql::types::BinaryOp::Div => crate::bridge::expr_eval::BinaryOp::Div, |
| 57 | nodedb_sql::types::BinaryOp::Mod => crate::bridge::expr_eval::BinaryOp::Mod, |
| 58 | nodedb_sql::types::BinaryOp::Eq => crate::bridge::expr_eval::BinaryOp::Eq, |
| 59 | nodedb_sql::types::BinaryOp::Ne => crate::bridge::expr_eval::BinaryOp::NotEq, |
| 60 | nodedb_sql::types::BinaryOp::Gt => crate::bridge::expr_eval::BinaryOp::Gt, |
| 61 | nodedb_sql::types::BinaryOp::Ge => crate::bridge::expr_eval::BinaryOp::GtEq, |
| 62 | nodedb_sql::types::BinaryOp::Lt => crate::bridge::expr_eval::BinaryOp::Lt, |
| 63 | nodedb_sql::types::BinaryOp::Le => crate::bridge::expr_eval::BinaryOp::LtEq, |
| 64 | nodedb_sql::types::BinaryOp::And => crate::bridge::expr_eval::BinaryOp::And, |
| 65 | nodedb_sql::types::BinaryOp::Or => crate::bridge::expr_eval::BinaryOp::Or, |
| 66 | nodedb_sql::types::BinaryOp::Concat => crate::bridge::expr_eval::BinaryOp::Concat, |
| 67 | }, |
| 68 | right: Box::new(convert_expr_inner(right, qualify)), |
| 69 | }, |
| 70 | SqlExpr::Function { name, args, .. } => BExpr::Function { |
| 71 | name: name.clone(), |
| 72 | args: args |
| 73 | .iter() |
| 74 | .map(|a| convert_expr_inner(a, qualify)) |
| 75 | .collect(), |
| 76 | }, |
| 77 | SqlExpr::Case { |
| 78 | operand, |
| 79 | when_then, |
| 80 | else_expr, |
| 81 | } => BExpr::Case { |
| 82 | operand: operand |
| 83 | .as_ref() |
| 84 | .map(|e| Box::new(convert_expr_inner(e, qualify))), |
| 85 | when_thens: when_then |
no test coverage detected