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>
impl<DB, Inner> QueryFragment<DB> for SqlQuery<Inner>
Source§fn walk_ast<'b>(&'b self, out: AstPass<'_, 'b, DB>) -> QueryResult<()>
fn walk_ast<'b>(&'b self, out: AstPass<'_, 'b, DB>) -> QueryResult<()>
QueryFragment
for all passes. Read moreSource§fn to_sql(&self, out: &mut DB::QueryBuilder, backend: &DB) -> QueryResult<()>
fn to_sql(&self, out: &mut DB::QueryBuilder, backend: &DB) -> QueryResult<()>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.QueryFragment
to its SQL representation. Read moreSource§fn collect_binds<'b>(
&'b self,
out: &mut DB::BindCollector<'b>,
metadata_lookup: &mut DB::MetadataLookup,
backend: &'b DB,
) -> QueryResult<()>
fn collect_binds<'b>( &'b self, out: &mut DB::BindCollector<'b>, metadata_lookup: &mut DB::MetadataLookup, backend: &'b DB, ) -> QueryResult<()>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.Source§fn is_safe_to_cache_prepared(&self, backend: &DB) -> QueryResult<bool>
fn is_safe_to_cache_prepared(&self, backend: &DB) -> QueryResult<bool>
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.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 execute(self, conn: &mut Conn) -> QueryResult<usize>where
Conn: Connection,
Self: ExecuteDsl<Conn>,
fn execute(self, conn: &mut Conn) -> QueryResult<usize>where
Conn: Connection,
Self: ExecuteDsl<Conn>,
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§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.