From d84509c6d067b2096bdde43d32dfd3c8d2384935 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 7 Oct 2024 14:52:32 +0800 Subject: [PATCH] Fix: `LIKE` wildcard operations (#173) --- src/builder_context/filter_types_map.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/builder_context/filter_types_map.rs b/src/builder_context/filter_types_map.rs index 2282e513..658f19ef 100644 --- a/src/builder_context/filter_types_map.rs +++ b/src/builder_context/filter_types_map.rs @@ -522,28 +522,44 @@ impl FilterTypesMapHelper { if let Some(value) = filter.get("contains") { let value = types_map_helper .async_graphql_value_to_sea_orm_value::(column, &value)?; - condition = condition.add(column.contains(value.to_string())); + let s = match value { + sea_orm::sea_query::Value::String(Some(s)) => s.to_string(), + _ => value.to_string(), + }; + condition = condition.add(column.contains(s)); } } FilterOperation::StartsWith => { if let Some(value) = filter.get("starts_with") { let value = types_map_helper .async_graphql_value_to_sea_orm_value::(column, &value)?; - condition = condition.add(column.starts_with(value.to_string())); + let s = match value { + sea_orm::sea_query::Value::String(Some(s)) => s.to_string(), + _ => value.to_string(), + }; + condition = condition.add(column.starts_with(s)); } } FilterOperation::EndsWith => { if let Some(value) = filter.get("ends_with") { let value = types_map_helper .async_graphql_value_to_sea_orm_value::(column, &value)?; - condition = condition.add(column.ends_with(value.to_string())); + let s = match value { + sea_orm::sea_query::Value::String(Some(s)) => s.to_string(), + _ => value.to_string(), + }; + condition = condition.add(column.ends_with(s)); } } FilterOperation::Like => { if let Some(value) = filter.get("like") { let value = types_map_helper .async_graphql_value_to_sea_orm_value::(column, &value)?; - condition = condition.add(column.like(value.to_string())); + let s = match value { + sea_orm::sea_query::Value::String(Some(s)) => s.to_string(), + _ => value.to_string(), + }; + condition = condition.add(column.like(s)); } } FilterOperation::NotLike => {