pub struct Condition {
pub page: Option<PaginationParam>,
pub cond: Condition,
pub order: Vec<(SimpleExpr, Order)>,
}api and seaorm only.Expand description
The query condition hub: filters + optional pagination + sort order.
Built fluently, then applied to a SeaORM Select via Condition::build
or executed directly with Condition::select_page. All CRUD helpers
generated by the default_repo macro funnel through it.
Fields§
§page: Option<PaginationParam>Optional SQL pagination.
cond: ConditionWHERE filters, all() by default.
order: Vec<(SimpleExpr, Order)>Sort expressions, applied in insertion order.
Implementations§
Source§impl Condition
impl Condition
Sourcepub fn new(cond: Condition) -> Self
pub fn new(cond: Condition) -> Self
Wrap an existing sea_orm::Condition as filters.
Sourcepub fn add_sort(self, col: SimpleExpr, sort: Order) -> Self
pub fn add_sort(self, col: SimpleExpr, sort: Order) -> Self
Append one sort expression; later calls take precedence for ties.
Sourcepub fn add_page(self, page: PaginationParam) -> Self
pub fn add_page(self, page: PaginationParam) -> Self
Attach SQL pagination.
Sourcepub fn parse_sort_option(
self,
str: &Option<String>,
col: Vec<ColumnRef>,
) -> Self
pub fn parse_sort_option( self, str: &Option<String>, col: Vec<ColumnRef>, ) -> Self
Parse the sort string when present, see Condition::parse_sort.
Sourcepub fn parse_sort(self, str: &str, col: Vec<ColumnRef>) -> Self
pub fn parse_sort(self, str: &str, col: Vec<ColumnRef>) -> Self
Parse a sort string like -created_at,+name into sort expressions.
-/+ prefixes select descending/ascending order (no prefix =
ascending); names not present in the col whitelist are silently
ignored, so this is safe to feed straight from user input.
Sourcepub fn any() -> Condition
pub fn any() -> Condition
Shortcut of sea_orm::Condition::any.
Sourcepub fn all() -> Condition
pub fn all() -> Condition
Shortcut of sea_orm::Condition::all.
Sourcepub fn add_option<C>(self, condition: Option<C>) -> Self
pub fn add_option<C>(self, condition: Option<C>) -> Self
AND one more condition, ignored when None.
Sourcepub fn build<E>(self, q: Select<E>) -> (Select<E>, Option<PaginationParam>)where
E: EntityTrait,
pub fn build<E>(self, q: Select<E>) -> (Select<E>, Option<PaginationParam>)where
E: EntityTrait,
Apply the sort order and filters to a Select.
Returns the built query together with the detached pagination, ready
for SelectPage::select_page.
Sourcepub async fn select_page<M, E, C>(
self,
q: Select<E>,
db: &C,
) -> Result<(Vec<E::Model>, u64)>
pub async fn select_page<M, E, C>( self, q: Select<E>, db: &C, ) -> Result<(Vec<E::Model>, u64)>
Condition::build + SelectPage::select_page in one call;
returns (items, total_count).
Sourcepub fn add_time<T>(self, p: &TimeParam) -> Selfwhere
T: DefaultColumnTrait,
Available on crate feature entity only.
pub fn add_time<T>(self, p: &TimeParam) -> Selfwhere
T: DefaultColumnTrait,
entity only.Add created/updated time range filters from TimeParam, using the
columns provided by DefaultColumnTrait (usually implemented by the
entity_timestamp macro).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Condition
impl RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl UnsafeUnpin for Condition
impl UnwindSafe for Condition
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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> ⓘ
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> ⓘ
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 more