Skip to content

Commit 3770d2d

Browse files
committed
add doctests for pg text expressions
1 parent b036058 commit 3770d2d

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

diesel/src/pg/expression/expression_methods.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,59 @@ impl<T> SortExpressionMethods for Desc<T> {}
368368

369369
pub trait PgTextExpressionMethods: Expression<SqlType = Text> + Sized {
370370
/// Returns a SQL `ILIKE` expression
371+
///
372+
/// # Example
373+
///
374+
/// ```rust
375+
/// # #[macro_use] extern crate diesel;
376+
/// # #[macro_use] extern crate diesel_codegen;
377+
/// # include!("../../doctest_setup.rs");
378+
/// # use schema::users;
379+
/// #
380+
/// # fn main() {
381+
/// # use schema::users::dsl::*;
382+
/// # let connection = establish_connection();
383+
/// #
384+
/// let like_sean = users
385+
/// .select(name)
386+
/// .filter(name.ilike("sean"))
387+
/// .get_results::<String>(&connection)
388+
/// .expect("Failed");
389+
///
390+
/// let expected = vec!["Sean".to_string()];
391+
///
392+
/// assert_eq!(expected, like_sean);
393+
/// # }
394+
/// ```
371395
fn ilike<T: AsExpression<Text>>(self, other: T) -> ILike<Self, T::Expression> {
372396
ILike::new(self.as_expression(), other.as_expression())
373397
}
374398

375399
/// Returns a SQL `NOT ILIKE` expression
400+
///
401+
/// # Example
402+
///
403+
/// ```rust
404+
/// # #[macro_use] extern crate diesel;
405+
/// # #[macro_use] extern crate diesel_codegen;
406+
/// # include!("../../doctest_setup.rs");
407+
/// # use schema::users;
408+
/// #
409+
/// # fn main() {
410+
/// # use schema::users::dsl::*;
411+
/// # let connection = establish_connection();
412+
/// #
413+
/// let not_like_sean = users
414+
/// .select(name)
415+
/// .filter(name.not_ilike("sean"))
416+
/// .get_results::<String>(&connection)
417+
/// .expect("Failed");
418+
///
419+
/// let expected = vec!["Tess".to_string()];
420+
///
421+
/// assert_eq!(expected, not_like_sean);
422+
/// # }
423+
/// ```
376424
fn not_ilike<T: AsExpression<Text>>(self, other: T) -> NotILike<Self, T::Expression> {
377425
NotILike::new(self.as_expression(), other.as_expression())
378426
}

0 commit comments

Comments
 (0)