1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Consider empty strings as None

This commit is contained in:
Pierre HUBERT 2020-05-23 14:12:42 +02:00
parent 505fa5adb3
commit 2807dcbffa

View File

@ -139,11 +139,16 @@ impl<'a> RowResult<'a> {
} }
} }
/// Get an optional string => Set to None if string is null /// Get an optional string => Set to None if string is null / empty
pub fn get_optional_str(&self, name: &str) -> ResultBoxError<Option<String>> { pub fn get_optional_str(&self, name: &str) -> ResultBoxError<Option<String>> {
match self.is_null(name)? { match self.is_null(name)? {
true => Ok(None), true => Ok(None),
false => Ok(Some(self.get_str(name)?)) false => Ok(Some(self.get_str(name)?).map_or(None, |d|{
match d.is_empty() {
true => None,
false => Some(d)
}
}))
} }
} }
} }