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>

source

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

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. binding in a loop.

source

pub fn sql<T: AsRef<str>>(self, sql: T) -> Self

Appends a piece of SQL code at the end.

Trait Implementations§

source§

impl<Inner: Clone> Clone for SqlQuery<Inner>

source§

fn clone(&self) -> SqlQuery<Inner>

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<Inner: Debug> Debug for SqlQuery<Inner>

source§

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

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

impl<Inner> Query for SqlQuery<Inner>

§

type SqlType = Untyped

The SQL type that this query represents. Read more
source§

impl<Inner> QueryId for SqlQuery<Inner>

§

type QueryId = ()

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

const HAS_STATIC_QUERY_ID: bool = false

Can the SQL generated by Self be uniquely identified by its type? 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<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>,

Executes the given query, returning a Vec with the returned rows. Read more
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,

Executes the given query, returning an Iterator with the returned rows. Read more
source§

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

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

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

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

Auto 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<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsQuery for Twhere T: Query,

§

type SqlType = <T as Query>::SqlType

The SQL type of Self::Query
§

type Query = T

What kind of query does this type represent?
source§

fn as_query(self) -> <T as AsQuery>::Query

Converts a type which semantically represents a SQL query into the actual query being executed. See the trait level docs for more.
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

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

source§

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

Execute this command
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, T: SqlType + TypedExpressionType,

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>, T: SqlType + TypedExpressionType,

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

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V