SelectDyn

Struct SelectDyn 

Source
pub struct SelectDyn<Cols, From> { /* private fields */ }
Expand description

A dynamic SELECT statement builder using string-based column names.

For compile-time validated queries, use Select from builder::typed.

Uses the typestate pattern to ensure that:

  • build() is only available when both columns and FROM are specified
  • where_clause() is only available after FROM is specified
  • group_by(), having(), order_by() follow SQL semantics

Implementations§

Source§

impl SelectDyn<NoColumns, NoFrom>

Source

pub fn new() -> Self

Creates a new SELECT builder.

Source§

impl<From> SelectDyn<NoColumns, From>

Source

pub fn columns(self, cols: &[&str]) -> SelectDyn<HasColumns, From>

Specifies the columns to select.

Source

pub fn all(self) -> SelectDyn<HasColumns, From>

Selects all columns (*).

Source§

impl<Cols> SelectDyn<Cols, NoFrom>

Source

pub fn from(self, table: &str) -> SelectDyn<Cols, HasFrom>

Specifies the table to select from.

Source§

impl<Cols> SelectDyn<Cols, HasFrom>

Source

pub fn where_clause(self, expr: ExprBuilder) -> Self

Adds a WHERE clause.

Source

pub fn join(self, table: &str, on: &str) -> Self

Adds an INNER JOIN.

Source

pub fn left_join(self, table: &str, on: &str) -> Self

Adds a LEFT JOIN.

Source

pub fn right_join(self, table: &str, on: &str) -> Self

Adds a RIGHT JOIN.

Source

pub fn cross_join(self, table: &str) -> Self

Adds a CROSS JOIN.

Source§

impl<From> SelectDyn<HasColumns, From>

Source

pub fn distinct(self) -> Self

Sets DISTINCT.

Source§

impl SelectDyn<HasColumns, HasFrom>

Source

pub fn group_by(self, cols: &[&str]) -> Self

Adds a GROUP BY clause.

Source

pub fn having(self, expr: ExprBuilder) -> Self

Adds a HAVING clause (only valid after GROUP BY).

Source

pub fn order_by(self, cols: &[&str]) -> Self

Adds an ORDER BY clause.

Source

pub fn order_by_desc(self, cols: &[&str]) -> Self

Adds an ORDER BY DESC clause.

Source

pub const fn limit(self, n: u64) -> Self

Adds a LIMIT clause.

Source

pub const fn offset(self, n: u64) -> Self

Adds an OFFSET clause.

Source

pub fn build(self) -> (String, Vec<SqlValue>)

Builds the SELECT statement and returns SQL with parameters.

Source

pub fn build_sql(self) -> String

Builds the SELECT statement and returns only the SQL string.

Warning: Parameters are inlined using proper escaping. Prefer build() for parameterized queries.

Trait Implementations§

Source§

impl Default for SelectDyn<NoColumns, NoFrom>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Cols, From> Freeze for SelectDyn<Cols, From>

§

impl<Cols, From> RefUnwindSafe for SelectDyn<Cols, From>
where Cols: RefUnwindSafe, From: RefUnwindSafe,

§

impl<Cols, From> Send for SelectDyn<Cols, From>
where Cols: Send, From: Send,

§

impl<Cols, From> Sync for SelectDyn<Cols, From>
where Cols: Sync, From: Sync,

§

impl<Cols, From> Unpin for SelectDyn<Cols, From>
where Cols: Unpin, From: Unpin,

§

impl<Cols, From> UnwindSafe for SelectDyn<Cols, From>
where Cols: UnwindSafe, From: UnwindSafe,

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> 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, 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.