Enum squeal::Term

source ·
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§

source§

impl Sql for Term

source§

fn sql(&self) -> String

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.