pub struct Expr<'column, S, T> { /* private fields */ }
Expand description
This is an expression that can be used in queries.
- The lifetime parameter
'column
specifies which columns need to be in scope. - The type parameter
S
specifies the expected schema of the query. - And finally the type paramter
T
specifies the type of the expression.
Expr implements Deref to have table extension methods in case the type is a table type.
Implementations§
Source§impl<'column, S, T: NumTyp> Expr<'column, S, T>
impl<'column, S, T: NumTyp> Expr<'column, S, T>
Sourcepub fn add(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, T>
pub fn add( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>
Add two expressions together.
assert_eq!(txn.query_one(1.into_expr().add(2)), 3);
assert_eq!(txn.query_one(1.0.into_expr().add(2.0)), 3.0);
Sourcepub fn sub(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, T>
pub fn sub( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>
Subtract one expression from another.
assert_eq!(txn.query_one(1.into_expr().sub(2)), -1);
assert_eq!(txn.query_one(1.0.into_expr().sub(2.0)), -1.0);
Sourcepub fn mul(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, T>
pub fn mul( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>
Multiply two expressions together.
assert_eq!(txn.query_one(2.into_expr().mul(3)), 6);
assert_eq!(txn.query_one(2.0.into_expr().mul(3.0)), 6.0);
Sourcepub fn lt(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn lt( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Compute the less than operator (<) of two expressions.
assert_eq!(txn.query_one(2.into_expr().lt(3)), true);
assert_eq!(txn.query_one(1.into_expr().lt(1)), false);
assert_eq!(txn.query_one(3.0.into_expr().lt(1.0)), false);
Sourcepub fn lte(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn lte( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Compute the less than or equal operator (<=) of two expressions.
assert_eq!(txn.query_one(2.into_expr().lte(2)), true);
assert_eq!(txn.query_one(3.0.into_expr().lte(1.0)), false);
Source§impl<'column, S, T: EqTyp + 'static> Expr<'column, S, T>
impl<'column, S, T: EqTyp + 'static> Expr<'column, S, T>
Sourcepub fn eq(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn eq( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Check whether two expressions are equal.
assert_eq!(txn.query_one(2.into_expr().eq(2)), true);
assert_eq!(txn.query_one(3.0.into_expr().eq(3.0)), true);
assert_eq!(txn.query_one("test".into_expr().eq("test")), true);
assert_eq!(txn.query_one(b"test".into_expr().eq(b"test" as &[u8])), true);
assert_eq!(txn.query_one(false.into_expr().eq(false)), true);
assert_eq!(txn.query_one(1.into_expr().eq(2)), false);
Source§impl<'column, S> Expr<'column, S, bool>
impl<'column, S> Expr<'column, S, bool>
Sourcepub fn not(&self) -> Expr<'column, S, bool>
pub fn not(&self) -> Expr<'column, S, bool>
Checks whether an expression is false.
assert_eq!(txn.query_one(true.into_expr().not()), false);
assert_eq!(txn.query_one(false.into_expr().not()), true);
Sourcepub fn and(
&self,
rhs: impl IntoExpr<'column, S, Typ = bool>,
) -> Expr<'column, S, bool>
pub fn and( &self, rhs: impl IntoExpr<'column, S, Typ = bool>, ) -> Expr<'column, S, bool>
Check if two expressions are both true.
assert_eq!(txn.query_one(true.into_expr().and(true)), true);
assert_eq!(txn.query_one(false.into_expr().and(true)), false);
assert_eq!(txn.query_one(false.into_expr().and(false)), false);
Sourcepub fn or(
&self,
rhs: impl IntoExpr<'column, S, Typ = bool>,
) -> Expr<'column, S, bool>
pub fn or( &self, rhs: impl IntoExpr<'column, S, Typ = bool>, ) -> Expr<'column, S, bool>
Check if one of two expressions is true.
assert_eq!(txn.query_one(true.into_expr().or(true)), true);
assert_eq!(txn.query_one(false.into_expr().or(true)), true);
assert_eq!(txn.query_one(false.into_expr().or(false)), false);
Source§impl<'column, S, Typ: 'static> Expr<'column, S, Option<Typ>>
impl<'column, S, Typ: 'static> Expr<'column, S, Option<Typ>>
Sourcepub fn unwrap_or(
&self,
rhs: impl IntoExpr<'column, S, Typ = Typ>,
) -> Expr<'column, S, Typ>
pub fn unwrap_or( &self, rhs: impl IntoExpr<'column, S, Typ = Typ>, ) -> Expr<'column, S, Typ>
Use the first expression if it is Some, otherwise use the second expression.
assert_eq!(txn.query_one(Some(10).into_expr().unwrap_or(5)), 10);
assert_eq!(txn.query_one(None::<String>.into_expr().unwrap_or("foo")), "foo");
Source§impl<'column, S> Expr<'column, S, String>
impl<'column, S> Expr<'column, S, String>
Sourcepub fn starts_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
pub fn starts_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
Check if the expression starts with the string pattern.
Matches case-sensitive. The pattern gets automatically escaped.
assert_eq!(txn.query_one("hello world".into_expr().starts_with("hello")), true);
assert_eq!(txn.query_one("hello world".into_expr().starts_with("Hello")), false);
Sourcepub fn ends_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
pub fn ends_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
Check if the expression ends with the string pattern.
Matches case-sensitive. The pattern gets automatically escaped.
assert_eq!(txn.query_one("hello world".into_expr().ends_with("world")), true);
assert_eq!(txn.query_one("hello world".into_expr().ends_with("World")), false);
Sourcepub fn contains(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
pub fn contains(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
Check if the expression contains the string pattern.
Matches case-sensitive. The pattern gets automatically escaped.
assert_eq!(txn.query_one("rhubarb".into_expr().contains("bar")), true);
assert_eq!(txn.query_one("rhubarb".into_expr().contains("Bar")), false);
Sourcepub fn glob(
&self,
rhs: impl IntoExpr<'column, S, Typ = String>,
) -> Expr<'column, S, bool>
pub fn glob( &self, rhs: impl IntoExpr<'column, S, Typ = String>, ) -> Expr<'column, S, bool>
Check if the expression matches the pattern docs.
This is a case-sensitive version of like. It uses Unix file globbing syntax for wild
cards. *
matches any sequence of characters and ?
matches any single character. [0-9]
matches
any single digit and [a-z]
matches any single lowercase letter. ^
negates the pattern.
assert_eq!(txn.query_one("hello world".into_expr().glob("?ello*")), true);
assert_eq!(txn.query_one("hello world".into_expr().glob("Hell*")), false);
Sourcepub fn like(&self, pattern: impl Into<String>) -> Expr<'column, S, bool>
pub fn like(&self, pattern: impl Into<String>) -> Expr<'column, S, bool>
Check if the expression matches the pattern docs.
As noted in the docs, it is case-insensitive for ASCII characters. Other characters are case-sensitive.
For creating patterns it uses %
as a wildcard for any sequence of characters and _
for any single character.
Special characters should be escaped with \
.
assert_eq!(txn.query_one("hello world".into_expr().like("HELLO%")), true);
assert_eq!(txn.query_one("hello world".into_expr().like("he_o%")), false);
Trait Implementations§
Source§impl<'columns, 'transaction, S, T> IntoSelect<'columns, 'transaction, S> for Expr<'columns, S, T>where
T: MyTyp,
impl<'columns, 'transaction, S, T> IntoSelect<'columns, 'transaction, S> for Expr<'columns, S, T>where
T: MyTyp,
Auto Trait Implementations§
impl<'column, S, T> Freeze for Expr<'column, S, T>
impl<'column, S, T> !RefUnwindSafe for Expr<'column, S, T>
impl<'column, S, T> !Send for Expr<'column, S, T>
impl<'column, S, T> !Sync for Expr<'column, S, T>
impl<'column, S, T> Unpin for Expr<'column, S, T>where
S: Unpin,
impl<'column, S, T> !UnwindSafe for Expr<'column, S, T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'columns, 'transaction, S, X> IntoSelectExt<'columns, 'transaction, S> for Xwhere
X: IntoSelect<'columns, 'transaction, S>,
impl<'columns, 'transaction, S, X> IntoSelectExt<'columns, 'transaction, S> for Xwhere
X: IntoSelect<'columns, 'transaction, S>,
Source§fn map_select<T>(
self,
f: impl FnMut(<X as IntoSelect<'columns, 'transaction, S>>::Out) -> T + 'transaction,
) -> Select<'columns, 'transaction, S, T>
fn map_select<T>( self, f: impl FnMut(<X as IntoSelect<'columns, 'transaction, S>>::Out) -> T + 'transaction, ) -> Select<'columns, 'transaction, S, T>
Select::map
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);