pub enum StatementCacheKey<DB: Backend> {
    Type(TypeId),
    Sql {
        sql: String,
        bind_types: Vec<DB::TypeMetadata>,
    },
}i-implement-a-third-party-backend-and-opt-into-breaking-changes only.Expand description
The lookup key used by StatementCache internally
This can contain either a at compile time known type id (representing a statically known query) or a at runtime calculated query string + parameter types (for queries that may change depending on their parameters)
Variants§
Type(TypeId)
Represents a at compile time known query
Calculated via QueryId::QueryId
Sql
Represents a dynamically constructed query
This variant is used if QueryId::HAS_STATIC_QUERY_ID
is false and AstPass::unsafe_to_cache_prepared is not
called for a given query.
Fields
bind_types: Vec<DB::TypeMetadata>contains the types of any bind parameter passed to the query
Implementations§
Source§impl<DB> StatementCacheKey<DB>
 
impl<DB> StatementCacheKey<DB>
Sourcepub fn for_source(
    maybe_type_id: Option<TypeId>,
    source: &dyn QueryFragmentForCachedStatement<DB>,
    bind_types: &[DB::TypeMetadata],
    backend: &DB,
) -> QueryResult<Self>
 
pub fn for_source( maybe_type_id: Option<TypeId>, source: &dyn QueryFragmentForCachedStatement<DB>, bind_types: &[DB::TypeMetadata], backend: &DB, ) -> QueryResult<Self>
Create a new statement cache key for the given query source
Sourcepub fn sql(
    &self,
    source: &dyn QueryFragmentForCachedStatement<DB>,
    backend: &DB,
) -> QueryResult<Cow<'_, str>>
 
pub fn sql( &self, source: &dyn QueryFragmentForCachedStatement<DB>, backend: &DB, ) -> QueryResult<Cow<'_, str>>
Get the sql for a given query source based
This is an optimization that may skip constructing the query string twice if it’s already part of the current cache key