use rusqlite::types::Value;
use crate::rusqlite::ToRusqliteSingleField;
use crate::sql::Field;
use crate::BooleanCriterium;
impl<F: Field> ToRusqliteSingleField<F> for BooleanCriterium {
fn get_sql_where(&self, field_name: &str) -> String {
match self {
Self::Equals(true) => format!("COALESCE({}, 0)", field_name),
Self::Equals(false) => format!("COALESCE(NOT {}, 0)", field_name),
Self::IsNone => format!("{field_name} is NULL"),
}
}
fn get_inverted_sql_where(&self, field_name: &str) -> Option<String> {
Some(match self {
Self::Equals(true) => format!("COALESCE(NOT {}, 1)", field_name),
Self::Equals(false) => format!("COALESCE({}, 1)", field_name),
Self::IsNone => format!("{field_name} is not NULL"),
})
}
fn get_where_values(&self, _is_inverted: bool) -> Vec<Value> {
Vec::new()
}
}