Skip to main content

PreparedDbQuery

Struct PreparedDbQuery 

Source
pub struct PreparedDbQuery<T, C = PostcardCodec>
where C: CacheCodec,
{ /* private fields */ }
Expand description

A prepared database query descriptor.

PreparedDbQuery keeps adapter state and stable query-cache metadata close together. It can cheaply create ordinary DbQuery values for each call, or execute loaders directly through load_id/fetch_with_id.

Implementations§

Source§

impl<T, C> PreparedDbQuery<T, C>
where C: CacheCodec,

Source

pub fn namespace(&self) -> &str

Return the namespace used for physical cache keys.

Source

pub fn cache(&self) -> &HydraCache<C>

Return the underlying local cache.

Source

pub fn prepared_policy(&self) -> &PreparedQueryPolicy

Return the prepared policy backing this descriptor.

Source

pub fn name(&self) -> Option<&str>

Return the optional diagnostic operation name.

Source

pub fn requires_id(&self) -> bool

Return whether this descriptor needs an id binding before execution.

Source

pub fn static_key_value(&self) -> Option<&str>

Return the static logical key, if this descriptor has one.

Source

pub fn entity_key_prefix(&self) -> Option<&str>

Return the precomputed entity key prefix, if this is an entity policy.

Source

pub fn tags_value(&self) -> &[String]

Return the precomputed tags.

Source

pub fn ttl_value(&self) -> Option<Duration>

Return the configured per-entry TTL.

Source

pub fn refresh_policy_value(&self) -> Option<RefreshOptions>

Return the configured refresh/stale policy.

Source

pub fn refresh_policy(self, refresh: RefreshOptions) -> PreparedDbQuery<T, C>

Replace refresh/stale behavior for this prepared descriptor.

Source

pub fn to_query(&self) -> DbQuery<T, C>

Create a runtime query from a static prepared policy.

Entity-id policies should usually use PreparedDbQuery::for_id so the dynamic id becomes part of the key and entity invalidation tag.

Source

pub fn for_id(&self, id: impl ToString) -> DbQuery<T, C>

Bind an id and create a runtime query.

Source

pub async fn load<E, F, Fut>(&self, loader: F) -> Result<T, DbCacheError>
where T: Serialize + DeserializeOwned + Send + 'static, E: Error + Send + Sync + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static,

Fetch a cached value from a static prepared policy or run the loader.

Source

pub async fn load_id<E, F, Fut>( &self, id: impl ToString, loader: F, ) -> Result<T, DbCacheError>
where T: Serialize + DeserializeOwned + Send + 'static, E: Error + Send + Sync + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static,

Bind an id, fetch a cached value, or run the loader.

Source

pub async fn fetch_value_with<U, E, F, Fut>( &self, loader: F, ) -> Result<U, DbCacheError>
where U: Serialize + DeserializeOwned + Send + 'static, E: Error + Send + Sync + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<U, E>> + Send + 'static,

Fetch a static prepared value with an output type chosen by an adapter.

Source

pub async fn fetch_value_with_id<U, E, F, Fut>( &self, id: impl ToString, loader: F, ) -> Result<U, DbCacheError>
where U: Serialize + DeserializeOwned + Send + 'static, E: Error + Send + Sync + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<U, E>> + Send + 'static,

Bind an id and fetch a value with an output type chosen by an adapter.

Trait Implementations§

Source§

impl<T, C> Clone for PreparedDbQuery<T, C>
where C: CacheCodec,

Source§

fn clone(&self) -> PreparedDbQuery<T, C>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, C> Debug for PreparedDbQuery<T, C>
where C: CacheCodec,

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, C = PostcardCodec> !RefUnwindSafe for PreparedDbQuery<T, C>

§

impl<T, C = PostcardCodec> !UnwindSafe for PreparedDbQuery<T, C>

§

impl<T, C> Freeze for PreparedDbQuery<T, C>

§

impl<T, C> Send for PreparedDbQuery<T, C>

§

impl<T, C> Sync for PreparedDbQuery<T, C>

§

impl<T, C> Unpin for PreparedDbQuery<T, C>

§

impl<T, C> UnsafeUnpin for PreparedDbQuery<T, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more