pub struct Read<'a, F> { /* private fields */ }Expand description
A database read that starts when awaited.
Constructed by CovenHandle::read or
CovenReadHandle::read. Await it to receive
the fetched values, or attach process to compute a result
on separate workers after releasing the database connection.
let titles = handle.read(|sql| {
Ok(sql.query("SELECT body FROM notes", [], |row| row.get::<_, String>(0))?)
}).process(|mut titles| {
titles.sort();
Ok(titles)
}).await?;Use IntoFuture::into_future when passing the read to an API that requires
a Future rather than an awaitable value.
Implementations§
Source§impl<'a, F, Raw> Read<'a, F>where
F: for<'connection> FnOnce(SqlReadContext<'connection>) -> CovenResult<Raw> + Send + 'static,
Raw: Send + 'static,
impl<'a, F, Raw> Read<'a, F>where
F: for<'connection> FnOnce(SqlReadContext<'connection>) -> CovenResult<Raw> + Send + 'static,
Raw: Send + 'static,
Sourcepub async fn process<P, R>(self, process: P) -> CovenResult<R>
pub async fn process<P, R>(self, process: P) -> CovenResult<R>
Process the fetched values on bounded workers after the read transaction ends. Fetch every database input in the read closure; the processor receives owned values without a SQL context. A failed read skips it.
Trait Implementations§
Source§impl<'a, F, R> IntoFuture for Read<'a, F>where
F: for<'connection> FnOnce(SqlReadContext<'connection>) -> CovenResult<R> + Send + 'static,
R: Send + 'static,
impl<'a, F, R> IntoFuture for Read<'a, F>where
F: for<'connection> FnOnce(SqlReadContext<'connection>) -> CovenResult<R> + Send + 'static,
R: Send + 'static,
Source§type Output = Result<R, CovenError>
type Output = Result<R, CovenError>
The output that the future will produce on completion.
Source§type IntoFuture = Pin<Box<dyn Future<Output = <Read<'a, F> as IntoFuture>::Output> + Send + 'a>>
type IntoFuture = Pin<Box<dyn Future<Output = <Read<'a, F> as IntoFuture>::Output> + Send + 'a>>
Which kind of future are we turning this into?
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Creates a future from a value. Read more
Auto Trait Implementations§
impl<'a, F> Freeze for Read<'a, F>where
F: Freeze,
impl<'a, F> !RefUnwindSafe for Read<'a, F>
impl<'a, F> Send for Read<'a, F>where
F: Send,
impl<'a, F> Sync for Read<'a, F>where
F: Sync,
impl<'a, F> Unpin for Read<'a, F>where
F: Unpin,
impl<'a, F> UnsafeUnpin for Read<'a, F>where
F: UnsafeUnpin,
impl<'a, F> !UnwindSafe for Read<'a, F>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 moreCreates a shared type from an unshared type.