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]
fn bind<BindST, T>(self, bind_value: T) -> UncheckedBind<Self, T, BindST>
[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]
impl<ST: Clone> Clone for SqlLiteral<ST>
[src]
fn clone(&self) -> SqlLiteral<ST>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<ST> Expression for SqlLiteral<ST>
[src]
type SqlType = ST
impl<ST, DB> QueryFragment<DB> for SqlLiteral<ST> where
DB: Backend + HasSqlType<ST>,
[src]
DB: Backend + HasSqlType<ST>,
fn walk_ast(&self, out: AstPass<DB>) -> QueryResult<()>
[src]
fn to_sql(&self, out: &mut DB::QueryBuilder) -> QueryResult<()>
[src]
fn collect_binds(
&self,
out: &mut DB::BindCollector,
metadata_lookup: &DB::MetadataLookup
) -> QueryResult<()>
[src]
&self,
out: &mut DB::BindCollector,
metadata_lookup: &DB::MetadataLookup
) -> QueryResult<()>