pub enum SqlExpr {
Column(String),
Literal(Value),
BinaryOp {
left: Box<SqlExpr>,
op: BinaryOp,
right: Box<SqlExpr>,
},
Negate(Box<SqlExpr>),
Function {
name: String,
args: Vec<SqlExpr>,
},
Cast {
expr: Box<SqlExpr>,
to_type: CastType,
},
Case {
operand: Option<Box<SqlExpr>>,
when_thens: Vec<(SqlExpr, SqlExpr)>,
else_expr: Option<Box<SqlExpr>>,
},
Coalesce(Vec<SqlExpr>),
NullIf(Box<SqlExpr>, Box<SqlExpr>),
IsNull {
expr: Box<SqlExpr>,
negated: bool,
},
OldColumn(String),
ExcludedColumn(String),
}Expand description
A serializable SQL expression that can be evaluated against a document.
Variants§
Column(String)
Column reference: extract field value from the document.
Literal(Value)
Literal value.
BinaryOp
Binary operation: left op right.
Negate(Box<SqlExpr>)
Unary negation: -expr or NOT expr.
Function
Scalar function call.
Cast
CAST(expr AS type).
Case
CASE WHEN cond1 THEN val1 … ELSE default END.
Fields
Coalesce(Vec<SqlExpr>)
COALESCE(expr1, expr2, …): first non-null value.
NullIf(Box<SqlExpr>, Box<SqlExpr>)
NULLIF(expr1, expr2): returns NULL if expr1 = expr2, else expr1.
IsNull
IS NULL / IS NOT NULL.
OldColumn(String)
OLD column reference: extract field value from the pre-update document.
Used in TRANSITION CHECK predicates. Resolves against the OLD row
when evaluated via eval_with_old(). Returns NULL in normal eval().
ExcludedColumn(String)
EXCLUDED.col reference from INSERT ... ON CONFLICT DO UPDATE:
the column value from the row proposed for insertion that
triggered the conflict. Resolves against the incoming row when
evaluated via eval_with_excluded(). Returns NULL in plain
eval() / eval_with_old().
Implementations§
Source§impl SqlExpr
impl SqlExpr
Sourcepub fn eval(&self, doc: &Value) -> Value
pub fn eval(&self, doc: &Value) -> Value
Evaluate this expression against a document.
Column references look up fields in the document. Missing fields
return Null. Arithmetic on non-numeric values returns Null.
OldColumn(..) resolves to Null (use eval_with_old for the
TRANSITION CHECK path).
Sourcepub fn eval_with_old(&self, new_doc: &Value, old_doc: &Value) -> Value
pub fn eval_with_old(&self, new_doc: &Value, old_doc: &Value) -> Value
Evaluate with access to both NEW and OLD documents, used by
TRANSITION CHECK predicates. Column(name) resolves against
new_doc; OldColumn(name) resolves against old_doc.
Sourcepub fn eval_with_excluded(&self, doc: &Value, excluded: &Value) -> Value
pub fn eval_with_excluded(&self, doc: &Value, excluded: &Value) -> Value
Evaluate with access to the incoming EXCLUDED.* row, used by
INSERT ... ON CONFLICT DO UPDATE. Column(name) resolves
against the existing (current) row doc; ExcludedColumn(name)
resolves against excluded.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SqlExpr
impl<'de> Deserialize<'de> for SqlExpr
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a> FromMessagePack<'a> for SqlExpr
impl<'a> FromMessagePack<'a> for SqlExpr
Source§impl ToMessagePack for SqlExpr
impl ToMessagePack for SqlExpr
impl StructuralPartialEq for SqlExpr
Auto Trait Implementations§
impl Freeze for SqlExpr
impl RefUnwindSafe for SqlExpr
impl Send for SqlExpr
impl Sync for SqlExpr
impl Unpin for SqlExpr
impl UnsafeUnpin for SqlExpr
impl UnwindSafe for SqlExpr
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.