use crate::{
concat::Concat,
fmt,
structure::{Values, ValuesClause},
utils::push_unique,
};
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
use crate::behavior::WithQuery;
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
impl WithQuery for Values {}
impl Values {
pub fn as_string(&self) -> String {
let fmts = fmt::one_line();
self.concat(&fmts)
}
pub fn debug(self) -> Self {
let fmts = fmt::multiline();
println!("{}", fmt::format(self.concat(&fmts), &fmts));
self
}
pub fn new() -> Self {
Self::default()
}
pub fn print(self) -> Self {
let fmts = fmt::one_line();
println!("{}", fmt::format(self.concat(&fmts), &fmts));
self
}
pub fn raw(mut self, raw_sql: &str) -> Self {
push_unique(&mut self._raw, raw_sql.trim().to_string());
self
}
pub fn raw_after(mut self, clause: ValuesClause, raw_sql: &str) -> Self {
self._raw_after.push((clause, raw_sql.trim().to_string()));
self
}
pub fn raw_before(mut self, clause: ValuesClause, raw_sql: &str) -> Self {
self._raw_before.push((clause, raw_sql.trim().to_string()));
self
}
#[cfg(not(feature = "mysql"))]
pub fn values(mut self, expression: &str) -> Self {
push_unique(&mut self._values, expression.trim().to_string());
self
}
}
#[cfg(feature = "mysql")]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
impl Values {
pub fn row(mut self, expression: &str) -> Self {
push_unique(&mut self._values, expression.trim().to_string());
self
}
}
impl std::fmt::Display for Values {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.as_string())
}
}
impl std::fmt::Debug for Values {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let fmts = fmt::multiline();
write!(f, "{}", fmt::format(self.concat(&fmts), &fmts))
}
}