Skip to content

Commit

Permalink
change formatter interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kysshsy committed Jul 31, 2024
1 parent 7efda84 commit f27adeb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions supabase-wrappers/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl FromDatum for Cell {
}

pub trait CellFormatter {
fn fmt_cell(&self, cell: &Cell) -> String;
fn fmt_cell(&mut self, cell: &Cell) -> String;
}

struct DefaultFormatter {}
Expand All @@ -229,7 +229,7 @@ impl DefaultFormatter {
}

impl CellFormatter for DefaultFormatter {
fn fmt_cell(&self, cell: &Cell) -> String {
fn fmt_cell(&mut self, cell: &Cell) -> String {
format!("{}", cell)
}
}
Expand Down Expand Up @@ -369,11 +369,11 @@ pub struct Qual {

impl Qual {
pub fn deparse(&self) -> String {
let formatter = DefaultFormatter::new();
self.deparse_with_fmt(formatter)
let mut formatter = DefaultFormatter::new();
self.deparse_with_fmt(&mut formatter)
}

pub fn deparse_with_fmt<T: CellFormatter>(&self, t: T) -> String {
pub fn deparse_with_fmt<T: CellFormatter>(&self, t: &mut T) -> String {
if self.use_or {
match &self.value {
Value::Cell(_) => unreachable!(),
Expand All @@ -394,11 +394,11 @@ impl Qual {
Cell::String(cell) if cell == "null" => {
format!("{} {} null", self.field, self.operator)
}
_ => format!("{} {} {}", self.field, self.operator, cell),
_ => format!("{} {} {}", self.field, self.operator, t.fmt_cell(cell)),
},
"~~" => format!("{} like {}", self.field, cell),
"!~~" => format!("{} not like {}", self.field, cell),
_ => format!("{} {} {}", self.field, self.operator, cell),
"~~" => format!("{} like {}", self.field, t.fmt_cell(cell)),
"!~~" => format!("{} not like {}", self.field, t.fmt_cell(cell)),
_ => format!("{} {} {}", self.field, self.operator, t.fmt_cell(cell)),
},
Value::Array(_) => unreachable!(),
}
Expand Down

0 comments on commit f27adeb

Please sign in to comment.