(expr: Expr, col: &C, f: F)
| 442 | } |
| 443 | |
| 444 | fn cast_enum_as<C, F>(expr: Expr, col: &C, f: F) -> SimpleExpr |
| 445 | where |
| 446 | C: ColumnTrait, |
| 447 | F: Fn(Expr, DynIden, &ColumnType) -> SimpleExpr, |
| 448 | { |
| 449 | let col_def = col.def(); |
| 450 | let col_type = col_def.get_column_type(); |
| 451 | |
| 452 | match col_type { |
| 453 | #[cfg(all(feature = "with-json", feature = "postgres-array"))] |
| 454 | ColumnType::Json | ColumnType::JsonBinary => { |
| 455 | use sea_query::ArrayType; |
| 456 | use serde_json::Value as Json; |
| 457 | |
| 458 | #[allow(clippy::boxed_local)] |
| 459 | fn unbox<T>(boxed: Box<T>) -> T { |
| 460 | *boxed |
| 461 | } |
| 462 | |
| 463 | let expr = expr.into(); |
| 464 | match expr { |
| 465 | SimpleExpr::Value(Value::Array(ArrayType::Json, Some(json_vec))) => { |
| 466 | // flatten Array(Vec<Json>) into Json |
| 467 | let json_vec: Vec<Json> = json_vec |
| 468 | .into_iter() |
| 469 | .filter_map(|val| match val { |
| 470 | Value::Json(Some(json)) => Some(unbox(json)), |
| 471 | _ => None, |
| 472 | }) |
| 473 | .collect(); |
| 474 | SimpleExpr::Value(Value::Json(Some(Box::new(json_vec.into())))) |
| 475 | } |
| 476 | SimpleExpr::Value(Value::Array(ArrayType::Json, None)) => { |
| 477 | SimpleExpr::Value(Value::Json(None)) |
| 478 | } |
| 479 | _ => expr, |
| 480 | } |
| 481 | } |
| 482 | _ => match col_type.get_enum_name() { |
| 483 | Some(enum_name) => f(expr, SeaRc::clone(enum_name), col_type), |
| 484 | None => expr.into(), |
| 485 | }, |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | #[cfg(test)] |
| 490 | mod tests { |
no test coverage detected