Skip to main content

SelectBuilder

Struct SelectBuilder 

Source
pub struct SelectBuilder { /* private fields */ }
Expand description

Fluent builder for SELECT statements.

§Examples

use sqlglot_rust::builder::select;

let query = select(&["a", "b"])
    .from("users")
    .where_clause("active = true")
    .order_by(&["created_at DESC"])
    .limit(10)
    .build();

Implementations§

Source§

impl SelectBuilder

Source

pub fn new() -> Self

Create a new empty SELECT builder.

Source

pub fn dialect(self, dialect: Dialect) -> Self

Set the dialect for parsing string inputs.

Source

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

Add columns to the SELECT list from strings.

Each string is parsed as an expression.

Source

pub fn column_expr(self, expr: Expr, alias: Option<&str>) -> Self

Add a single column expression.

Source

pub fn all(self) -> Self

Add a wildcard (*) to the SELECT list.

Source

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

Add a qualified wildcard (table.*) to the SELECT list.

Source

pub fn distinct(self) -> Self

Set distinct mode.

Source

pub fn from(self, table_name: &str) -> Self

Set the FROM clause to a table name.

Source

pub fn from_table(self, table_ref: TableRef) -> Self

Set the FROM clause to a table reference.

Source

pub fn from_subquery(self, query: Statement, alias: &str) -> Self

Set the FROM clause to a subquery.

Source

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

Add a JOIN clause.

Source

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

Add a LEFT JOIN clause.

Source

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

Add a RIGHT JOIN clause.

Source

pub fn full_join(self, table_name: &str, on: &str) -> Self

Add a FULL JOIN clause.

Source

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

Add a CROSS JOIN clause.

Source

pub fn join_using( self, table_name: &str, columns: &[&str], join_type: JoinType, ) -> Self

Add a JOIN with USING clause.

Source

pub fn join_subquery( self, query: Statement, alias: &str, on: &str, join_type: JoinType, ) -> Self

Add a JOIN with a subquery.

Source

pub fn where_clause(self, condition: &str) -> Self

Set the WHERE clause from a string.

Source

pub fn where_expr(self, expr: Expr) -> Self

Set the WHERE clause from an expression.

Source

pub fn and_where(self, condition: &str) -> Self

Add to the WHERE clause with AND.

Source

pub fn or_where(self, condition: &str) -> Self

Add to the WHERE clause with OR.

Source

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

Set the GROUP BY clause.

Source

pub fn add_group_by(self, expr: &str) -> Self

Add a GROUP BY expression.

Source

pub fn having(self, condition: &str) -> Self

Set the HAVING clause.

Source

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

Set the ORDER BY clause.

Source

pub fn add_order_by(self, expr: &str) -> Self

Add an ORDER BY item.

Source

pub fn add_order_by_expr( self, expr: Expr, ascending: bool, nulls_first: Option<bool>, ) -> Self

Add an ORDER BY item with explicit direction.

Source

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

Set the LIMIT clause.

Source

pub fn limit_expr(self, expr: Expr) -> Self

Set the LIMIT clause from an expression.

Source

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

Set the OFFSET clause.

Source

pub fn offset_expr(self, expr: Expr) -> Self

Set the OFFSET clause from an expression.

Source

pub fn top(self, n: i64) -> Self

Set TOP N (T-SQL style).

Source

pub fn qualify(self, condition: &str) -> Self

Set the QUALIFY clause (BigQuery, Snowflake).

Source

pub fn build(self) -> Statement

Build the final SELECT statement.

Source

pub fn build_select(self) -> SelectStatement

Build and return the inner SelectStatement.

Trait Implementations§

Source§

impl Clone for SelectBuilder

Source§

fn clone(&self) -> SelectBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SelectBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SelectBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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.