Struct diesel::expression::sql_literal::SqlLiteral [] [src]

pub struct SqlLiteral<ST> { /* fields omitted */ }

Available for when you truly cannot represent something using the expression DSL. You will need to provide the type of the expression, in addition to the SQL. The compiler will be unable to verify the correctness of this type.

To get a SQL literal, use the sql() function.

Methods

impl<ST> SqlLiteral<ST>
[src]

Bind a value for use with this SQL query.

Safety

This function should be used with care, as Diesel cannot validate that the value is of the right type nor can it validate that you have passed the correct number of parameters.

Examples

#[cfg(feature="postgres")]
let query = sql::<Integer>("SELECT id FROM users WHERE name = $1");
#[cfg(not(feature="postgres"))]
let query = sql::<Integer>("SELECT id FROM users WHERE name = ?");
let seans_id = query.clone().bind::<Text, _>("Sean")
    .get_result(&connection);
assert_eq!(Ok(1), seans_id);
let tess_id = query.bind::<Text, _>("Tess")
    .get_result(&connection);
assert_eq!(Ok(2), tess_id);

Multiple Bind Params

#[cfg(not(feature="postgres"))]
let query = sql::<Text>("SELECT name FROM users WHERE id > ? AND name <> ?");
#[cfg(feature="postgres")]
let query = sql("SELECT name FROM users WHERE id > $1 AND name <> $2");
let query = query
    .bind::<Integer, _>(1)
    .bind::<Text, _>("Jim");
let expected = vec!["Tess".to_string()];
assert_eq!(Ok(expected), query.load(&connection));

Trait Implementations

impl<ST: Debug> Debug for SqlLiteral<ST>
[src]

Formats the value using the given formatter.

impl<ST: Clone> Clone for SqlLiteral<ST>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<ST> Expression for SqlLiteral<ST>
[src]

impl<ST, DB> QueryFragment<DB> for SqlLiteral<ST> where
    DB: Backend + HasSqlType<ST>, 
[src]

impl<ST> QueryId for SqlLiteral<ST>
[src]

impl<ST> Query for SqlLiteral<ST>
[src]

impl<QS, ST> SelectableExpression<QS> for SqlLiteral<ST>
[src]

impl<QS, ST> AppearsOnTable<QS> for SqlLiteral<ST>
[src]

impl<ST> NonAggregate for SqlLiteral<ST>
[src]