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