Trait nostr_database::NostrDatabase

source ·
pub trait NostrDatabase:
    Debug
    + Send
    + Sync {
    // Required methods
    fn backend(&self) -> Backend;
    fn save_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event: &'life1 Event,
    ) -> Pin<Box<dyn Future<Output = Result<bool, DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn check_id<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event_id: &'life1 EventId,
    ) -> Pin<Box<dyn Future<Output = Result<DatabaseEventStatus, DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn has_coordinate_been_deleted<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        coordinate: &'life1 Coordinate,
        timestamp: &'life2 Timestamp,
    ) -> Pin<Box<dyn Future<Output = Result<bool, DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn event_id_seen<'life0, 'async_trait>(
        &'life0 self,
        event_id: EventId,
        relay_url: Url,
    ) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn event_seen_on_relays<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event_id: &'life1 EventId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<HashSet<Url>>, DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn event_by_id<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event_id: &'life1 EventId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Event>, DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn count<'life0, 'async_trait>(
        &'life0 self,
        filters: Vec<Filter>,
    ) -> Pin<Box<dyn Future<Output = Result<usize, DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn query<'life0, 'async_trait>(
        &'life0 self,
        filters: Vec<Filter>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Event>, DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'async_trait>(
        &'life0 self,
        filter: Filter,
    ) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn wipe<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

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

Nostr Database

Required Methods§

source

fn backend(&self) -> Backend

Name of the backend database used (ex. rocksdb, lmdb, sqlite, indexeddb, …)

source

fn save_event<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 Event, ) -> Pin<Box<dyn Future<Output = Result<bool, DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Save Event into store

Return true if event was successfully saved into database.

This method assume that Event was already verified

source

fn check_id<'life0, 'life1, 'async_trait>( &'life0 self, event_id: &'life1 EventId, ) -> Pin<Box<dyn Future<Output = Result<DatabaseEventStatus, DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check event status by ID

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

source

fn has_coordinate_been_deleted<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, coordinate: &'life1 Coordinate, timestamp: &'life2 Timestamp, ) -> Pin<Box<dyn Future<Output = Result<bool, DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Check if Coordinate has been deleted before a certain Timestamp

source

fn event_id_seen<'life0, 'async_trait>( &'life0 self, event_id: EventId, relay_url: Url, ) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Set EventId as seen by relay

Useful for NIP65 (aka gossip)

source

fn event_seen_on_relays<'life0, 'life1, 'async_trait>( &'life0 self, event_id: &'life1 EventId, ) -> Pin<Box<dyn Future<Output = Result<Option<HashSet<Url>>, DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get list of relays that have seen the EventId

source

fn event_by_id<'life0, 'life1, 'async_trait>( &'life0 self, event_id: &'life1 EventId, ) -> Pin<Box<dyn Future<Output = Result<Option<Event>, DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get Event by EventId

source

fn count<'life0, 'async_trait>( &'life0 self, filters: Vec<Filter>, ) -> Pin<Box<dyn Future<Output = Result<usize, DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count number of Event found by filters

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

source

fn query<'life0, 'async_trait>( &'life0 self, filters: Vec<Filter>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Event>, DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Query store with filters

source

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

Delete all events that match the Filter

source

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

Wipe all data

Provided Methods§

source

fn negentropy_items<'life0, 'async_trait>( &'life0 self, filter: Filter, ) -> Pin<Box<dyn Future<Output = Result<Vec<(EventId, Timestamp)>, DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get negentropy items

Implementors§