From e6d120769aed0abccade086f48528a61fb3ecc43 Mon Sep 17 00:00:00 2001 From: Julius de Bruijn Date: Wed, 20 May 2020 18:01:20 +0200 Subject: [PATCH] Fix compilation errors if json is not enabled --- src/visitor/postgres.rs | 68 ++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/visitor/postgres.rs b/src/visitor/postgres.rs index c9081049a..fcefa7bdf 100644 --- a/src/visitor/postgres.rs +++ b/src/visitor/postgres.rs @@ -119,52 +119,56 @@ impl<'a> Visitor<'a> for Postgres<'a> { self.write(")") } + #[cfg(feature = "json-1")] fn visit_condition_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> fmt::Result { - if cfg!(feature = "json-1") { - let (left_is_json, right_is_json) = (left.is_json_value(), right.is_json_value()); - - self.visit_expression(left)?; + let (left_is_json, right_is_json) = (left.is_json_value(), right.is_json_value()); - if right_is_json { - self.write("::jsonb")?; - } + self.visit_expression(left)?; - self.write(" = ")?; + if right_is_json { + self.write("::jsonb")?; + } - if left_is_json { - self.write("::jsonb")?; - } + self.write(" = ")?; - self.visit_expression(right) - } else { - self.visit_expression(left)?; - self.write(" = ")?; - self.visit_expression(right) + if left_is_json { + self.write("::jsonb")?; } + + self.visit_expression(right) } - fn visit_condition_not_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> fmt::Result { - if cfg!(feature = "json-1") { - let (left_is_json, right_is_json) = (left.is_json_value(), right.is_json_value()); + #[cfg(not(feature = "json-1"))] + fn visit_condition_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> fmt::Result { + self.visit_expression(left)?; + self.write(" = ")?; + self.visit_expression(right) + } - self.visit_expression(left)?; + #[cfg(feature = "json-1")] + fn visit_condition_not_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> fmt::Result { + let (left_is_json, right_is_json) = (left.is_json_value(), right.is_json_value()); - if right_is_json { - self.write("::jsonb")?; - } + self.visit_expression(left)?; - self.write(" <> ")?; + if right_is_json { + self.write("::jsonb")?; + } - if left_is_json { - self.write("::jsonb")?; - } + self.write(" <> ")?; - self.visit_expression(right) - } else { - self.visit_expression(left)?; - self.write(" <> ")?; - self.visit_expression(right) + if left_is_json { + self.write("::jsonb")?; } + + self.visit_expression(right) + } + + #[cfg(not(feature = "json-1"))] + fn visit_condition_not_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> fmt::Result { + self.visit_expression(left)?; + self.write(" <> ")?; + self.visit_expression(right) } }