Skip to main content

SelectBuilder

Struct SelectBuilder 

Source
pub struct SelectBuilder<'a, C: ConnExt> { /* private fields */ }
Expand description

Composable query builder combining filters, sorting, and pagination.

Created via ConnExt::select with a base SQL query. Chain filter, order_by, and cursor_column before executing with page, cursor, fetch_all, fetch_one, or fetch_optional.

Implementations§

Source§

impl<'a, C: ConnExt> SelectBuilder<'a, C>

Source

pub fn filter(self, filter: ValidatedFilter) -> Self

Apply a validated filter (WHERE clauses).

Source

pub fn order_by(self, order: &str) -> Self

Set ORDER BY clause. This is raw SQL — not user input. If a filter has a sort_clause, it takes precedence over this.

Source

pub fn cursor_column(self, col: &str) -> Self

Set the column used for cursor pagination (default: "id").

The column must appear in the SELECT list and be sortable (e.g., ULID, timestamp, auto-increment). Cursor pagination will ORDER BY this column ascending and use it for the WHERE col > ? condition.

Source

pub fn oldest_first(self) -> Self

Use ascending (oldest-first) cursor ordering instead of the default DESC.

By default cursor pagination orders descending (newest-first), which is the common pattern for feeds and timelines. Call this to switch to ascending order when you need chronological (oldest-first) traversal.

Source

pub async fn page<T: FromRow + Serialize>( self, req: PageRequest, ) -> Result<Page<T>>

Execute with offset pagination, returning a Page<T>.

Runs a COUNT(*) subquery for the total, then fetches the requested page with LIMIT/OFFSET.

§Errors

Returns an error if the query or row conversion fails.

Source

pub async fn cursor<T: FromRow + Serialize>( self, req: CursorRequest, ) -> Result<CursorPage<T>>

Execute with cursor pagination. Returns CursorPage<T>.

By default orders descending (newest-first). Use oldest_first to switch to ascending order. The cursor column can be changed with cursor_column.

§Errors

Returns an error if the query or row conversion fails.

Source

pub async fn fetch_all<T: FromRow>(self) -> Result<Vec<T>>

Execute without pagination, returning all matching rows.

§Errors

Returns an error if the query or row conversion fails.

Source

pub async fn fetch_one<T: FromRow>(self) -> Result<T>

Execute without pagination, returning the first row.

§Errors

Returns Error::not_found if no rows match.

Source

pub async fn fetch_optional<T: FromRow>(self) -> Result<Option<T>>

Execute without pagination, returning the first row or None.

§Errors

Returns an error if the query or row conversion fails.

Auto Trait Implementations§

§

impl<'a, C> Freeze for SelectBuilder<'a, C>

§

impl<'a, C> RefUnwindSafe for SelectBuilder<'a, C>
where C: RefUnwindSafe,

§

impl<'a, C> Send for SelectBuilder<'a, C>

§

impl<'a, C> Sync for SelectBuilder<'a, C>

§

impl<'a, C> Unpin for SelectBuilder<'a, C>

§

impl<'a, C> UnsafeUnpin for SelectBuilder<'a, C>

§

impl<'a, C> UnwindSafe for SelectBuilder<'a, C>
where C: RefUnwindSafe,

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,