Trait diesel::expression_methods::TextExpressionMethods[][src]

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

Methods present on text expressions

Provided methods

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);

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);

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);

Implementors