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
28    /// Creates a database
29    async fn create(
30        &self,
31        db_id: Uuid,
32        restrict_privileges: bool,
33    ) -> Result<
34        Self::Pool,
35        Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>,
36    >;
37
38    /// Cleans a database
39    async fn clean(
40        &self,
41        db_id: Uuid,
42    ) -> Result<(), Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>>;
43
44    /// Drops a database
45    async fn drop(
46        &self,
47        db_id: Uuid,
48        is_restricted: bool,
49    ) -> Result<(), Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>>;
50}