Skip to main content

ModelSelect

Struct ModelSelect 

Source
pub struct ModelSelect<M: View> { /* private fields */ }
Expand description

A model SELECT: the dialect statement plus the extension payloads the query carries — hooks, preload mapper mods, then-loaders.

Still a Query: build() hands back the same (String, Vec<Value>) escape hatch as everything else, and the raw Execute verbs keep working. The model verbs — all, one, optional — are the path that also runs the extensions, reading them back through QueryExtensions, which this type implements with the pinned payload types.

Layer 1 interop: the wrapper implements every Has* clause trait its statement implements (see delegate.rs), so shared dialect mods (select::limit(20), select::where_("raw sql"), joins, CTEs, …) apply to it directly, in the same tuple as typed filters. Statement-specific mods go through apply.

Implementations§

Source§

impl<M: View> ModelSelect<M>

Source

pub fn apply(&mut self, mods: impl Mod<M::Select>)

Apply mods written against the concrete dialect statement — the escape hatch for the statement-specific ones (psql’s select::distinct()) that are not generic over a Has* trait and so cannot land on the wrapper directly.

Source

pub fn as_select(&self) -> &M::Select

The dialect statement, for inspection.

Source

pub fn add_hook(&mut self, hook: ExecHook)

Attach a pre-query hook. Runs on the caller’s executor, before the statement, in attachment order.

Source

pub fn add_mapper_mod(&mut self, mapper_mod: MapperMod<M::Row>)

Attach a mapper mod — generated preload mods call this.

Source

pub fn add_loader(&mut self, loader: Loader<M::Row>)

Attach a then-loader — generated then-load mods call this.

Source

pub async fn all(&self, db: &dyn Executor) -> Result<Vec<M::Row>, ExecError>

Every row, mapped, loaded, hooked.

The order is the contract: hooks → the statement (through the same traced verb funnel as everything else) → base FromRow plus mapper mods, per row → then-loaders → View::after_select. All of it on db, so inside db’s transaction when db is one.

Source

pub async fn one(&self, db: &dyn Executor) -> Result<M::Row, ExecError>

Exactly one row — zero is ExecError::RowNotFound, two is ExecError::TooManyRows, matching the execution layer’s “one means one”.

Source

pub async fn optional( &self, db: &dyn Executor, ) -> Result<Option<M::Row>, ExecError>

At most one row; a second is still ExecError::TooManyRows.

Trait Implementations§

Source§

impl<M: View> Debug for ModelSelect<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M: View> Expression for ModelSelect<M>

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Append this fragment to w. Read more
Source§

impl<M: View> HasCombines for ModelSelect<M>
where M::Select: HasCombines,

Source§

fn combines_mut(&mut self) -> &mut Combines

The set operations to modify.
Source§

impl<M: View> HasFetch for ModelSelect<M>
where M::Select: HasFetch,

Source§

fn fetch_mut(&mut self) -> &mut Fetch

The FETCH clause to modify.
Source§

impl<M: View> HasGroupBy for ModelSelect<M>
where M::Select: HasGroupBy,

Source§

fn group_by_mut(&mut self) -> &mut GroupBy

The GROUP BY clause to modify.
Source§

impl<M: View> HasHaving for ModelSelect<M>
where M::Select: HasHaving,

Source§

fn having_mut(&mut self) -> &mut Having

The HAVING clause to modify.
Source§

impl<M: View> HasJoins for ModelSelect<M>
where M::Select: HasJoins,

Source§

fn joins_mut(&mut self) -> &mut Vec<Join>

The join list to modify.
Source§

impl<M: View> HasLimit for ModelSelect<M>
where M::Select: HasLimit,

Source§

fn limit_mut(&mut self) -> &mut Limit

The LIMIT clause to modify.
Source§

impl<M: View> HasLocks for ModelSelect<M>
where M::Select: HasLocks,

Source§

fn locks_mut(&mut self) -> &mut Locks

The locking clauses to modify.
Source§

impl<M: View> HasOffset for ModelSelect<M>
where M::Select: HasOffset,

Source§

fn offset_mut(&mut self) -> &mut Offset

The OFFSET clause to modify.
Source§

impl<M: View> HasOrderBy for ModelSelect<M>
where M::Select: HasOrderBy,

Source§

fn order_by_mut(&mut self) -> &mut OrderBy

The ORDER BY clause to modify.
Source§

impl<M: View> HasSelectList for ModelSelect<M>

Source§

fn select_list_mut(&mut self) -> &mut SelectList

The projection to modify.
Source§

impl<M: View> HasTableRef for ModelSelect<M>
where M::Select: HasTableRef,

Source§

fn table_ref_mut(&mut self) -> &mut TableRef

The table reference to modify.
Source§

impl<M: View> HasWhere for ModelSelect<M>
where M::Select: HasWhere,

Source§

fn where_mut(&mut self) -> &mut Where

The WHERE clause to modify.
Source§

impl<M: View> HasWindows for ModelSelect<M>
where M::Select: HasWindows,

Source§

fn windows_mut(&mut self) -> &mut Windows

The WINDOW clause to modify.
Source§

impl<M: View> HasWith for ModelSelect<M>
where M::Select: HasWith,

Source§

fn with_mut(&mut self) -> &mut With

The WITH clause to modify.
Source§

impl<P, C, K> Mod<ModelSelect<P>> for ThenLoad<P, C, K>
where P: View, C: View, K: Ord + Clone + Send + Sync + 'static,

Source§

fn apply(self, q: &mut ModelSelect<P>)

Apply this modification to q.
Source§

impl<M: View> Query for ModelSelect<M>

Source§

fn query_type(&self) -> QueryType

Which statement this renders.
Source§

fn dialect(&self) -> &dyn Dialect

The dialect this query renders itself in. Read more
Source§

fn build(&self) -> Result<(String, Vec<Value>), Error>

Render to SQL and arguments, numbering placeholders from 1. Read more
Source§

fn build_from(&self, start: usize) -> Result<(String, Vec<Value>), Error>

build with a different first placeholder position, for splicing into a statement that already has arguments — bob’s BuildN.
Source§

impl<M: View> QueryExtensions<Arc<dyn for<'a> Fn(&'a dyn Executor) -> Pin<Box<dyn Future<Output = Result<(), ExecError>> + Send + 'a>> + Sync + Send>, Arc<dyn for<'a> Fn(&'a dyn Executor, &'a mut Vec<<M as View>::Row>) -> Pin<Box<dyn Future<Output = Result<(), ExecError>> + Send + 'a>> + Sync + Send>, Arc<dyn Fn(&mut Row, &mut <M as View>::Row) -> Result<(), ExecError> + Sync + Send>> for ModelSelect<M>

The extension points, answered with the pinned payload types — the completion of the QueryExtensions wiring core left with type parameters.

Source§

fn hooks(&self) -> &[ExecHook]

Hooks to run before this query executes.
Source§

fn loaders(&self) -> &[Loader<M::Row>]

Loaders to run after this query executes, for eagerly loaded relations.
Source§

fn mapper_mods(&self) -> &[MapperMod<M::Row>]

Adjustments to the row mapper, for relations loaded in the same query.

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for ModelSelect<M>

§

impl<M> !UnwindSafe for ModelSelect<M>

§

impl<M> Freeze for ModelSelect<M>
where <M as View>::Select: Freeze,

§

impl<M> Send for ModelSelect<M>

§

impl<M> Sync for ModelSelect<M>

§

impl<M> Unpin for ModelSelect<M>
where <M as View>::Select: Unpin,

§

impl<M> UnsafeUnpin for ModelSelect<M>
where <M as View>::Select: UnsafeUnpin,

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<Q> Execute for Q
where Q: Query + ?Sized,

Source§

fn fetch_all<T>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<Vec<T>, ExecError>> + Send
where T: FromRow,

Every row, mapped to T.
Source§

fn fetch_rows( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<Vec<Row>, ExecError>> + Send

Every row, undecoded. Read more
Source§

fn fetch_one<T>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<T, ExecError>> + Send
where T: FromRow,

Exactly one row. Zero rows is ExecError::RowNotFound; a second row is ExecError::TooManyRows — “one” means one.
Source§

fn fetch_optional<T>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<Option<T>, ExecError>> + Send
where T: FromRow,

At most one row. A second row is still ExecError::TooManyRows.
Source§

fn fetch_scalar<T>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<T, ExecError>> + Send
where T: FromValue,

The first column of the single row — SELECT count(*), or an INSERT … RETURNING id. Read more
Source§

fn fetch_scalars<T>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<Vec<T>, ExecError>> + Send
where T: FromValue,

The first column of every row.
Source§

fn execute( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<ExecResult, ExecError>> + Send

Run for the side effect.
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.