use crate::{Values, expr::*, query::*};
use std::fmt::Debug;
#[cfg(feature = "backend-postgres")]
use crate::extension::postgres::PgBinOper;
#[cfg(feature = "backend-sqlite")]
use crate::extension::sqlite::SqliteBinOper;
mod iden;
pub use iden::*;
#[cfg(not(feature = "thread-safe"))]
pub type RcOrArc<T> = std::rc::Rc<T>;
#[cfg(feature = "thread-safe")]
pub type RcOrArc<T> = std::sync::Arc<T>;
#[derive(Debug)]
pub struct SeaRc;
impl SeaRc {
#[allow(clippy::new_ret_no_self)]
pub fn new<I>(i: I) -> DynIden
where
I: Iden,
{
DynIden(i.quoted())
}
pub fn clone(iden: &DynIden) -> DynIden {
iden.clone()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum UnOper {
Not,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum BinOper {
And,
Or,
Like,
NotLike,
Is,
IsNot,
In,
NotIn,
Between,
NotBetween,
Equal,
NotEqual,
SmallerThan,
GreaterThan,
SmallerThanOrEqual,
GreaterThanOrEqual,
Add,
Sub,
Mul,
Div,
Mod,
BitAnd,
BitOr,
LShift,
RShift,
As,
Escape,
Custom(&'static str),
#[cfg(feature = "backend-postgres")]
PgOperator(PgBinOper),
#[cfg(feature = "backend-sqlite")]
SqliteOperator(SqliteBinOper),
}
#[derive(Debug, Clone, PartialEq)]
pub enum LogicalChainOper {
And(Expr),
Or(Expr),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum JoinType {
Join,
CrossJoin,
InnerJoin,
LeftJoin,
RightJoin,
FullOuterJoin,
StraightJoin,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NullOrdering {
First,
Last,
}
#[derive(Debug, Clone, PartialEq)]
pub struct OrderExpr {
pub(crate) expr: Expr,
pub(crate) order: Order,
pub(crate) nulls: Option<NullOrdering>,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum JoinOn {
Condition(Box<ConditionHolder>),
Columns(Vec<Expr>),
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum Order {
Asc,
Desc,
Field(Values),
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum Keyword {
Null,
CurrentDate,
CurrentTime,
CurrentTimestamp,
Default,
Custom(DynIden),
}
#[derive(Debug, Clone)]
pub struct LikeExpr {
pub(crate) pattern: String,
pub(crate) escape: Option<char>,
}
impl LikeExpr {
pub fn new<T>(pattern: T) -> Self
where
T: Into<String>,
{
Self {
pattern: pattern.into(),
escape: None,
}
}
#[deprecated(since = "0.29.0", note = "Please use the [`LikeExpr::new`] method")]
pub fn str<T>(pattern: T) -> Self
where
T: Into<String>,
{
Self {
pattern: pattern.into(),
escape: None,
}
}
pub fn escape(self, c: char) -> Self {
Self {
pattern: self.pattern,
escape: Some(c),
}
}
}
pub trait IntoLikeExpr: Into<LikeExpr> {
fn into_like_expr(self) -> LikeExpr;
}
impl<T> IntoLikeExpr for T
where
T: Into<LikeExpr>,
{
fn into_like_expr(self) -> LikeExpr {
self.into()
}
}
impl<T> From<T> for LikeExpr
where
T: Into<String>,
{
fn from(value: T) -> Self {
LikeExpr::new(value)
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[non_exhaustive]
pub enum SubQueryOper {
Exists,
Any,
Some,
All,
}