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 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 more