soph_database/support/
instance.rs

1use crate::{
2    async_trait,
3    error::Error,
4    traits::{ErrorTrait, InstanceTrait},
5    Database, Result,
6};
7use soph_core::{
8    error::ContainerError,
9    support::{app, Container},
10};
11
12#[async_trait]
13impl InstanceTrait for Database {
14    type Error = Error;
15
16    async fn register(_: &Container) -> Result<Self, ContainerError>
17    where
18        Self: Sized,
19    {
20        Ok(Self::new().await.map_err(Error::wrap)?)
21    }
22
23    async fn boot() -> Result<(), ContainerError>
24    where
25        Self: Sized,
26    {
27        let database = app().resolve::<Self>()?;
28
29        database.ping().await.map_err(Error::wrap)?;
30
31        Ok(())
32    }
33}