From 0e35395cf60d12b90d2d1340ed659f9e14cf895d Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 12 Sep 2024 15:01:18 +0800 Subject: [PATCH] Fix: `LIKE` wildcard operations --- 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 c5b00dcf..86210f2e 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 => {