Trait diesel::prelude::TextExpressionMethods

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

Methods present on text expressions

Provided Methods§

source

fn concat<T>(self, other: T) -> Concat<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

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

fn like<T>(self, other: T) -> Like<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

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

fn not_like<T>(self, other: T) -> NotLike<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

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

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> TextExpressionMethods for T
where T: Expression, T::SqlType: TextOrNullableText,