[][src]Trait diesel::query_builder::QueryId

pub trait QueryId {
    type QueryId: Any;

    const HAS_STATIC_QUERY_ID: bool;
    fn query_id() -> Option<TypeId> { ... }
}

Uniquely identifies queries by their type for the purpose of prepared statement caching.

All types which implement QueryFragment should also implement this trait (It is not an actual supertrait of QueryFragment for boxing purposes).

See the documentation of the QueryId type and HAS_STATIC_QUERY_ID for more details.

Deriving

This trait can be automatically derived by Diesel. For example, given this struct:

#[derive(QueryId)]
pub struct And<Left, Right> {
    left: Left,
    right: Right,
}

the following implementation will be generated

This example is not tested
impl<Left, Right> QueryId for And<Left, Right>
where
    Left: QueryId,
    Right: QueryId,
{
    type QueryId = And<Left::QueryId, Right::QueryId>;

    const HAS_STATIC_QUERY_ID: bool = Left::HAS_STATIC_QUERY_ID && Right::HAS_STATIC_QUERY_ID;
}

If the SQL generated by a struct is not uniquely identifiable by its type, meaning that HAS_STATIC_QUERY_ID should always be false, you should not derive this trait. In that case you should manually implement it instead.

Associated Types

type QueryId: Any

A type which uniquely represents Self in a SQL query.

Typically this will be a re-construction of Self using the QueryId type of each of your type parameters. For example, the type And<Left, Right> would have type QueryId = And<Left::QueryId, Right::QueryId>.

The exception to this is when one of your type parameters does not affect whether the same prepared statement can be used or not. For example, a bind parameter is represented as Bound<SqlType, RustType>. The actual Rust type we are serializing does not matter for the purposes of prepared statement reuse, but a query which has identical SQL but different types for its bind parameters requires a new prepared statement. For this reason, Bound would have type QueryId = Bound<SqlType::QueryId, ()>.

If HAS_STATIC_QUERY_ID is false, you can put any type here (typically ()).

Loading content...

Associated Constants

const HAS_STATIC_QUERY_ID: bool

Can the SQL generated by Self be uniquely identified by its type?

Typically this question can be answered by looking at whether unsafe_to_cache_prepared is called in your implementation of QueryFragment::walk_ast. In Diesel itself, the only type which has false here, but is potentially safe to store in the prepared statement cache is a boxed query.

Loading content...

Provided methods

fn query_id() -> Option<TypeId>

Returns the type id of Self::QueryId if Self::HAS_STATIC_QUERY_ID. Returns None otherwise.

You should never need to override this method.

Loading content...

Implementations on Foreign Types

impl QueryId for ()[src]

impl<T: QueryId + ?Sized> QueryId for Box<T>[src]

impl<'a, T: QueryId + ?Sized> QueryId for &'a T[src]

impl<A: QueryId> QueryId for (A,)[src]

impl<A: QueryId, B: QueryId> QueryId for (A, B)[src]

impl<A: QueryId, B: QueryId, C: QueryId> QueryId for (A, B, C)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId> QueryId for (A, B, C, D)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId> QueryId for (A, B, C, D, E)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId> QueryId for (A, B, C, D, E, F)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId> QueryId for (A, B, C, D, E, F, G)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId> QueryId for (A, B, C, D, E, F, G, H)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId, I: QueryId> QueryId for (A, B, C, D, E, F, G, H, I)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId, I: QueryId, J: QueryId> QueryId for (A, B, C, D, E, F, G, H, I, J)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId, I: QueryId, J: QueryId, K: QueryId> QueryId for (A, B, C, D, E, F, G, H, I, J, K)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId, I: QueryId, J: QueryId, K: QueryId, L: QueryId> QueryId for (A, B, C, D, E, F, G, H, I, J, K, L)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId, I: QueryId, J: QueryId, K: QueryId, L: QueryId, M: QueryId> QueryId for (A, B, C, D, E, F, G, H, I, J, K, L, M)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId, I: QueryId, J: QueryId, K: QueryId, L: QueryId, M: QueryId, N: QueryId> QueryId for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId, I: QueryId, J: QueryId, K: QueryId, L: QueryId, M: QueryId, N: QueryId, O: QueryId> QueryId for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)[src]

impl<A: QueryId, B: QueryId, C: QueryId, D: QueryId, E: QueryId, F: QueryId, G: QueryId, H: QueryId, I: QueryId, J: QueryId, K: QueryId, L: QueryId, M: QueryId, N: QueryId, O: QueryId, P: QueryId> QueryId for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)[src]

Loading content...

Implementors

impl QueryId for now[src]

impl QueryId for Datetime[src]

impl QueryId for Cidr[src]

impl QueryId for Inet[src]

impl QueryId for Json[src]

impl QueryId for Jsonb[src]

impl QueryId for MacAddr[src]

impl QueryId for Money[src]

impl QueryId for Oid[src]

impl QueryId for Timestamptz[src]

impl QueryId for Uuid[src]

impl QueryId for SqlQuery[src]

impl QueryId for BigInt[src]

impl QueryId for Binary[src]

impl QueryId for Bool[src]

impl QueryId for Date[src]

impl QueryId for Double[src]

impl QueryId for Float[src]

impl QueryId for Integer[src]

impl QueryId for Interval[src]

impl QueryId for Numeric[src]

impl QueryId for SmallInt[src]

impl QueryId for Text[src]

impl QueryId for Time[src]

impl QueryId for Timestamp[src]

impl QueryId for TinyInt[src]

impl<'a, QS, ST, DB> QueryId for dyn BoxableExpression<QS, DB, SqlType = ST> + 'a[src]

impl<DB> QueryId for dyn QueryFragment<DB>[src]

impl<Query: QueryId, Value: QueryId> QueryId for UncheckedBind<Query, Value>[src]

impl<ST, T> QueryId for SqlLiteral<ST, T>[src]

impl<ST: QueryId> QueryId for Unsigned<ST>[src]

impl<ST: QueryId> QueryId for Array<ST>[src]

impl<ST: QueryId> QueryId for Range<ST>[src]

impl<ST: QueryId> QueryId for Record<ST>[src]

impl<T> QueryId for Nullable<T> where
    T: QueryId + NotNull
[src]

impl<T, U, Op, Ret> QueryId for InsertStatement<T, U, Op, Ret>[src]

impl<T, U, V, Ret> QueryId for UpdateStatement<T, U, V, Ret>[src]

impl<T: QueryId> QueryId for DistinctOnClause<T>[src]

impl<T: QueryId, U: QueryId, Ret: QueryId> QueryId for DeleteStatement<T, U, Ret>[src]

Loading content...