pub enum StatementCacheKey<DB: Backend> {
Type(TypeId),
Sql {
sql: String,
bind_types: Vec<DB::TypeMetadata>,
},
}
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<T>(
source: &T,
bind_types: &[DB::TypeMetadata],
backend: &DB,
) -> QueryResult<Self>where
T: QueryFragment<DB> + QueryId,
pub fn for_source<T>(
source: &T,
bind_types: &[DB::TypeMetadata],
backend: &DB,
) -> QueryResult<Self>where
T: QueryFragment<DB> + QueryId,
Create a new statement cache key for the given query source
sourcepub fn sql<T: QueryFragment<DB>>(
&self,
source: &T,
backend: &DB,
) -> QueryResult<Cow<'_, str>>
pub fn sql<T: QueryFragment<DB>>( &self, source: &T, 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