pub struct WindowSpecRef<'a> {
pub partition_by: SmallVec<[Cow<'a, str>; 4]>,
pub order_by: SmallVec<[(Cow<'a, str>, SortOrder); 4]>,
pub frame: Option<FrameRef<'a>>,
pub window_ref: Option<Cow<'a, str>>,
}Expand description
A zero-copy window specification using borrowed column references.
This is more efficient than WindowSpec when working with string literals.
§Example
use prax_query::zero_copy::WindowSpecRef;
use prax_query::sql::DatabaseType;
// All column names are borrowed - no allocations
let spec = WindowSpecRef::new()
.partition_by(&["dept", "team"])
.order_by_asc("salary")
.rows_unbounded_preceding();
let sql = spec.to_sql(DatabaseType::PostgreSQL);Fields§
§partition_by: SmallVec<[Cow<'a, str>; 4]>Partition by columns (borrowed slice or owned vec).
order_by: SmallVec<[(Cow<'a, str>, SortOrder); 4]>Order by columns with direction.
frame: Option<FrameRef<'a>>Frame clause.
window_ref: Option<Cow<'a, str>>Reference to named window.
Implementations§
Source§impl<'a> WindowSpecRef<'a>
impl<'a> WindowSpecRef<'a>
Sourcepub fn partition_by(self, columns: &[&'a str]) -> Self
pub fn partition_by(self, columns: &[&'a str]) -> Self
Add partition by columns from a slice (zero-copy).
Sourcepub fn partition_by_owned<I, S>(self, columns: I) -> Self
pub fn partition_by_owned<I, S>(self, columns: I) -> Self
Add partition by columns (owned).
Sourcepub fn partition_by_col(self, column: &'a str) -> Self
pub fn partition_by_col(self, column: &'a str) -> Self
Add a single partition column (borrowed).
Sourcepub fn order_by_asc(self, column: &'a str) -> Self
pub fn order_by_asc(self, column: &'a str) -> Self
Add order by column ascending (borrowed).
Sourcepub fn order_by_desc(self, column: &'a str) -> Self
pub fn order_by_desc(self, column: &'a str) -> Self
Add order by column descending (borrowed).
Sourcepub fn order_by(self, column: &'a str, order: SortOrder) -> Self
pub fn order_by(self, column: &'a str, order: SortOrder) -> Self
Add order by column with direction (borrowed).
Sourcepub fn order_by_owned(self, column: String, order: SortOrder) -> Self
pub fn order_by_owned(self, column: String, order: SortOrder) -> Self
Add order by column (owned).
Sourcepub fn rows(
self,
start: FrameBoundRef<'a>,
end: Option<FrameBoundRef<'a>>,
) -> Self
pub fn rows( self, start: FrameBoundRef<'a>, end: Option<FrameBoundRef<'a>>, ) -> Self
Set ROWS frame.
Sourcepub fn range(
self,
start: FrameBoundRef<'a>,
end: Option<FrameBoundRef<'a>>,
) -> Self
pub fn range( self, start: FrameBoundRef<'a>, end: Option<FrameBoundRef<'a>>, ) -> Self
Set RANGE frame.
Sourcepub fn rows_unbounded_preceding(self) -> Self
pub fn rows_unbounded_preceding(self) -> Self
Set ROWS UNBOUNDED PRECEDING frame (common for running totals).
Sourcepub fn window_name(self, name: &'a str) -> Self
pub fn window_name(self, name: &'a str) -> Self
Set reference to named window.
Sourcepub fn is_zero_copy(&self) -> bool
pub fn is_zero_copy(&self) -> bool
Check if this spec uses only borrowed data.
Sourcepub fn to_sql(&self, _db_type: DatabaseType) -> String
pub fn to_sql(&self, _db_type: DatabaseType) -> String
Generate SQL for the OVER clause.
Trait Implementations§
Source§impl<'a> Clone for WindowSpecRef<'a>
impl<'a> Clone for WindowSpecRef<'a>
Source§fn clone(&self) -> WindowSpecRef<'a>
fn clone(&self) -> WindowSpecRef<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for WindowSpecRef<'a>
impl<'a> Debug for WindowSpecRef<'a>
Source§impl<'a> Default for WindowSpecRef<'a>
impl<'a> Default for WindowSpecRef<'a>
Source§fn default() -> WindowSpecRef<'a>
fn default() -> WindowSpecRef<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<'a> Freeze for WindowSpecRef<'a>
impl<'a> RefUnwindSafe for WindowSpecRef<'a>
impl<'a> Send for WindowSpecRef<'a>
impl<'a> Sync for WindowSpecRef<'a>
impl<'a> Unpin for WindowSpecRef<'a>
impl<'a> UnwindSafe for WindowSpecRef<'a>
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