Struct TestDatabaseInstance

Source
pub struct TestDatabaseInstance<B>
where B: DatabaseBackend + 'static + Clone + Debug + Send + Sync,
{ pub backend: B, pub pool: B::Pool, pub db_name: DatabaseName, pub connection_pool: Option<Arc<Mutex<Vec<B::Connection>>>>, }
Expand description

A test database that handles setup, connections, and cleanup TODO: Create a TestManager that can handle connection pooling and cleanup

Fields§

§backend: B

The database backend

§pool: B::Pool

The connection pool

§db_name: DatabaseName

The database name

§connection_pool: Option<Arc<Mutex<Vec<B::Connection>>>>

The connection pool

Implementations§

Source§

impl<B> TestDatabaseInstance<B>
where B: DatabaseBackend + 'static + Clone + Debug + Send + Sync,

Source

pub async fn new(backend: B, config: DatabaseConfig) -> Result<Self, B::Error>

Create a new test database with the given backend

Source

pub async fn new_with_name( backend: B, config: DatabaseConfig, db_name: DatabaseName, ) -> Result<Self, B::Error>

Create a new test database with the given backend and specific name

Source

pub fn backend(&self) -> &B

Returns a reference to the backend

Source

pub fn name(&self) -> &DatabaseName

Returns a reference to the database name

Source

pub async fn connect(&self) -> Result<B::Connection, B::Error>

Create a single connection to the database without using the pool This is useful for cases where a single connection is needed for a specific operation

Source

pub async fn with_connection<F, R, E>( &self, operation: F, ) -> Result<R, B::Error>
where F: FnOnce(&B::Connection) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send>> + Send, E: Error + Send + Sync + 'static, B::Error: From<E>,

Execute a function with a one-off connection and automatically close it after use This is the most efficient way to perform a one-off database operation

Source

pub async fn acquire_connection( &self, ) -> Result<<B::Pool as DatabasePool>::Connection, B::Error>

Get a connection from the pool or acquire a new one

Source

pub async fn release_connection( &self, conn: <B::Pool as DatabasePool>::Connection, ) -> Result<(), B::Error>

Release a connection back to the pool

Source

pub async fn setup<F, Fut>(&self, setup_fn: F) -> Result<(), B::Error>
where F: FnOnce(&mut <B::Pool as DatabasePool>::Connection) -> Fut + Send, Fut: Future<Output = Result<(), B::Error>> + Send,

Setup the database with a function The connection handling approach needs to match the expected B::Connection type

Trait Implementations§

Source§

impl<B> Clone for TestDatabaseInstance<B>
where B: DatabaseBackend + 'static + Clone + Debug + Send + Sync + Clone, B::Pool: Clone, B::Connection: Clone,

Source§

fn clone(&self) -> TestDatabaseInstance<B>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B> Debug for TestDatabaseInstance<B>
where B: DatabaseBackend + 'static + Clone + Debug + Send + Sync,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B> Drop for TestDatabaseInstance<B>
where B: DatabaseBackend + Clone + Debug + Send + Sync + 'static,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more