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<DB, Inner> QueryFragment<DB> for SqlQuery<Inner>where
DB: Backend + DieselReserveSpecialization,
Inner: QueryFragment<DB>,
impl<DB, Inner> QueryFragment<DB> for SqlQuery<Inner>where
DB: Backend + DieselReserveSpecialization,
Inner: QueryFragment<DB>,
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<Self::RowIter<'conn>>where
U: 'conn,
Self: LoadQuery<'query, Conn, U, B> + 'conn,
fn load_iter<'conn, 'query: 'conn, U, B>(
self,
conn: &'conn mut Conn,
) -> QueryResult<Self::RowIter<'conn>>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> Freeze for SqlQuery<Inner>where
Inner: Freeze,
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<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)