StoragePort

Trait StoragePort 

Source
pub trait StoragePort: Send + Sync {
    // Required methods
    fn store<'life0, 'async_trait>(
        &'life0 self,
        record: StorageRecord,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn retrieve<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<StorageRecord>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list<'life0, 'life1, 'async_trait>(
        &'life0 self,
        pipeline_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<StorageRecord>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Port: persist and retrieve StorageRecords produced by pipelines.

§Example

use stygian_graph::ports::storage::{StoragePort, StorageRecord};
use serde_json::json;

async fn run<S: StoragePort>(storage: &S) {
    let r = StorageRecord::new("pipe-1", "fetch", json!({"url": "https://example.com"}));
    storage.store(r.clone()).await.unwrap();

    let fetched = storage.retrieve(&r.id).await.unwrap().unwrap();
    assert_eq!(fetched.id, r.id);
}

Required Methods§

Source

fn store<'life0, 'async_trait>( &'life0 self, record: StorageRecord, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Persist a record.

§Example
s.store(StorageRecord::new("p", "n", json!(null))).await.unwrap();
Source

fn retrieve<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<StorageRecord>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve a record by ID. Returns None if not found.

§Example
let maybe = s.retrieve("some-id").await.unwrap();
Source

fn list<'life0, 'life1, 'async_trait>( &'life0 self, pipeline_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<StorageRecord>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all records for a given pipeline_id.

§Example
let records = s.list("pipe-1").await.unwrap();
Source

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a record by ID. No-op if it does not exist.

§Example
s.delete("some-id").await.unwrap();

Implementors§