teo_sql_connector/stmts/select/
where.rs1use crate::schema::dialect::SQLDialect;
2use crate::schema::value::encode::ToSQLString;
3
4pub enum WhereClause {
5 And(Vec<String>),
6 Or(Vec<String>),
7 Not(String),
8}
9
10pub trait ToWrappedSQLString {
11 fn to_wrapped_string(&self, dialect: SQLDialect) -> String;
12}
13
14impl ToWrappedSQLString for WhereClause {
15 fn to_wrapped_string(&self, dialect: SQLDialect) -> String {
16 "(".to_owned() + &self.to_string(dialect) + ")"
17 }
18}
19
20impl ToSQLString for WhereClause {
21 fn to_string(&self, _dialect: SQLDialect) -> String {
22 match self {
23 WhereClause::And(items) => items.join(" AND "),
24 WhereClause::Or(items) => items.join(" OR "),
25 WhereClause::Not(item) => format!("NOT {item}"),
26 }
27 }
28}
29
30pub struct WhereItem<'a>(&'a str, &'a str, &'a str);
31
32impl<'a> ToSQLString for WhereItem<'a> {
33 fn to_string(&self, _dialect: SQLDialect) -> String {
34 format!("{} {} {}", self.0, self.1, self.2)
35 }
36}