Struct diesel::query_builder::SqlQuery
source · pub struct SqlQuery<Inner = Empty> { /* private fields */ }
Expand description
The return value of sql_query
.
Unlike most queries in Diesel, SqlQuery
loads its data by column name,
rather than by index. This means that you cannot deserialize this query into
a tuple, and any structs used must implement QueryableByName
.
See sql_query
for examples.
Implementations§
source§impl<Inner> SqlQuery<Inner>
impl<Inner> SqlQuery<Inner>
sourcepub fn bind<ST, Value>(self, value: Value) -> UncheckedBind<Self, Value, ST>
pub fn bind<ST, Value>(self, value: Value) -> UncheckedBind<Self, Value, ST>
Bind a value for use with this SQL query. The given query should have placeholders that vary based on the database type, like SQLite Parameter syntax, PostgreSQL PREPARE syntax, or MySQL bind syntax.
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.
Example
let users = sql_query("SELECT * FROM users WHERE id > ? AND name <> ?")
.bind::<Integer, _>(1)
.bind::<Text, _>("Tess")
.get_results(connection);
let expected_users = vec![
User { id: 3, name: "Jim".into() },
];
assert_eq!(Ok(expected_users), users);
sourcepub fn into_boxed<'f, DB: Backend>(self) -> BoxedSqlQuery<'f, DB, Self>
pub fn into_boxed<'f, DB: Backend>(self) -> BoxedSqlQuery<'f, DB, Self>
Internally boxes future calls on bind
and sql
so that they don’t
change the type.
This allows doing things you otherwise couldn’t do, e.g. bind
ing in a
loop.
Trait Implementations§
source§impl<Inner> QueryId for SqlQuery<Inner>
impl<Inner> QueryId for SqlQuery<Inner>
source§const HAS_STATIC_QUERY_ID: bool = false
const HAS_STATIC_QUERY_ID: bool = false
Self
be uniquely identified by its type? Read moresource§impl<Inner, Conn> RunQueryDsl<Conn> for SqlQuery<Inner>
impl<Inner, Conn> RunQueryDsl<Conn> for SqlQuery<Inner>
source§fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>where
Self: LoadQuery<'query, Conn, U>,
fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>where
Self: LoadQuery<'query, Conn, U>,
source§fn load_iter<'conn, 'query: 'conn, U, B>(
self,
conn: &'conn mut Conn
) -> QueryResult<LoadIter<'conn, 'query, Self, Conn, U, B>>where
U: 'conn,
Self: LoadQuery<'query, Conn, U, B> + 'conn,
fn load_iter<'conn, 'query: 'conn, U, B>(
self,
conn: &'conn mut Conn
) -> QueryResult<LoadIter<'conn, 'query, Self, Conn, U, B>>where
U: 'conn,
Self: LoadQuery<'query, Conn, U, B> + 'conn,
source§fn get_result<'query, U>(self, conn: &mut Conn) -> QueryResult<U>where
Self: LoadQuery<'query, Conn, U>,
fn get_result<'query, U>(self, conn: &mut Conn) -> QueryResult<U>where
Self: LoadQuery<'query, Conn, U>,
source§fn get_results<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>where
Self: LoadQuery<'query, Conn, U>,
fn get_results<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>where
Self: LoadQuery<'query, Conn, U>,
Vec
with the affected rows. Read moreAuto Trait Implementations§
impl<Inner> RefUnwindSafe for SqlQuery<Inner>where
Inner: RefUnwindSafe,
impl<Inner> Send for SqlQuery<Inner>where
Inner: Send,
impl<Inner> Sync for SqlQuery<Inner>where
Inner: Sync,
impl<Inner> Unpin for SqlQuery<Inner>where
Inner: Unpin,
impl<Inner> UnwindSafe for SqlQuery<Inner>where
Inner: UnwindSafe,
Blanket Implementations§
source§impl<Conn, DB, T> ExecuteDsl<Conn, DB> for Twhere
Conn: Connection<Backend = DB>,
DB: Backend,
T: QueryFragment<DB, NotSpecialized> + QueryId,
impl<Conn, DB, T> ExecuteDsl<Conn, DB> for Twhere
Conn: Connection<Backend = DB>,
DB: Backend,
T: QueryFragment<DB, NotSpecialized> + QueryId,
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> AsExprOf<Self, T>where
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
fn into_sql<T>(self) -> AsExprOf<Self, T>where
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>where
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>where
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
&self
to an expression for Diesel’s query builder. Read more