Skip to main content

MockExecutor

Struct MockExecutor 

Source
pub struct MockExecutor {
    pub executed_queries: Vec<(String, usize)>,
    /* private fields */
}
Expand description

An in-memory testing stub satisfying the Executor trait without PostgreSQL connections.

Queues mock results that are drained in FIFO order as queries are executed.

Fields§

§executed_queries: Vec<(String, usize)>

Records all executed queries as (sql, param_count) tuples.

Implementations§

Source§

impl MockExecutor

Source

pub fn new() -> Self

Source

pub fn push_result(&mut self, rows: Vec<Row>)

Enqueues a set of rows to be returned by the next query() call.

Source

pub fn remaining_results(&self) -> usize

Returns the number of remaining mocked result sets.

Source

pub fn reset(&mut self)

Clears all recorded queries and remaining mocked results.

Trait Implementations§

Source§

impl Default for MockExecutor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Executor for MockExecutor

Source§

fn execute(&mut self, query: &str, params: &[&dyn ToSql]) -> OrmResult<u64>

Executes a command (e.g., INSERT, UPDATE, DELETE) and returns the number of affected rows.
Source§

fn query(&mut self, query: &str, params: &[&dyn ToSql]) -> OrmResult<Vec<Row>>

Executes a query and returns the resulting rows.

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.