Skip to main content

DatabaseChannel

Struct DatabaseChannel 

Source
pub struct DatabaseChannel { /* private fields */ }
Expand description

Stores notifications in a table, for an in-app notification list.

Uses to_data, falling back to wrapping to_text — so a notification that only wrote a line still gets a row rather than being silently dropped.

Addresses the recipient by their id, not by a route: every notifiable has one, so this channel is never skipped for want of an address.

Implementations§

Source§

impl DatabaseChannel

Source

pub fn new(db: Database) -> Self

A channel writing to db.

Source

pub fn migrations() -> Migrator

The migration this channel needs.

Merge it into the application’s migrator:

ⓘ
Migrator::new()
    .create_table::<User>("0001_create_users")
    .merge(DatabaseChannel::migrations())
Source

pub async fn for_recipient( &self, notifiable_type: &str, notifiable_id: &str, limit: u64, ) -> Result<Vec<NotificationRow>>

Everything sent to a recipient, newest first.

Source

pub async fn unread( &self, notifiable_type: &str, notifiable_id: &str, limit: u64, ) -> Result<Vec<NotificationRow>>

The unread ones, newest first.

Source

pub async fn unread_count( &self, notifiable_type: &str, notifiable_id: &str, ) -> Result<u64>

How many are unread — what the badge on the bell shows.

Source

pub async fn find_for( &self, notifiable_type: &str, notifiable_id: &str, id: &str, ) -> Result<Option<NotificationRow>>

One notification, but only if it belongs to this recipient.

What an endpoint should look it up with. Reading the row and then comparing the owner in the handler is the same query with one more place to forget the comparison.

Source

pub async fn mark_read(&self, id: &str) -> Result<bool>

Mark one as read. true if it was there and unread.

Source

pub async fn mark_all_read( &self, notifiable_type: &str, notifiable_id: &str, ) -> Result<u64>

Mark everything for a recipient as read. Returns how many changed.

Source

pub async fn prune_read(&self, before: DateTime<Utc>) -> Result<u64>

Delete everything read before before. Returns how many.

A notifications table grows forever otherwise. Worth scheduling.

Trait Implementations§

Source§

impl Channel for DatabaseChannel

Source§

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

The channel’s name. Read more
Source§

fn send<'a>(&'a self, delivery: &'a Delivery) -> BoxFuture<'a, Result<()>>

Send it.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

fn event_name() -> &'static str
where Self: Sized,

A human-readable name, used by wildcard listeners and log output. Always the Rust type path; see the trait docs.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more