diff --git a/src/http/api1/query.rs b/src/http/api1/query.rs index a0e14fb..ffaaf00 100644 --- a/src/http/api1/query.rs +++ b/src/http/api1/query.rs @@ -46,6 +46,14 @@ use super::error; /// - exact equality: `key=value` /// /// - numeric comparison: `key>=value`, `key>value`, `key<=value`, `key ParseResult { fn value(input: &str) -> ParseResult { alt(( + map(boolean, query::Value::Boolean), map(number, query::Value::Number), map(string, query::Value::String), ))(input) } +fn boolean(input: &str) -> ParseResult { + alt((nom_value(true, tag("true")), nom_value(false, tag("false"))))(input) +} + fn number(input: &str) -> ParseResult { alt(( // Try to parse the number as a potentially-signed integer. If it's followed by `.`, it'll fall through to the float check. @@ -403,6 +416,22 @@ mod test { ); } + #[test] + fn booleans() { + fn harness(value: bool) -> query::Node { + group(vec![( + query::Occur::Should, + leaf( + field_struct("A"), + query::Operation::Eq(query::Value::Boolean(value)), + ), + )]) + } + + assert_eq!(test_parse("A=true"), harness(true)); + assert_eq!(test_parse("A=false"), harness(false)); + } + #[test] fn number_types() { fn harness(number: query::Number) -> query::Node { diff --git a/src/search/query/query.rs b/src/search/query/query.rs index a248aa8..0c948bc 100644 --- a/src/search/query/query.rs +++ b/src/search/query/query.rs @@ -46,6 +46,7 @@ pub struct Relation { #[derive(Debug, Clone, PartialEq)] pub enum Value { + Boolean(bool), Number(Number), String(String), } diff --git a/src/search/sqlite/query.rs b/src/search/sqlite/query.rs index 4b51893..ba701b6 100644 --- a/src/search/sqlite/query.rs +++ b/src/search/sqlite/query.rs @@ -347,8 +347,9 @@ fn table_alias(alias_base: &str, language: Language) -> Alias { impl From for sea_query::Value { fn from(value: post::Value) -> Self { match value { + post::Value::Boolean(value) => sea_query::Value::from(value), post::Value::Number(value) => sea_query::Value::from(value), - post::Value::String(value) => sea_query::Value::String(Some(value.into())), + post::Value::String(value) => sea_query::Value::from(value), } } }