pub struct TestDatabase { /* private fields */ }
Expand description
Test database manager that handles automatic setup and cleanup
Implementations§
Source§impl TestDatabase
impl TestDatabase
Sourcepub async fn new() -> TestResult<Self>
pub async fn new() -> TestResult<Self>
Create a new test database connection
This will automatically configure a test database connection using environment variables or sensible defaults
Sourcepub async fn with_transaction() -> TestResult<Self>
pub async fn with_transaction() -> TestResult<Self>
Create a new test database with an isolated transaction
This is the recommended approach for test isolation
Sourcepub async fn execute(&self, sql: &str) -> TestResult<()>
pub async fn execute(&self, sql: &str) -> TestResult<()>
Execute a raw SQL query (for test setup)
Sourcepub async fn fetch_one(&self, sql: &str) -> TestResult<PgRow>
pub async fn fetch_one(&self, sql: &str) -> TestResult<PgRow>
Execute a query and return the first row
Sourcepub async fn fetch_all(&self, sql: &str) -> TestResult<Vec<PgRow>>
pub async fn fetch_all(&self, sql: &str) -> TestResult<Vec<PgRow>>
Execute a query and return all rows
Sourcepub async fn record_exists(
&self,
table: &str,
conditions: &[(&str, &dyn ToString)],
) -> TestResult<bool>
pub async fn record_exists( &self, table: &str, conditions: &[(&str, &dyn ToString)], ) -> TestResult<bool>
Check if a record exists in the database
Sourcepub async fn count_records(
&self,
table: &str,
conditions: &[(&str, &dyn ToString)],
) -> TestResult<i64>
pub async fn count_records( &self, table: &str, conditions: &[(&str, &dyn ToString)], ) -> TestResult<i64>
Count records in a table with conditions
Sourcepub async fn cleanup(&self) -> TestResult<()>
pub async fn cleanup(&self) -> TestResult<()>
Clean up test data (truncate all tables except migrations)
Sourcepub async fn seed_from_json(&self, data: JsonValue) -> TestResult<()>
pub async fn seed_from_json(&self, data: JsonValue) -> TestResult<()>
Seed test data from a JSON file or inline JSON
Trait Implementations§
Source§impl Clone for TestDatabase
impl Clone for TestDatabase
Source§fn clone(&self) -> TestDatabase
fn clone(&self) -> TestDatabase
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for TestDatabase
impl !RefUnwindSafe for TestDatabase
impl Send for TestDatabase
impl Sync for TestDatabase
impl Unpin for TestDatabase
impl !UnwindSafe for TestDatabase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more