db_pool/sync/backend/
trait.rs

1use std::fmt::Debug;
2
3use r2d2::{ManageConnection, Pool};
4use uuid::Uuid;
5
6use super::error::Error;
7
8/// Backend trait
9pub trait Backend: Sized + Send + Sync + 'static {
10    /// Type that implements the [`r2d2::ManageConnection`](https://docs.rs/r2d2/0.8.10/r2d2/trait.ManageConnection.html) trait
11    type ConnectionManager: ManageConnection;
12    /// Connection error type that implements [`Debug`](https://doc.rust-lang.org/std/fmt/trait.Debug.html)
13    type ConnectionError: Debug;
14    /// Query error type that implements [`Debug`](https://doc.rust-lang.org/std/fmt/trait.Debug.html)
15    type QueryError: Debug;
16
17    /// Initializes the backend
18    fn init(&self) -> Result<(), Error<Self::ConnectionError, Self::QueryError>>;
19
20    /// Creates a database
21    #[allow(clippy::complexity)]
22    fn create(
23        &self,
24        db_id: Uuid,
25        restrict_privileges: bool,
26    ) -> Result<Pool<Self::ConnectionManager>, Error<Self::ConnectionError, Self::QueryError>>;
27
28    /// Cleans a database
29    fn clean(&self, db_id: Uuid) -> Result<(), Error<Self::ConnectionError, Self::QueryError>>;
30
31    /// Drops a database
32    fn drop(
33        &self,
34        db_id: Uuid,
35        is_restricted: bool,
36    ) -> Result<(), Error<Self::ConnectionError, Self::QueryError>>;
37}