Trait block_tools::db::use_diesel::prelude::TextExpressionMethods[][src]

pub trait TextExpressionMethods: Expression {
    pub fn concat<T>(
        self,
        other: T
    ) -> Concat<Self, <T as AsExpression<Self::SqlType>>::Expression>
    where
        T: AsExpression<Self::SqlType>
, { ... }
pub fn like<T>(
        self,
        other: T
    ) -> Like<Self, <T as AsExpression<Self::SqlType>>::Expression>
    where
        T: AsExpression<Self::SqlType>
, { ... }
pub fn not_like<T>(
        self,
        other: T
    ) -> NotLike<Self, <T as AsExpression<Self::SqlType>>::Expression>
    where
        T: AsExpression<Self::SqlType>
, { ... } }

Methods present on text expressions

Provided methods

pub fn concat<T>(
    self,
    other: T
) -> Concat<Self, <T as AsExpression<Self::SqlType>>::Expression> where
    T: AsExpression<Self::SqlType>, 
[src]

Concatenates two strings using the || operator.

Example

let names = users.select(name.concat(" the Greatest")).load(&connection);
let expected_names = vec![
    "Sean the Greatest".to_string(),
    "Tess the Greatest".to_string(),
];
assert_eq!(Ok(expected_names), names);

// If the value is nullable, the output will be nullable
let names = users.select(hair_color.concat("ish")).load(&connection);
let expected_names = vec![
    Some("Greenish".to_string()),
    None,
];
assert_eq!(Ok(expected_names), names);

pub fn like<T>(
    self,
    other: T
) -> Like<Self, <T as AsExpression<Self::SqlType>>::Expression> where
    T: AsExpression<Self::SqlType>, 
[src]

Returns a SQL LIKE expression

This method is case insensitive for SQLite and MySQL. On PostgreSQL, LIKE is case sensitive. You may use ilike() for case insensitive comparison on PostgreSQL.

Examples

let starts_with_s = users
    .select(name)
    .filter(name.like("S%"))
    .load::<String>(&connection)?;
assert_eq!(vec!["Sean"], starts_with_s);

pub fn not_like<T>(
    self,
    other: T
) -> NotLike<Self, <T as AsExpression<Self::SqlType>>::Expression> where
    T: AsExpression<Self::SqlType>, 
[src]

Returns a SQL NOT LIKE expression

This method is case insensitive for SQLite and MySQL. On PostgreSQL NOT LIKE is case sensitive. You may use not_ilike() for case insensitive comparison on PostgreSQL.

Examples

let doesnt_start_with_s = users
    .select(name)
    .filter(name.not_like("S%"))
    .load::<String>(&connection)?;
assert_eq!(vec!["Tess"], doesnt_start_with_s);
Loading content...

Implementors

impl<T> TextExpressionMethods for T where
    T: Expression,
    <T as Expression>::SqlType: TextOrNullableText, 
[src]

Loading content...