Skip to main content

CteSpec

Struct CteSpec 

Source
#[non_exhaustive]
pub struct CteSpec { pub name: String, pub sql: String, pub table: String, pub where_expr: Option<BoolExpr>, pub params: Vec<DbValue>, pub columns: Vec<String>, pub is_recursive: bool, pub recursive_link: Option<(String, String)>, }
Expand description

Specification for a Common Table Expression (CTE).

A CTE is defined by a name and either a pre-compiled SQL string (raw mode) or a typed WHERE expression compiled at SQL generation time (typed mode). The main query references the CTE by name (typically in its FROM clause). Parameters are prepended to the main query’s parameter list in CTE declaration order.

§Modes

  • Raw mode (via with_cte_internal): sql is non-empty, table and where_expr are empty. The SQL is emitted verbatim. Placeholders use the ? style and are not converted to provider-specific syntax — suitable for SQLite/MySQL but may produce incorrect $N on PostgreSQL.

  • Typed mode (via with_cte_typed, used by linq!(with ...)): table is non-empty, where_expr is Some(...), sql is empty. The CTE body SELECT * FROM <table> WHERE <expr> is compiled at to_sql_with time using the provider’s placeholder syntax, ensuring correct $N numbering on all providers.

#[non_exhaustive] prevents direct struct construction outside the crate so future field additions don’t break downstream code. Use with_cte_internal (raw mode) or with_cte_typed (typed mode) to create CTE specifications.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: String

The CTE name (used as the derived table alias in WITH name AS (...)).

§sql: String

Raw mode: the pre-compiled SQL of the CTE body. Empty in typed mode.

§table: String

Typed mode: source table name (SELECT * FROM <table> WHERE ...). Empty in raw mode.

§where_expr: Option<BoolExpr>

Typed mode: WHERE expression compiled at to_sql_with time with the provider’s placeholder syntax. None in raw mode.

§params: Vec<DbValue>

Parameter values bound to the CTE’s placeholders, in order. In typed mode, these are extracted from where_expr via collect_bool_expr_values at construction time.

§columns: Vec<String>

Optional explicit column list (WITH name (c1, c2) AS (...)). Empty means no explicit column list.

§is_recursive: bool

Recursive CTE flag. When true, generates WITH RECURSIVE name AS (anchor UNION ALL SELECT t.* FROM table t JOIN name ON t.fk = name.pk).

§recursive_link: Option<(String, String)>

Recursive link columns: (fk_column, pk_column). Only meaningful when is_recursive is true. The recursive member joins the CTE name to the source table via t.fk = name.pk.

Trait Implementations§

Source§

impl Clone for CteSpec

Source§

fn clone(&self) -> CteSpec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CteSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.