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§

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

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.

Appends a piece of SQL code at the end.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The SQL type that this query represents. Read more
A type which uniquely represents Self in a SQL query. Read more
Can the SQL generated by Self be uniquely identified by its type? Read more
Returns the type id of Self::QueryId if Self::HAS_STATIC_QUERY_ID. Returns None otherwise. Read more
Executes the given query, returning a Vec with the returned rows. Read more
Executes the given query, returning an Iterator with the returned rows. Read more
Runs the command, and returns the affected row. Read more
Runs the command, returning an Vec with the affected rows. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
The SQL type of Self::Query
What kind of query does this type represent?
Converts a type which semantically represents a SQL query into the actual query being executed. See the trait level docs for more.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Execute this command

Returns the argument unchanged.

Calls U::from(self).

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

Convert self to an expression for Diesel’s query builder. Read more
Convert &self to an expression for Diesel’s query builder. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.