Struct TestDatabaseInstance

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

Re-export the traits from testkit-core 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 as DatabaseBackend>::Pool

The connection pool

§db_name: DatabaseName

The database name

§connection_pool: Option<Arc<Mutex<RawMutex, Vec<<B as DatabaseBackend>::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<TestDatabaseInstance<B>, <B as DatabaseBackend>::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<TestDatabaseInstance<B>, <B as DatabaseBackend>::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 as DatabaseBackend>::Connection, <B as DatabaseBackend>::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 as DatabaseBackend>::Error>
where F: FnOnce(&<B as DatabaseBackend>::Connection) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send>> + Send, E: Error + Send + Sync + 'static, <B as DatabaseBackend>::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 as DatabaseBackend>::Pool as DatabasePool>::Connection, <B as DatabaseBackend>::Error>

Get a connection from the pool or acquire a new one

Source

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

Release a connection back to the pool

Source

pub async fn setup<F, Fut>( &self, setup_fn: F, ) -> Result<(), <B as DatabaseBackend>::Error>
where F: FnOnce(&mut <<B as DatabaseBackend>::Pool as DatabasePool>::Connection) -> Fut + Send, Fut: Future<Output = Result<(), <B as DatabaseBackend>::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: Clone + DatabaseBackend + 'static + Debug + Send + Sync, <B as DatabaseBackend>::Pool: Clone, <B as DatabaseBackend>::Connection: Clone,

Source§

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

Returns a copy 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<(), Error>

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
Source§

impl TransactionManager for TestDatabaseInstance<PostgresBackend>

Implementation of TransactionManager for PostgreSQL

Source§

type Error = PostgresError

Source§

type Tx = PostgresTransaction

Source§

type Connection = PostgresConnection

Source§

fn begin_transaction<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Self::Tx, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn commit_transaction<'life0, 'async_trait>( tx: &'life0 mut Self::Tx, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn rollback_transaction<'life0, 'async_trait>( tx: &'life0 mut Self::Tx, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T