use crate::expr::{And, Eq, Expr, Gt, GtEq, IsNull, Like, Lt, LtEq, NotEq, Or};
use crate::types::{Boolean, Float, Integer, Text};
pub trait Column: Expr + Sized {
type Table;
const NAME: &'static str;
}
pub trait ExprExt: Expr + Sized {
fn eq<R>(self, rhs: R) -> Eq<Self, R>
where
R: Expr<SqlType = Self::SqlType>,
{
Eq {
left: self,
right: rhs,
}
}
fn ne<R>(self, rhs: R) -> NotEq<Self, R>
where
R: Expr<SqlType = Self::SqlType>,
{
NotEq {
left: self,
right: rhs,
}
}
#[allow(clippy::wrong_self_convention)]
fn is_null(self) -> IsNull<Self> {
IsNull { inner: self }
}
}
impl<E: Expr + Sized> ExprExt for E {}
pub trait IntOps: Expr<SqlType = Integer> + Sized {
fn lt<R: Expr<SqlType = Integer>>(self, rhs: R) -> Lt<Self, R> {
Lt {
left: self,
right: rhs,
}
}
fn lte<R: Expr<SqlType = Integer>>(self, rhs: R) -> LtEq<Self, R> {
LtEq {
left: self,
right: rhs,
}
}
fn gt<R: Expr<SqlType = Integer>>(self, rhs: R) -> Gt<Self, R> {
Gt {
left: self,
right: rhs,
}
}
fn gte<R: Expr<SqlType = Integer>>(self, rhs: R) -> GtEq<Self, R> {
GtEq {
left: self,
right: rhs,
}
}
}
impl<E> IntOps for E where E: Expr<SqlType = Integer> + Sized {}
pub trait FloatOps: Expr<SqlType = Float> + Sized {
fn lt<R: Expr<SqlType = Float>>(self, rhs: R) -> Lt<Self, R> {
Lt {
left: self,
right: rhs,
}
}
fn lte<R: Expr<SqlType = Float>>(self, rhs: R) -> LtEq<Self, R> {
LtEq {
left: self,
right: rhs,
}
}
fn gt<R: Expr<SqlType = Float>>(self, rhs: R) -> Gt<Self, R> {
Gt {
left: self,
right: rhs,
}
}
fn gte<R: Expr<SqlType = Float>>(self, rhs: R) -> GtEq<Self, R> {
GtEq {
left: self,
right: rhs,
}
}
}
impl<E> FloatOps for E where E: Expr<SqlType = Float> + Sized {}
pub trait TextOps: Expr<SqlType = Text> + Sized {
fn lt<R: Expr<SqlType = Text>>(self, rhs: R) -> Lt<Self, R> {
Lt {
left: self,
right: rhs,
}
}
fn lte<R: Expr<SqlType = Text>>(self, rhs: R) -> LtEq<Self, R> {
LtEq {
left: self,
right: rhs,
}
}
fn gt<R: Expr<SqlType = Text>>(self, rhs: R) -> Gt<Self, R> {
Gt {
left: self,
right: rhs,
}
}
fn gte<R: Expr<SqlType = Text>>(self, rhs: R) -> GtEq<Self, R> {
GtEq {
left: self,
right: rhs,
}
}
fn like<R: Expr<SqlType = Text>>(self, pattern: R) -> Like<Self, R> {
Like {
left: self,
right: pattern,
}
}
}
impl<E> TextOps for E where E: Expr<SqlType = Text> + Sized {}
pub trait BoolOps: Expr<SqlType = Boolean> + Sized {
fn and<R: Expr<SqlType = Boolean>>(self, rhs: R) -> And<Self, R> {
And {
left: self,
right: rhs,
}
}
fn or<R: Expr<SqlType = Boolean>>(self, rhs: R) -> Or<Self, R> {
Or {
left: self,
right: rhs,
}
}
}
impl<E> BoolOps for E where E: Expr<SqlType = Boolean> + Sized {}