7373 ///
7474 /// ```rust
7575 /// # include!("../doctest_setup.rs");
76- ///
76+ /// #
7777 /// # table! {
7878 /// # users {
7979 /// # id -> Integer,
@@ -125,7 +125,7 @@ where
125125 ///
126126 /// ```rust
127127 /// # include!("../doctest_setup.rs");
128- ///
128+ /// #
129129 /// # table! {
130130 /// # users {
131131 /// # id -> Integer,
@@ -199,7 +199,7 @@ impl<ST, T, GB> ValidGrouping<GB> for SqlLiteral<ST, T> {
199199 type IsAggregate = is_aggregate:: Never ;
200200}
201201
202- /// Use literal SQL in the query builder
202+ /// Use literal SQL in the query builder.
203203///
204204/// Available for when you truly cannot represent something using the expression
205205/// DSL. You will need to provide the SQL type of the expression, in addition to
@@ -209,6 +209,8 @@ impl<ST, T, GB> ValidGrouping<GB> for SqlLiteral<ST, T> {
209209/// your query. If you want to write the entire query using raw SQL, use
210210/// [`sql_query`](../fn.sql_query.html) instead.
211211///
212+ /// Query parameters can be bound into the literal SQL using [`SqlLiteral::bind()`].
213+ ///
212214/// # Safety
213215///
214216/// The compiler will be unable to verify the correctness of the annotated type.
@@ -220,10 +222,11 @@ impl<ST, T, GB> ValidGrouping<GB> for SqlLiteral<ST, T> {
220222/// ```rust
221223/// # include!("../doctest_setup.rs");
222224/// # fn main() {
223- /// # run_test().unwrap();
225+ /// # run_test_1().unwrap();
226+ /// # run_test_2().unwrap();
224227/// # }
225228/// #
226- /// # fn run_test () -> QueryResult<()> {
229+ /// # fn run_test_1 () -> QueryResult<()> {
227230/// # use schema::users::dsl::*;
228231/// # use diesel::sql_types::Bool;
229232/// use diesel::dsl::sql;
@@ -233,7 +236,30 @@ impl<ST, T, GB> ValidGrouping<GB> for SqlLiteral<ST, T> {
233236/// assert_eq!(expected, user);
234237/// # Ok(())
235238/// # }
239+ /// #
240+ /// # fn run_test_2() -> QueryResult<()> {
241+ /// # use crate::schema::users::dsl::*;
242+ /// # use diesel::dsl::sql;
243+ /// # use diesel::sql_types::{Bool, Integer, Text};
244+ /// # let connection = establish_connection();
245+ /// # diesel::insert_into(users)
246+ /// # .values(name.eq("Ryan"))
247+ /// # .execute(&connection).unwrap();
248+ /// let query = users
249+ /// .select(name)
250+ /// .filter(
251+ /// sql::<Bool>("id > ")
252+ /// .bind::<Integer,_>(1)
253+ /// .sql(" AND name <> ")
254+ /// .bind::<Text, _>("Ryan")
255+ /// )
256+ /// .get_results(&connection);
257+ /// let expected = vec!["Tess".to_string()];
258+ /// assert_eq!(Ok(expected), query);
259+ /// # Ok(())
260+ /// # }
236261/// ```
262+ /// [`SqlLiteral::bind()`]: ../expression/struct.SqlLiteral.html#method.bind
237263pub fn sql < ST > ( sql : & str ) -> SqlLiteral < ST >
238264where
239265 ST : TypedExpressionType ,
@@ -245,7 +271,7 @@ where
245271#[ must_use = "Queries are only executed when calling `load`, `get_result`, or similar." ]
246272/// Returned by the [`SqlLiteral::bind()`] method when binding a value to a fragment of SQL.
247273///
248- /// [`bind()`]: ./struct.SqlLiteral.html#method.bind
274+ /// [`SqlLiteral:: bind()`]: ./struct.SqlLiteral.html#method.bind
249275pub struct UncheckedBind < Query , Value > {
250276 query : Query ,
251277 value : Value ,
@@ -259,7 +285,7 @@ where
259285 UncheckedBind { query, value }
260286 }
261287
262- /// Use literal SQL in the query builder
288+ /// Use literal SQL in the query builder.
263289 ///
264290 /// This function is intended for use when you need a small bit of raw SQL in
265291 /// your query. If you want to write the entire query using raw SQL, use
@@ -275,7 +301,7 @@ where
275301 ///
276302 /// ```rust
277303 /// # include!("../doctest_setup.rs");
278- ///
304+ /// #
279305 /// # table! {
280306 /// # users {
281307 /// # id -> Integer,
0 commit comments