Struct notedealer::database::Database
source · [−]Expand description
A database connection pool holder, with functions for inserting and getting ActivityPub objects to and from.
Fields
pool: Pool<Postgres>Implementations
sourceimpl Database
impl Database
sourcepub async fn new(url: &str) -> Result<Database>
pub async fn new(url: &str) -> Result<Database>
Creates a new connection pool and run migrations to bring the database up to speed.
sourcepub async fn insert(&self, obj: &Object<'_>) -> Result<()>
pub async fn insert(&self, obj: &Object<'_>) -> Result<()>
Inserts the object into the database, or do nothing if it has already been inserted.
sourcepub async fn insert_to_collection(
&self,
collection_id: &str,
item_id: &str
) -> Result<()>
pub async fn insert_to_collection(
&self,
collection_id: &str,
item_id: &str
) -> Result<()>
Inserts the item into the collection. Both ids must refer to objects that have been previously inserted with Database::insert.
sourcepub async fn get_object(
&self,
id: &str,
page: Option<u32>
) -> Result<Option<Object<'_>>>
pub async fn get_object(
&self,
id: &str,
page: Option<u32>
) -> Result<Option<Object<'_>>>
Returns the object with the id. If the object is an “OrderedCollection”,
page will be used to provide the specific “CollectionPage”, if
provided.
sourcepub async fn deliver(&self, inbox_url: &str, activity_id: &str) -> Result<()>
pub async fn deliver(&self, inbox_url: &str, activity_id: &str) -> Result<()>
Adds the activity with the given id to the delivery queue, to be delivered to the given inbox.
sourcepub async fn wait_for_inbox_delivery(&self) -> Result<()>
pub async fn wait_for_inbox_delivery(&self) -> Result<()>
Waits until the next time there’s deliveries to be delivered.
Implementation details
Returns either when the “activitypub_inbox_delivery” channel is notified (i.e. when a new delivery is added to the db), or when the earliest “next_delivery_time_utc” is reached, whichever is first.
sourcepub async fn get_deliveries(&self) -> Result<Vec<(String, Object<'_>)>>
pub async fn get_deliveries(&self) -> Result<Vec<(String, Object<'_>)>>
Returns a list of (inbox, activity to send to inbox) tuples that are
due to be sent now, and marks the rows as having attempted a delivery at
the time of calling this function.