Skip to main content

LoadExt

Trait LoadExt 

Source
pub trait LoadExt {
    // Provided methods
    fn load<'e, Idx, E: PgExecutor<'e>>(
        &self,
        executor: E,
    ) -> impl Future<Output = Result<Vec<<Self as RowQuery<Idx>>::Output>>>
       where Self: RowQuery<Idx> { ... }
    fn load_one<'e, Idx, E: PgExecutor<'e>>(
        &self,
        executor: E,
    ) -> impl Future<Output = Result<Option<<Self as RowQuery<Idx>>::Output>>>
       where Self: RowQuery<Idx> { ... }
    fn stream<'e, Idx, E: PgExecutor<'e>>(
        &self,
        executor: E,
    ) -> Result<impl Stream<Item = Result<<Self as RowQuery<Idx>>::Output>> + Send + Unpin + 'e>
       where Self: RowQuery<Idx>,
             <Self as RowQuery<Idx>>::Output: Send + 'e { ... }
}
Expand description

load for the rows, load_one for the first of them, stream for them one at a time, and ExecuteExt::execute where there are none to decode. One trait for every row-producing builder keeps the terminal vocabulary tied to what a statement yields rather than to which builder happens to be in hand.

Implemented for every builder, satisfiable by the ones that produce rows: what a builder can’t do is then reported by RowQuery, which says so, rather than by the method not existing, which rustc answers with a list of unsatisfied bounds or, worse, by suggesting Iterator. Not a blanket impl, since load/count/execute are names other traits in a caller’s scope have too. A builder added here needs its three empty impls, or its terminal goes back to reporting nothing.

Provided Methods§

Source

fn load<'e, Idx, E: PgExecutor<'e>>( &self, executor: E, ) -> impl Future<Output = Result<Vec<<Self as RowQuery<Idx>>::Output>>>
where Self: RowQuery<Idx>,

Source

fn load_one<'e, Idx, E: PgExecutor<'e>>( &self, executor: E, ) -> impl Future<Output = Result<Option<<Self as RowQuery<Idx>>::Output>>>
where Self: RowQuery<Idx>,

Source

fn stream<'e, Idx, E: PgExecutor<'e>>( &self, executor: E, ) -> Result<impl Stream<Item = Result<<Self as RowQuery<Idx>>::Output>> + Send + Unpin + 'e>
where Self: RowQuery<Idx>, <Self as RowQuery<Idx>>::Output: Send + 'e,

The rows one at a time, for a result too large to hold: an export that writes as it reads rather than collecting first. Yields the same values .load(..) would, decoded as each row arrives.

Not a cursor: the server still produces the whole result, and the connection is held until the stream is dropped or exhausted. What this bounds is the client’s memory, which is what a Vec of every row costs.

Returns a Result around the stream rather than as its first item, because what can fail before a row arrives (an unresolved placeholder, a value whose feature is on in qbrs and off here) is a misuse of this crate rather than a row that didn’t decode. Everything the database has to say arrives as an item.

Send and Unpin are promised, so the stream can be spawned and polled without pinning it first, which a generic caller has no way to ask for otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<D, Output> LoadExt for DynSelect<D, Output>

Source§

impl<D, Output> LoadExt for SetOp<D, Output>

Source§

impl<D, R: InsertRow> LoadExt for Insert<D, R>

Source§

impl<D, Scope, Sel, Outer> LoadExt for Select<D, Scope, Sel, Outer>

Source§

impl<D, T: Table> LoadExt for Delete<D, T>

Source§

impl<D, T: Table> LoadExt for InsertSelect<D, T>

Source§

impl<D, T: Table> LoadExt for Update<D, T>

Source§

impl<S, Sel> LoadExt for Returning<S, Sel>

Source§

impl<Sel> LoadExt for SelectSeed<Sel>

Implementors§