diesel::query_builder

Struct SqlQuery

Source
pub struct SqlQuery { /* 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 SqlQuery

Source

pub fn bind<ST, Value>(self, value: Value) -> UncheckedBind<Self, Value, ST>

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.

§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);

Trait Implementations§

Source§

impl Clone for SqlQuery

Source§

fn clone(&self) -> SqlQuery

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SqlQuery

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Conn, T> LoadQuery<Conn, T> for SqlQuery
where Conn: Connection, T: QueryableByName<Conn::Backend>,

Source§

fn internal_load(self, conn: &Conn) -> QueryResult<Vec<T>>

Load this query
Source§

impl<DB> QueryFragment<DB> for SqlQuery
where DB: Backend,

Source§

fn walk_ast(&self, out: AstPass<'_, DB>) -> QueryResult<()>

Walk over this QueryFragment for all passes. Read more
Source§

fn to_sql(&self, out: &mut DB::QueryBuilder) -> QueryResult<()>

Converts this QueryFragment to its SQL representation. Read more
Source§

fn collect_binds( &self, out: &mut DB::BindCollector, metadata_lookup: &DB::MetadataLookup, ) -> QueryResult<()>

Serializes all bind parameters in this query. Read more
Source§

fn is_safe_to_cache_prepared(&self) -> QueryResult<bool>

Is this query safe to store in the prepared statement cache? Read more
Source§

impl QueryId for SqlQuery

Source§

const HAS_STATIC_QUERY_ID: bool = false

Can the SQL generated by Self be uniquely identified by its type? Read more
Source§

type QueryId = ()

A type which uniquely represents Self in a SQL query. Read more
Source§

fn query_id() -> Option<TypeId>

Returns the type id of Self::QueryId if Self::HAS_STATIC_QUERY_ID. Returns None otherwise. Read more
Source§

impl<Conn> RunQueryDsl<Conn> for SqlQuery

Source§

fn execute(self, conn: &Conn) -> QueryResult<usize>
where Conn: Connection, Self: ExecuteDsl<Conn>,

Executes the given command, returning the number of rows affected. Read more
Source§

fn load<U>(self, conn: &Conn) -> QueryResult<Vec<U>>
where Self: LoadQuery<Conn, U>,

Executes the given query, returning a Vec with the returned rows. Read more
Source§

fn get_result<U>(self, conn: &Conn) -> QueryResult<U>
where Self: LoadQuery<Conn, U>,

Runs the command, and returns the affected row. Read more
Source§

fn get_results<U>(self, conn: &Conn) -> QueryResult<Vec<U>>
where Self: LoadQuery<Conn, U>,

Runs the command, returning an Vec with the affected rows. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Conn, DB, T> ExecuteDsl<Conn, DB> for T
where Conn: Connection<Backend = DB>, DB: Backend, T: QueryFragment<DB> + QueryId,

Source§

fn execute(query: T, conn: &Conn) -> Result<usize, Error>

Execute this command
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> AsExprOf<Self, T>
where Self: AsExpression<T> + Sized,

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>
where &'a Self: AsExpression<T>,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.