Skip to main content

NostrDatabase

Trait NostrDatabase 

Source
pub trait NostrDatabase:
    Any
    + Debug
    + Send
    + Sync {
    // Required methods
    fn backend(&self) -> &'static str;
    fn features(&self) -> Features;
    fn save_event<'a>(
        &'a self,
        event: &'a Event,
    ) -> Pin<Box<dyn Future<Output = Result<SaveEventStatus, Error>> + Send + 'a>>;
    fn check_id<'a>(
        &'a self,
        event_id: &'a EventId,
    ) -> Pin<Box<dyn Future<Output = Result<DatabaseEventStatus, Error>> + Send + 'a>>;
    fn event_by_id<'a>(
        &'a self,
        event_id: &'a EventId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Event>, Error>> + Send + 'a>>;
    fn count(
        &self,
        filter: Filter,
    ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + '_>>;
    fn query(
        &self,
        filter: Filter,
    ) -> Pin<Box<dyn Future<Output = Result<BTreeSet<Event>, Error>> + Send + '_>>;
    fn delete(
        &self,
        filter: Filter,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>;
    fn wipe(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>;

    // Provided method
    fn negentropy_items(
        &self,
        filter: Filter,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(EventId, Timestamp)>, Error>> + Send + '_>> { ... }
}
Expand description

Nostr (Events) Database

Required Methods§

Source

fn backend(&self) -> &'static str

Name of the backend database used

Source

fn features(&self) -> Features

Get backend features

Source

fn save_event<'a>( &'a self, event: &'a Event, ) -> Pin<Box<dyn Future<Output = Result<SaveEventStatus, Error>> + Send + 'a>>

Save Event into store

This method assumes that Event was already verified

Source

fn check_id<'a>( &'a self, event_id: &'a EventId, ) -> Pin<Box<dyn Future<Output = Result<DatabaseEventStatus, Error>> + Send + 'a>>

Check event status by ID

Check if the event is saved, deleted or not existent.

Source

fn event_by_id<'a>( &'a self, event_id: &'a EventId, ) -> Pin<Box<dyn Future<Output = Result<Option<Event>, Error>> + Send + 'a>>

Get Event by EventId

Source

fn count( &self, filter: Filter, ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + '_>>

Count the number of events found with Filter.

Use Filter::new() or Filter::default() to count all events.

Source

fn query( &self, filter: Filter, ) -> Pin<Box<dyn Future<Output = Result<BTreeSet<Event>, Error>> + Send + '_>>

Query stored events.

Source

fn delete( &self, filter: Filter, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Delete all events that match the Filter

Source

fn wipe(&self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Wipe all data

Provided Methods§

Source

fn negentropy_items( &self, filter: Filter, ) -> Pin<Box<dyn Future<Output = Result<Vec<(EventId, Timestamp)>, Error>> + Send + '_>>

Get unexpired negentropy items.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§