pub enum Term {
Atom(String),
Condition(Box<Term>, Op, Box<Term>),
Parens(Box<Term>),
Null,
}Expand description
The Term enum is used to specify a condition in a query (WHERE clause). It is used in the Query struct.
A Term can be an atom, a condition, parentheses or null. Observant minds might notice that this is a fragment of a grammar and simply a reified syntax tree.
Examples
Atom:
use squeal::*;
let result = Term::Atom("a".to_string()).sql();
assert_eq!(result, "a");A number of different conditions and complex combinations:
use squeal::*;
let result = Term::Condition(
Box::new(Term::Atom("a".to_string())),
Op::O("<>".to_string()),
Box::new(Term::Atom("b".to_string())),
).sql();
assert_eq!(result, "a <> b");An example setting up a = b AND (c = d OR e <> f):
use squeal::*;
let result = Term::Condition(
Box::new(Term::Atom("a".to_string())),
Op::Equals,
Box::new(Term::Condition(
Box::new(Term::Atom("b".to_string())),
Op::And,
Box::new(Term::Parens(Box::new(Term::Condition(
Box::new(Term::Atom("c".to_string())),
Op::Equals,
Box::new(Term::Condition(
Box::new(Term::Atom("d".to_string())),
Op::Or,
Box::new(Term::Atom("e".to_string())),
))))))))).sql();
assert_eq!(result, "a = b AND (c = d OR e)");Variants§
Atom(String)
An atom is a single identifier.
Condition(Box<Term>, Op, Box<Term>)
A condition is a combination of two terms and an operator.
Parens(Box<Term>)
A parenthesized term.
Null
A null term.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Term
impl Send for Term
impl Sync for Term
impl Unpin for Term
impl UnwindSafe for Term
Blanket Implementations§
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
Mutably borrows from an owned value. Read more