Trait diesel::query_builder::QueryId

source ·
pub trait QueryId {
    type QueryId: Any;

    const HAS_STATIC_QUERY_ID: bool = true;

    // Provided method
    fn query_id() -> Option<TypeId> { ... }
}
Expand description

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:

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.

Required Associated Types§

source

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 ()).

Provided Associated Constants§

source

const HAS_STATIC_QUERY_ID: bool = true

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.

Provided Methods§

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl QueryId for ()

source§

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

§

type QueryId = <T as QueryId>::QueryId

source§

const HAS_STATIC_QUERY_ID: bool = T::HAS_STATIC_QUERY_ID

source§

impl<T0: QueryId> QueryId for (T0,)

source§

impl<T0: QueryId, T1: QueryId> QueryId for (T0, T1)

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId> QueryId for (T0, T1, T2)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId> QueryId for (T0, T1, T2, T3)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId> QueryId for (T0, T1, T2, T3, T4)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId> QueryId for (T0, T1, T2, T3, T4, T5)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId, T8: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId, <T8 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId, T8: QueryId, T9: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId, <T8 as QueryId>::QueryId, <T9 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId, T8: QueryId, T9: QueryId, T10: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId, <T8 as QueryId>::QueryId, <T9 as QueryId>::QueryId, <T10 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId, T8: QueryId, T9: QueryId, T10: QueryId, T11: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId, <T8 as QueryId>::QueryId, <T9 as QueryId>::QueryId, <T10 as QueryId>::QueryId, <T11 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId, T8: QueryId, T9: QueryId, T10: QueryId, T11: QueryId, T12: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId, <T8 as QueryId>::QueryId, <T9 as QueryId>::QueryId, <T10 as QueryId>::QueryId, <T11 as QueryId>::QueryId, <T12 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId, T8: QueryId, T9: QueryId, T10: QueryId, T11: QueryId, T12: QueryId, T13: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId, <T8 as QueryId>::QueryId, <T9 as QueryId>::QueryId, <T10 as QueryId>::QueryId, <T11 as QueryId>::QueryId, <T12 as QueryId>::QueryId, <T13 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId, T8: QueryId, T9: QueryId, T10: QueryId, T11: QueryId, T12: QueryId, T13: QueryId, T14: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId, <T8 as QueryId>::QueryId, <T9 as QueryId>::QueryId, <T10 as QueryId>::QueryId, <T11 as QueryId>::QueryId, <T12 as QueryId>::QueryId, <T13 as QueryId>::QueryId, <T14 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId, T7: QueryId, T8: QueryId, T9: QueryId, T10: QueryId, T11: QueryId, T12: QueryId, T13: QueryId, T14: QueryId, T15: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)

§

type QueryId = (<T0 as QueryId>::QueryId, <T1 as QueryId>::QueryId, <T2 as QueryId>::QueryId, <T3 as QueryId>::QueryId, <T4 as QueryId>::QueryId, <T5 as QueryId>::QueryId, <T6 as QueryId>::QueryId, <T7 as QueryId>::QueryId, <T8 as QueryId>::QueryId, <T9 as QueryId>::QueryId, <T10 as QueryId>::QueryId, <T11 as QueryId>::QueryId, <T12 as QueryId>::QueryId, <T13 as QueryId>::QueryId, <T14 as QueryId>::QueryId, <T15 as QueryId>::QueryId)

source§

const HAS_STATIC_QUERY_ID: bool = _

source§

impl<T: QueryId + ?Sized> QueryId for Box<T>

§

type QueryId = <T as QueryId>::QueryId

source§

const HAS_STATIC_QUERY_ID: bool = T::HAS_STATIC_QUERY_ID

Implementors§

source§

impl QueryId for now

source§

impl QueryId for today

source§

impl QueryId for BigInt

source§

impl QueryId for Binary

source§

impl QueryId for Bool

source§

impl QueryId for CChar

Available on crate feature postgres_backend only.
source§

impl QueryId for Cidr

Available on crate feature postgres_backend only.
source§

impl QueryId for Date

source§

impl QueryId for Datetime

Available on crate feature mysql_backend only.
source§

impl QueryId for Double

source§

impl QueryId for Float

source§

impl QueryId for Inet

Available on crate feature postgres_backend only.
source§

impl QueryId for Integer

source§

impl QueryId for Interval

source§

impl QueryId for Json

source§

impl QueryId for Jsonb

Available on crate feature postgres_backend only.
source§

impl QueryId for MacAddr

Available on crate feature postgres_backend only.
source§

impl QueryId for Money

Available on crate feature postgres_backend only.
source§

impl QueryId for Numeric

source§

impl QueryId for Oid

Available on crate feature postgres_backend only.
source§

impl QueryId for SmallInt

source§

impl QueryId for Text

source§

impl QueryId for Time

source§

impl QueryId for Timestamp

source§

impl QueryId for diesel::sql_types::Timestamptz

Available on crate feature postgres_backend only.
source§

impl QueryId for diesel::sql_types::TimestamptzSqlite

Available on crate feature sqlite only.
source§

impl QueryId for TinyInt

source§

impl QueryId for Uuid

Available on crate feature postgres_backend only.
source§

impl<'a, QS, ST, DB, GB, IsAggregate> QueryId for dyn BoxableExpression<QS, DB, GB, IsAggregate, SqlType = ST> + 'a

source§

impl<DB> QueryId for dyn QueryFragment<DB>

source§

impl<DB: Backend, Query> QueryId for BoxedSqlQuery<'_, DB, Query>

source§

impl<Inner> QueryId for SqlQuery<Inner>

source§

impl<Query: QueryId, Value: QueryId> QueryId for UncheckedBind<Query, Value>

source§

impl<S> QueryId for Alias<S>
where Self: 'static, S: AliasSource, S::Target: QueryId,

§

type QueryId = Alias<S>

source§

const HAS_STATIC_QUERY_ID: bool = <S::Target as QueryId>::HAS_STATIC_QUERY_ID

source§

impl<S> QueryId for Only<S>
where Self: 'static, S: QueryId,

Available on crate feature postgres_backend only.
§

type QueryId = Only<S>

source§

const HAS_STATIC_QUERY_ID: bool = <S as QueryId>::HAS_STATIC_QUERY_ID

source§

impl<S, C> QueryId for AliasedField<S, C>
where S: AliasSource + 'static, S::Target: 'static, C: Column<Table = S::Target> + 'static + QueryId,

§

type QueryId = AliasedField<S, C>

source§

const HAS_STATIC_QUERY_ID: bool = <C as QueryId>::HAS_STATIC_QUERY_ID

source§

impl<ST, T> QueryId for SqlLiteral<ST, T>

source§

impl<ST: 'static + QueryId> QueryId for Array<ST>

Available on crate feature postgres_backend only.
source§

impl<ST: 'static + QueryId> QueryId for Range<ST>

Available on crate feature postgres_backend only.
source§

impl<ST: 'static + QueryId> QueryId for Record<ST>

Available on crate feature postgres_backend only.
source§

impl<ST: 'static + QueryId> QueryId for Unsigned<ST>

Available on crate feature mysql_backend only.
source§

impl<T> QueryId for Nullable<T>
where T: QueryId + SqlType<IsNull = NotNull>,

§

type QueryId = <T as QueryId>::QueryId

source§

const HAS_STATIC_QUERY_ID: bool = T::HAS_STATIC_QUERY_ID

source§

impl<T, U, Op, Ret> QueryId for InsertStatement<T, U, Op, Ret>
where T: QuerySource + QueryId + 'static, U: QueryId, Op: QueryId, Ret: QueryId,

source§

impl<T, U, Ret> QueryId for DeleteStatement<T, U, Ret>
where T: QuerySource + QueryId + 'static, U: QueryId, Ret: QueryId,

source§

impl<T, U, V, Ret> QueryId for UpdateStatement<T, U, V, Ret>
where T: QuerySource,

source§

impl<T: QueryId> QueryId for DistinctOnClause<T>

Available on crate feature postgres_backend only.