Skip to main content

EntityStore

Trait EntityStore 

Source
pub trait EntityStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn upsert_entity<'life0, 'async_trait>(
        &'life0 self,
        entity: Entity,
    ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn upsert_entities<'life0, 'async_trait>(
        &'life0 self,
        entities: Vec<Entity>,
    ) -> Pin<Box<dyn Future<Output = StorageResult<BatchWriteSummary>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_entity<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Option<Entity>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete_entity<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
        mode: DeleteMode,
    ) -> Pin<Box<dyn Future<Output = StorageResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn query_entities<'life0, 'life1, 'async_trait>(
        &'life0 self,
        namespace: &'life1 str,
        filter: EntityFilter,
        page: PageRequest,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Page<Entity>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn count_entities<'life0, 'life1, 'async_trait>(
        &'life0 self,
        namespace: &'life1 str,
        filter: EntityFilter,
    ) -> Pin<Box<dyn Future<Output = StorageResult<u64>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_entity_including_deleted<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Option<Entity>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn insert_entity_if_absent<'life0, 'async_trait>(
        &'life0 self,
        _entity: Entity,
    ) -> Pin<Box<dyn Future<Output = StorageResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn upsert_entity_with_attachments<'life0, 'async_trait>(
        &'life0 self,
        _entity: Entity,
        _attachments: Vec<Attachment>,
    ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn replace_entity_if_unchanged<'life0, 'async_trait>(
        &'life0 self,
        _entity: Entity,
        _expected_updated_at: i64,
        _expected_deleted_at: Option<i64>,
    ) -> Pin<Box<dyn Future<Output = StorageResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn entity_sequence<'life0, 'async_trait>(
        &'life0 self,
        _id: Uuid,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Option<i64>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn query_entities_after<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _namespace: &'life1 str,
        _filter: EntityFilter,
        _after: Option<SeekCursor>,
        _limit: u32,
    ) -> Pin<Box<dyn Future<Output = StorageResult<SeekPage<Entity>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Entity CRUD operations over the entities substrate table.

Required Methods§

Source

fn upsert_entity<'life0, 'async_trait>( &'life0 self, entity: Entity, ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Insert at version one or update the current row and advance its version once. Incoming version values do not override the stored counter. Raw SQL replacement of an existing entity is forbidden: use a conflict UPDATE or the typed store.

Source

fn upsert_entities<'life0, 'async_trait>( &'life0 self, entities: Vec<Entity>, ) -> Pin<Box<dyn Future<Output = StorageResult<BatchWriteSummary>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Insert or update a batch of entities.

Source

fn get_entity<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = StorageResult<Option<Entity>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch an entity by UUID, returning None if absent.

Source

fn delete_entity<'life0, 'async_trait>( &'life0 self, id: Uuid, mode: DeleteMode, ) -> Pin<Box<dyn Future<Output = StorageResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete an entity by UUID using the specified delete mode.

Source

fn query_entities<'life0, 'life1, 'async_trait>( &'life0 self, namespace: &'life1 str, filter: EntityFilter, page: PageRequest, ) -> Pin<Box<dyn Future<Output = StorageResult<Page<Entity>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Query entities by namespace with filter and pagination.

Source

fn count_entities<'life0, 'life1, 'async_trait>( &'life0 self, namespace: &'life1 str, filter: EntityFilter, ) -> Pin<Box<dyn Future<Output = StorageResult<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Count entities in a namespace matching the given filter.

Source

fn get_entity_including_deleted<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = StorageResult<Option<Entity>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch an entity by UUID regardless of soft-deletion state.

Returns the entity row even when deleted_at is set. Callers use this to distinguish “soft-deleted” from “never existed”.

Provided Methods§

Source

fn insert_entity_if_absent<'life0, 'async_trait>( &'life0 self, _entity: Entity, ) -> Pin<Box<dyn Future<Output = StorageResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Insert an entity only when no row with its id or another conflicting key exists. Returns true when this call inserted the row and false when an existing row won the race. The existing row is never updated.

The default returns Unsupported rather than falling back to EntityStore::upsert_entity, because an upsert would overwrite the winning row and violate this method’s conditional-insert contract.

Source

fn upsert_entity_with_attachments<'life0, 'async_trait>( &'life0 self, _entity: Entity, _attachments: Vec<Attachment>, ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Atomically insert/update an entity and all supplied attachment roles.

Source

fn replace_entity_if_unchanged<'life0, 'async_trait>( &'life0 self, _entity: Entity, _expected_updated_at: i64, _expected_deleted_at: Option<i64>, ) -> Pin<Box<dyn Future<Output = StorageResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Replace an entity only when the persisted row still matches the caller’s read snapshot.

entity.version is the persisted revision read with the snapshot; a successful replacement increments the stored version once. expected_updated_at is an additional snapshot timestamp guard and expected_deleted_at closes the soft-delete race. The replacement entity’s updated_at must be strictly greater than that persisted revision. Returns false when the row disappeared, changed, or was supplied a non-advancing replacement revision. This is the full-entity compare-and-swap seam used when a caller derives coupled fields from that snapshot before persistence — mirrors crate::NoteStore::replace_note_if_unchanged. The default returns Unsupported rather than falling back to an unguarded upsert and reintroducing the stale-snapshot race.

Source

fn entity_sequence<'life0, 'async_trait>( &'life0 self, _id: Uuid, ) -> Pin<Box<dyn Future<Output = StorageResult<Option<i64>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Resolve an entity id to its immutable insertion sequence.

Source

fn query_entities_after<'life0, 'life1, 'async_trait>( &'life0 self, _namespace: &'life1 str, _filter: EntityFilter, _after: Option<SeekCursor>, _limit: u32, ) -> Pin<Box<dyn Future<Output = StorageResult<SeekPage<Entity>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Query an immutable insertion-sequence keyset page.

Backends that do not implement seek pagination may retain the default unsupported result; callers must not silently fall back to offset paging because that would weaken the no-gap/no-duplicate contract.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§