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§
sourcetype QueryId: Any
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§
sourceconst HAS_STATIC_QUERY_ID: bool = true
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§
Object Safety§
Implementations on Foreign Types§
source§impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId> QueryId for (T0, T1, T2, T3, T4)
impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId> QueryId for (T0, T1, T2, T3, T4)
source§impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId> QueryId for (T0, T1, T2, T3, T4, T5)
impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId> QueryId for (T0, T1, T2, T3, T4, T5)
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)
impl<T0: QueryId, T1: QueryId, T2: QueryId, T3: QueryId, T4: QueryId, T5: QueryId, T6: QueryId> QueryId for (T0, T1, T2, T3, T4, T5, T6)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
const HAS_STATIC_QUERY_ID: bool = _
Implementors§
source§impl QueryId for diesel::sql_types::Timestamptz
Available on crate feature postgres_backend
only.
impl QueryId for diesel::sql_types::Timestamptz
postgres_backend
only.type QueryId = Timestamptz
const HAS_STATIC_QUERY_ID: bool = true
source§impl QueryId for diesel::sql_types::TimestamptzSqlite
Available on crate feature sqlite
only.
impl QueryId for diesel::sql_types::TimestamptzSqlite
sqlite
only.type QueryId = Timestamptz
const HAS_STATIC_QUERY_ID: bool = true
source§impl<'a, QS, ST, DB, GB, IsAggregate> QueryId for dyn BoxableExpression<QS, DB, GB, IsAggregate, SqlType = ST> + 'a
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>
impl<DB> QueryId for dyn QueryFragment<DB>
source§impl<DB: Backend, Query> QueryId for BoxedSqlQuery<'_, DB, Query>
impl<DB: Backend, Query> QueryId for BoxedSqlQuery<'_, DB, Query>
source§impl<S> QueryId for Only<S>where
Self: 'static,
S: QueryId,
Available on crate feature postgres_backend
only.
impl<S> QueryId for Only<S>where
Self: 'static,
S: QueryId,
postgres_backend
only.source§impl<S, C> QueryId for AliasedField<S, C>where
S: AliasSource + 'static,
S::Target: 'static,
C: Column<Table = S::Target> + 'static + QueryId,
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>
const HAS_STATIC_QUERY_ID: bool = <C as QueryId>::HAS_STATIC_QUERY_ID
source§impl<ST, T> QueryId for SqlLiteral<ST, T>
impl<ST, T> QueryId for SqlLiteral<ST, T>
source§impl<ST: 'static + QueryId> QueryId for Array<ST>
Available on crate feature postgres_backend
only.
impl<ST: 'static + QueryId> QueryId for Array<ST>
postgres_backend
only.source§impl<ST: 'static + QueryId> QueryId for Range<ST>
Available on crate feature postgres_backend
only.
impl<ST: 'static + QueryId> QueryId for Range<ST>
postgres_backend
only.source§impl<ST: 'static + QueryId> QueryId for Record<ST>
Available on crate feature postgres_backend
only.
impl<ST: 'static + QueryId> QueryId for Record<ST>
postgres_backend
only.source§impl<ST: 'static + QueryId> QueryId for Unsigned<ST>
Available on crate feature mysql_backend
only.
impl<ST: 'static + QueryId> QueryId for Unsigned<ST>
mysql_backend
only.source§impl<T, U, Op, Ret> QueryId for InsertStatement<T, U, Op, Ret>
impl<T, U, Op, Ret> QueryId for InsertStatement<T, U, Op, Ret>
source§impl<T, U, Ret> QueryId for DeleteStatement<T, U, Ret>
impl<T, U, Ret> QueryId for DeleteStatement<T, U, Ret>
source§impl<T, U, V, Ret> QueryId for UpdateStatement<T, U, V, Ret>where
T: QuerySource,
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.
impl<T: QueryId> QueryId for DistinctOnClause<T>
postgres_backend
only.