pub struct KeepsakeRepository<C = NoopRelationCache> { /* private fields */ }Expand description
SQLx-backed keepsake repository.
Implementations§
Source§impl<C> KeepsakeRepository<C>where
C: RelationCache,
impl<C> KeepsakeRepository<C>where
C: RelationCache,
Sourcepub const fn at(&self, at: DateTime<Utc>) -> TimedKeepsakeRepository<'_, C>
pub const fn at(&self, at: DateTime<Utc>) -> TimedKeepsakeRepository<'_, C>
Creates a timestamp-scoped repository view.
Use this at request or job boundaries to keep one explicit clock read while avoiding repeated timestamp plumbing through related repository calls.
Sourcepub fn with_relation_cache<Next>(self, cache: Next) -> KeepsakeRepository<Next>where
Next: RelationCache,
pub fn with_relation_cache<Next>(self, cache: Next) -> KeepsakeRepository<Next>where
Next: RelationCache,
Enables relation definition caching for read helper methods.
Sourcepub fn with_local_relation_cache(
self,
config: LocalRelationCacheConfig,
) -> KeepsakeRepository<LocalRelationCache>
pub fn with_local_relation_cache( self, config: LocalRelationCacheConfig, ) -> KeepsakeRepository<LocalRelationCache>
Enables local in-process relation definition caching for read helper methods.
Sourcepub async fn migrate(&self) -> RepositoryResult<()>
pub async fn migrate(&self) -> RepositoryResult<()>
Runs embedded migrations.
Sourcepub async fn upsert_relation(
&self,
relation: &RelationDefinition,
at: DateTime<Utc>,
) -> RepositoryResult<RelationDefinition>
pub async fn upsert_relation( &self, relation: &RelationDefinition, at: DateTime<Utc>, ) -> RepositoryResult<RelationDefinition>
Inserts or updates a relation definition by its natural relation key.
If a relation already exists for the same kind/name, its stable id is preserved and the returned definition contains the existing id.
Sourcepub async fn upsert_relation_spec<Spec>(
&self,
at: DateTime<Utc>,
) -> RepositoryResult<RelationDefinition>where
Spec: RelationSpec,
pub async fn upsert_relation_spec<Spec>(
&self,
at: DateTime<Utc>,
) -> RepositoryResult<RelationDefinition>where
Spec: RelationSpec,
Inserts or updates a typed relation spec by its natural relation key.
Sourcepub async fn relation_by_id(
&self,
relation_id: RelationId,
) -> RepositoryResult<Option<RelationDefinition>>
pub async fn relation_by_id( &self, relation_id: RelationId, ) -> RepositoryResult<Option<RelationDefinition>>
Looks up a relation definition by stable id.
Sourcepub async fn relation_by_key(
&self,
key: &RelationKey,
) -> RepositoryResult<Option<RelationDefinition>>
pub async fn relation_by_key( &self, key: &RelationKey, ) -> RepositoryResult<Option<RelationDefinition>>
Looks up a relation definition by its natural relation key.
Sourcepub async fn set_relation_enabled(
&self,
relation_id: RelationId,
enabled: bool,
at: DateTime<Utc>,
) -> RepositoryResult<bool>
pub async fn set_relation_enabled( &self, relation_id: RelationId, enabled: bool, at: DateTime<Utc>, ) -> RepositoryResult<bool>
Enables or disables a relation.
Sourcepub async fn apply(
&self,
subject: &SubjectRef,
relation_id: RelationId,
at: DateTime<Utc>,
metadata: &BTreeMap<String, String>,
) -> RepositoryResult<AppliedKeepsake>
pub async fn apply( &self, subject: &SubjectRef, relation_id: RelationId, at: DateTime<Utc>, metadata: &BTreeMap<String, String>, ) -> RepositoryResult<AppliedKeepsake>
Applies a keepsake relation idempotently.
If an active keepsake already exists for the subject and relation, the existing
row is returned with duplicate_prevented set to true, even if the relation
has since been disabled. Disabled relations reject new non-duplicate applies.
Sourcepub async fn apply_spec<Spec>(
&self,
subject: &SubjectRef,
at: DateTime<Utc>,
metadata: &BTreeMap<String, String>,
) -> RepositoryResult<AppliedKeepsake>where
Spec: RelationSpec,
pub async fn apply_spec<Spec>(
&self,
subject: &SubjectRef,
at: DateTime<Utc>,
metadata: &BTreeMap<String, String>,
) -> RepositoryResult<AppliedKeepsake>where
Spec: RelationSpec,
Applies a typed keepsake relation idempotently.
Sourcepub async fn apply_without_metadata(
&self,
subject: &SubjectRef,
relation_id: RelationId,
at: DateTime<Utc>,
) -> RepositoryResult<AppliedKeepsake>
pub async fn apply_without_metadata( &self, subject: &SubjectRef, relation_id: RelationId, at: DateTime<Utc>, ) -> RepositoryResult<AppliedKeepsake>
Applies a keepsake relation with empty metadata.
Sourcepub async fn apply_spec_without_metadata<Spec>(
&self,
subject: &SubjectRef,
at: DateTime<Utc>,
) -> RepositoryResult<AppliedKeepsake>where
Spec: RelationSpec,
pub async fn apply_spec_without_metadata<Spec>(
&self,
subject: &SubjectRef,
at: DateTime<Utc>,
) -> RepositoryResult<AppliedKeepsake>where
Spec: RelationSpec,
Applies a typed keepsake relation with empty metadata.
Sourcepub async fn revoke(
&self,
keepsake_id: Uuid,
at: DateTime<Utc>,
) -> RepositoryResult<bool>
pub async fn revoke( &self, keepsake_id: Uuid, at: DateTime<Utc>, ) -> RepositoryResult<bool>
Revokes an active keepsake.
Sourcepub async fn active_for_subject(
&self,
subject: &SubjectRef,
) -> RepositoryResult<Vec<Keepsake>>
pub async fn active_for_subject( &self, subject: &SubjectRef, ) -> RepositoryResult<Vec<Keepsake>>
Returns active keepsakes for a subject.
Sourcepub async fn active_relations_for_subject(
&self,
subject: &SubjectRef,
) -> RepositoryResult<Vec<ActiveRelation>>
pub async fn active_relations_for_subject( &self, subject: &SubjectRef, ) -> RepositoryResult<Vec<ActiveRelation>>
Returns active keepsakes for a subject with their relation definitions.
Sourcepub async fn active_relations_for_subject_by_keys(
&self,
subject: &SubjectRef,
keys: &[RelationKey],
) -> RepositoryResult<Vec<ActiveRelation>>
pub async fn active_relations_for_subject_by_keys( &self, subject: &SubjectRef, keys: &[RelationKey], ) -> RepositoryResult<Vec<ActiveRelation>>
Returns active keepsakes for a subject, filtered by relation keys.
This is the bounded variant of Self::active_relations_for_subject for
request paths that know the small set of relation keys they care about.
Missing keys are ignored, and disabled relation definitions are still
returned when their keepsake is active.
Sourcepub async fn active_membership_scan(
&self,
relation_id: RelationId,
limit: i64,
) -> RepositoryResult<Vec<Keepsake>>
pub async fn active_membership_scan( &self, relation_id: RelationId, limit: i64, ) -> RepositoryResult<Vec<Keepsake>>
Scans active memberships for a relation in stable order.
Sourcepub async fn active_membership_scan_after(
&self,
relation_id: RelationId,
after: Option<&MembershipCursor>,
limit: i64,
) -> RepositoryResult<Vec<Keepsake>>
pub async fn active_membership_scan_after( &self, relation_id: RelationId, after: Option<&MembershipCursor>, limit: i64, ) -> RepositoryResult<Vec<Keepsake>>
Scans active memberships after a keyset cursor in stable order.
Sourcepub async fn due_timed_expiry(
&self,
now: DateTime<Utc>,
limit: i64,
) -> RepositoryResult<Vec<TimedExpiryCandidate>>
pub async fn due_timed_expiry( &self, now: DateTime<Utc>, limit: i64, ) -> RepositoryResult<Vec<TimedExpiryCandidate>>
Lists due timed expiry candidates in stable batch order.
Sourcepub async fn expire_due_timed(
&self,
now: DateTime<Utc>,
limit: i64,
) -> RepositoryResult<u64>
pub async fn expire_due_timed( &self, now: DateTime<Utc>, limit: i64, ) -> RepositoryResult<u64>
Expires a stable batch of due timed keepsakes.
Sourcepub async fn upsert_counter_projection(
&self,
keepsake_id: Uuid,
key: &str,
value: i64,
observed_at: DateTime<Utc>,
) -> RepositoryResult<()>
pub async fn upsert_counter_projection( &self, keepsake_id: Uuid, key: &str, value: i64, observed_at: DateTime<Utc>, ) -> RepositoryResult<()>
Upserts a simple fulfillment counter projection.
Trait Implementations§
Source§impl<C: Clone> Clone for KeepsakeRepository<C>
impl<C: Clone> Clone for KeepsakeRepository<C>
Source§fn clone(&self) -> KeepsakeRepository<C>
fn clone(&self) -> KeepsakeRepository<C>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<C = NoopRelationCache> !RefUnwindSafe for KeepsakeRepository<C>
impl<C = NoopRelationCache> !UnwindSafe for KeepsakeRepository<C>
impl<C> Freeze for KeepsakeRepository<C>where
C: Freeze,
impl<C> Send for KeepsakeRepository<C>where
C: Send,
impl<C> Sync for KeepsakeRepository<C>where
C: Sync,
impl<C> Unpin for KeepsakeRepository<C>where
C: Unpin,
impl<C> UnsafeUnpin for KeepsakeRepository<C>where
C: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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