1use crate::{Values, expr::*, query::*};
4use std::fmt::Debug;
5
6#[cfg(feature = "backend-postgres")]
7use crate::extension::postgres::PgBinOper;
8#[cfg(feature = "backend-sqlite")]
9use crate::extension::sqlite::SqliteBinOper;
10
11mod iden;
13
14pub use iden::*;
15
16#[cfg(not(feature = "thread-safe"))]
21pub type RcOrArc<T> = std::rc::Rc<T>;
22#[cfg(feature = "thread-safe")]
27pub type RcOrArc<T> = std::sync::Arc<T>;
28
29#[derive(Debug)]
37pub struct SeaRc;
38
39impl SeaRc {
40 #[allow(clippy::new_ret_no_self)]
48 pub fn new<I>(i: I) -> DynIden
49 where
50 I: Iden,
51 {
52 DynIden(i.quoted())
53 }
54
55 pub fn clone(iden: &DynIden) -> DynIden {
56 iden.clone()
57 }
58}
59
60#[derive(Debug, Clone, Copy, PartialEq, Eq)]
62#[non_exhaustive]
63pub enum UnOper {
64 Not,
65}
66
67#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71#[non_exhaustive]
72pub enum BinOper {
73 And,
74 Or,
75 Like,
76 NotLike,
77 Is,
78 IsNot,
79 In,
80 NotIn,
81 Between,
82 NotBetween,
83 Equal,
84 NotEqual,
85 SmallerThan,
86 GreaterThan,
87 SmallerThanOrEqual,
88 GreaterThanOrEqual,
89 Add,
90 Sub,
91 Mul,
92 Div,
93 Mod,
94 BitAnd,
95 BitOr,
96 LShift,
97 RShift,
98 As,
99 Escape,
100 Custom(&'static str),
101 #[cfg(feature = "backend-postgres")]
102 PgOperator(PgBinOper),
103 #[cfg(feature = "backend-sqlite")]
104 SqliteOperator(SqliteBinOper),
105}
106
107#[derive(Debug, Clone, PartialEq)]
109pub enum LogicalChainOper {
110 And(Expr),
111 Or(Expr),
112}
113
114#[derive(Debug, Clone, Copy, PartialEq, Eq)]
116pub enum JoinType {
117 Join,
118 CrossJoin,
119 InnerJoin,
120 LeftJoin,
121 RightJoin,
122 FullOuterJoin,
123 StraightJoin,
124}
125
126#[derive(Debug, Clone, Copy, PartialEq, Eq)]
128pub enum NullOrdering {
129 First,
130 Last,
131}
132
133#[derive(Debug, Clone, PartialEq)]
135pub struct OrderExpr {
136 pub(crate) expr: Expr,
137 pub(crate) order: Order,
138 pub(crate) nulls: Option<NullOrdering>,
139}
140
141#[derive(Debug, Clone, PartialEq)]
143#[non_exhaustive]
144pub enum JoinOn {
145 Condition(Box<ConditionHolder>),
146 Columns(Vec<Expr>),
147}
148
149#[derive(Debug, Clone, PartialEq)]
151#[non_exhaustive]
152pub enum Order {
153 Asc,
154 Desc,
155 Field(Values),
156}
157
158#[derive(Debug, Clone, PartialEq)]
162#[non_exhaustive]
163pub enum Keyword {
164 Null,
165 CurrentDate,
166 CurrentTime,
167 CurrentTimestamp,
168 Default,
169 Custom(DynIden),
170}
171
172#[derive(Debug, Clone)]
174pub struct LikeExpr {
175 pub(crate) pattern: String,
176 pub(crate) escape: Option<char>,
177}
178
179impl LikeExpr {
180 pub fn new<T>(pattern: T) -> Self
181 where
182 T: Into<String>,
183 {
184 Self {
185 pattern: pattern.into(),
186 escape: None,
187 }
188 }
189
190 #[deprecated(since = "0.29.0", note = "Please use the [`LikeExpr::new`] method")]
191 pub fn str<T>(pattern: T) -> Self
192 where
193 T: Into<String>,
194 {
195 Self {
196 pattern: pattern.into(),
197 escape: None,
198 }
199 }
200
201 pub fn escape(self, c: char) -> Self {
202 Self {
203 pattern: self.pattern,
204 escape: Some(c),
205 }
206 }
207}
208
209pub trait IntoLikeExpr: Into<LikeExpr> {
210 fn into_like_expr(self) -> LikeExpr;
211}
212
213impl<T> IntoLikeExpr for T
214where
215 T: Into<LikeExpr>,
216{
217 fn into_like_expr(self) -> LikeExpr {
218 self.into()
219 }
220}
221
222impl<T> From<T> for LikeExpr
223where
224 T: Into<String>,
225{
226 fn from(value: T) -> Self {
227 LikeExpr::new(value)
228 }
229}
230
231#[derive(Debug, Copy, Clone, PartialEq)]
233#[non_exhaustive]
234pub enum SubQueryOper {
235 Exists,
236 Any,
237 Some,
238 All,
239}