db_pool/async/backend/
trait.rs

1use std::fmt::Debug;
2
3use async_trait::async_trait;
4use uuid::Uuid;
5
6use super::error::Error;
7
8/// Backend trait
9#[async_trait]
10pub trait Backend: Sized + Send + Sync + 'static {
11    /// Connection pool type that implements [`Send`](https://doc.rust-lang.org/std/marker/trait.Send.html)
12    type Pool: Send;
13
14    /// Connection pool build error type that implements [`Debug`](https://doc.rust-lang.org/std/fmt/trait.Debug.html) and [`Send`](https://doc.rust-lang.org/std/marker/trait.Send.html)
15    type BuildError: Debug + Send;
16    /// Connection pool error type that implements [`Debug`](https://doc.rust-lang.org/std/fmt/trait.Debug.html) and [`Send`](https://doc.rust-lang.org/std/marker/trait.Send.html)
17    type PoolError: Debug + Send;
18    /// Connection error type that implements [`Debug`](https://doc.rust-lang.org/std/fmt/trait.Debug.html)
19    type ConnectionError: Debug;
20    /// Query error type that implements [`Debug`](https://doc.rust-lang.org/std/fmt/trait.Debug.html)
21    type QueryError: Debug;
22
23    /// Initializes the backend
24    async fn init(
25        &self,
26    ) -> Result<(), Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>>;
27    #[allow(clippy::complexity)]
28
29    /// Creates a database
30    async fn create(
31        &self,
32        db_id: Uuid,
33        restrict_privileges: bool,
34    ) -> Result<
35        Self::Pool,
36        Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>,
37    >;
38
39    /// Cleans a database
40    async fn clean(
41        &self,
42        db_id: Uuid,
43    ) -> Result<(), Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>>;
44
45    /// Drops a database
46    async fn drop(
47        &self,
48        db_id: Uuid,
49        is_restricted: bool,
50    ) -> Result<(), Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>>;
51}