Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Fix compilation errors if json is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn committed May 20, 2020
1 parent 7d89232 commit e6d1207
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions src/visitor/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit e6d1207

Please sign in to comment.