pub struct Cte { /* private fields */ }Expand description
A Common Table Expression (WITH clause).
Implementations§
Source§impl Cte
impl Cte
Sourcepub fn recursive(name: impl Into<String>) -> Self
pub fn recursive(name: impl Into<String>) -> Self
Create a new recursive CTE.
Recursive CTEs require an initial (anchor) term and a recursive term joined with UNION ALL.
§Example
ⓘ
// Traverse an employee hierarchy
let hierarchy = Cte::recursive("org_chart")
.columns(&["id", "name", "level"])
.as_select("SELECT id, name, 0 FROM employees WHERE manager_id IS NULL")
.union_all("SELECT e.id, e.name, h.level + 1 FROM employees e JOIN org_chart h ON e.manager_id = h.id");Sourcepub fn as_select_with_params(
self,
sql: impl Into<String>,
params: Vec<Value>,
) -> Self
pub fn as_select_with_params( self, sql: impl Into<String>, params: Vec<Value>, ) -> Self
Set the CTE query from SQL with parameters.
§Arguments
sql- The SQL query for the CTEparams- Parameters to bind
Sourcepub fn union_all_with_params(
self,
sql: impl Into<String>,
params: Vec<Value>,
) -> Self
pub fn union_all_with_params( self, sql: impl Into<String>, params: Vec<Value>, ) -> Self
Add a UNION ALL clause with parameters.
Sourcepub fn is_recursive(&self) -> bool
pub fn is_recursive(&self) -> bool
Check if this is a recursive CTE.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cte
impl RefUnwindSafe for Cte
impl Send for Cte
impl Sync for Cte
impl Unpin for Cte
impl UnsafeUnpin for Cte
impl UnwindSafe for Cte
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).