pub enum OrderBy {
Field(OrderByField),
Fields(Box<[OrderByField]>),
}Expand description
Order by specification that can be a single field or multiple fields.
Variants§
Field(OrderByField)
Order by a single field.
Fields(Box<[OrderByField]>)
Order by multiple fields (frozen slice for memory efficiency).
Implementations§
Source§impl OrderBy
impl OrderBy
Sourcepub fn then(self, field: OrderByField) -> Self
pub fn then(self, field: OrderByField) -> Self
Add a field to the order by.
Sourcepub fn from_fields(fields: impl IntoIterator<Item = OrderByField>) -> Self
pub fn from_fields(fields: impl IntoIterator<Item = OrderByField>) -> Self
Create an OrderBy from multiple fields (optimized).
Sourcepub fn to_sql(&self) -> String
pub fn to_sql(&self) -> String
Generate the SQL ORDER BY clause (without the “ORDER BY” keyword).
Optimized to write directly to a pre-sized buffer.
Sourcepub fn write_sql(&self, buffer: &mut String)
pub fn write_sql(&self, buffer: &mut String)
Write the SQL ORDER BY clause directly to a buffer (zero allocation).
§Examples
use prax_query::types::{OrderBy, OrderByField};
let order = OrderBy::from_fields([
OrderByField::desc("created_at"),
OrderByField::asc("id"),
]);
let mut buffer = String::with_capacity(64);
buffer.push_str("ORDER BY ");
order.write_sql(&mut buffer);
assert_eq!(buffer, "ORDER BY created_at DESC, id ASC");Sourcepub fn field_count(&self) -> usize
pub fn field_count(&self) -> usize
Get the number of fields in this OrderBy.
Trait Implementations§
Source§impl From<OrderByField> for OrderBy
impl From<OrderByField> for OrderBy
Source§fn from(field: OrderByField) -> Self
fn from(field: OrderByField) -> Self
Converts to this type from the input type.
Source§impl From<Vec<OrderByField>> for OrderBy
impl From<Vec<OrderByField>> for OrderBy
Source§fn from(fields: Vec<OrderByField>) -> Self
fn from(fields: Vec<OrderByField>) -> Self
Converts to this type from the input type.
impl Eq for OrderBy
impl StructuralPartialEq for OrderBy
Auto Trait Implementations§
impl Freeze for OrderBy
impl RefUnwindSafe for OrderBy
impl Send for OrderBy
impl Sync for OrderBy
impl Unpin for OrderBy
impl UnwindSafe for OrderBy
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