Skip to main content

Selectable

Trait Selectable 

Source
pub trait Selectable<T, C = Expression<T>>:
    Send
    + Sync
    + Debug
    + Clone {
Show 33 methods // Required methods fn add_source( &mut self, source: impl Into<SourceRef<T>>, alias: Option<String>, ); fn add_field(&mut self, field: impl Into<String>); fn add_expression(&mut self, expression: impl Expressive<T>); fn add_where_condition(&mut self, condition: impl Into<C>); fn set_distinct(&mut self, distinct: bool); fn add_order_by(&mut self, order: impl Into<C>, direction: Order); fn add_group_by(&mut self, expression: impl Expressive<T>); fn set_limit(&mut self, limit: Option<i64>, skip: Option<i64>); fn clear_fields(&mut self); fn clear_where_conditions(&mut self); fn clear_order_by(&mut self); fn clear_group_by(&mut self); fn has_fields(&self) -> bool; fn has_where_conditions(&self) -> bool; fn has_order_by(&self) -> bool; fn has_group_by(&self) -> bool; fn is_distinct(&self) -> bool; fn get_limit(&self) -> Option<i64>; fn get_skip(&self) -> Option<i64>; fn as_field(&self, field: impl Into<String>) -> Expression<T>; fn as_count(&self) -> Expression<T>; fn as_sum(&self, column: impl Expressive<T>) -> Expression<T>; fn as_max(&self, column: impl Expressive<T>) -> Expression<T>; fn as_min(&self, column: impl Expressive<T>) -> Expression<T>; // Provided methods fn with_source(self, source: impl Into<SourceRef<T>>) -> Self where Self: Sized { ... } fn with_source_as( self, source: impl Into<SourceRef<T>>, alias: impl Into<String>, ) -> Self where Self: Sized { ... } fn with_condition(self, condition: impl Into<C>) -> Self where Self: Sized { ... } fn with_order(self, order: impl Into<C>, direction: Order) -> Self where Self: Sized { ... } fn with_field(self, field: impl Into<String>) -> Self where Self: Sized { ... } fn with_expression(self, expression: impl Expressive<T>) -> Self where Self: Sized { ... } fn with_group_by(self, expression: impl Expressive<T>) -> Self where Self: Sized { ... } fn with_distinct(self, distinct: bool) -> Self where Self: Sized { ... } fn with_limit(self, limit: Option<i64>, skip: Option<i64>) -> Self where Self: Sized { ... }
}
Expand description

Unified protocol for building SELECT queries across different databases.

The Selectable trait provides a standardized interface for building SELECT-style queries that work with databases supporting columns, conditions, ordering, limits, and aggregations. This allows the same query building patterns to work across SQL databases, SurrealDB, MongoDB, and other backends.

The trait is parameterized on:

  • T — the value/expression type (e.g. AnySqliteType, AnyMongoType)
  • C — the condition type, defaults to Expression<T> for SQL backends. Document-oriented backends like MongoDB can use bson::Document or a custom condition type.

Implementations handle database-specific syntax while exposing a consistent API for field selection, filtering, sorting, grouping, and aggregation operations. The trait supports both mutable builder methods and fluent chainable methods.

Required Methods§

Source

fn add_source(&mut self, source: impl Into<SourceRef<T>>, alias: Option<String>)

Adds a data source to the FROM clause (table name, subquery, etc.). This is additive — calling it multiple times adds comma-separated sources.

Source

fn add_field(&mut self, field: impl Into<String>)

Adds a column name to the SELECT clause.

Source

fn add_expression(&mut self, expression: impl Expressive<T>)

Adds a complex expression to the SELECT clause.

Source

fn add_where_condition(&mut self, condition: impl Into<C>)

Adds a condition to the WHERE clause.

Source

fn set_distinct(&mut self, distinct: bool)

Sets whether the query should return distinct results.

Source

fn add_order_by(&mut self, order: impl Into<C>, direction: Order)

Adds an ORDER BY clause with direction and optional null handling.

Source

fn add_group_by(&mut self, expression: impl Expressive<T>)

Adds a GROUP BY clause.

Source

fn set_limit(&mut self, limit: Option<i64>, skip: Option<i64>)

Sets LIMIT and OFFSET for result pagination.

Source

fn clear_fields(&mut self)

Removes all fields from the SELECT clause.

Source

fn clear_where_conditions(&mut self)

Removes all WHERE conditions.

Source

fn clear_order_by(&mut self)

Removes all ORDER BY clauses.

Source

fn clear_group_by(&mut self)

Removes all GROUP BY clauses.

Source

fn has_fields(&self) -> bool

Returns true if any fields have been added to SELECT clause.

Source

fn has_where_conditions(&self) -> bool

Returns true if any WHERE conditions have been added.

Source

fn has_order_by(&self) -> bool

Returns true if any ORDER BY clauses have been added.

Source

fn has_group_by(&self) -> bool

Returns true if any GROUP BY clauses have been added.

Source

fn is_distinct(&self) -> bool

Returns true if DISTINCT mode is enabled.

Source

fn get_limit(&self) -> Option<i64>

Returns the current LIMIT value, if set.

Source

fn get_skip(&self) -> Option<i64>

Returns the current OFFSET/SKIP value, if set.

Source

fn as_field(&self, field: impl Into<String>) -> Expression<T>

Creates a single-field subquery expression from this query configuration.

Builds SELECT field FROM ... WHERE ... — useful for correlated subqueries.

Source

fn as_count(&self) -> Expression<T>

Creates a COUNT(*) expression from this query configuration.

Source

fn as_sum(&self, column: impl Expressive<T>) -> Expression<T>

Creates a SUM(column) expression from this query configuration.

Source

fn as_max(&self, column: impl Expressive<T>) -> Expression<T>

Creates a MAX(column) expression from this query configuration.

Source

fn as_min(&self, column: impl Expressive<T>) -> Expression<T>

Creates a MIN(column) expression from this query configuration.

Provided Methods§

Source

fn with_source(self, source: impl Into<SourceRef<T>>) -> Self
where Self: Sized,

Builder pattern method identical to Self::add_source without alias.

Source

fn with_source_as( self, source: impl Into<SourceRef<T>>, alias: impl Into<String>, ) -> Self
where Self: Sized,

Builder pattern method identical to Self::add_source with alias.

Source

fn with_condition(self, condition: impl Into<C>) -> Self
where Self: Sized,

Builder pattern method identical to Self::add_where_condition.

Source

fn with_order(self, order: impl Into<C>, direction: Order) -> Self
where Self: Sized,

Builder pattern method identical to Self::add_order_by.

Source

fn with_field(self, field: impl Into<String>) -> Self
where Self: Sized,

Builder pattern method identical to Self::add_field.

Source

fn with_expression(self, expression: impl Expressive<T>) -> Self
where Self: Sized,

Builder pattern method identical to Self::add_expression.

Source

fn with_group_by(self, expression: impl Expressive<T>) -> Self
where Self: Sized,

Builder pattern method identical to Self::add_group_by.

Source

fn with_distinct(self, distinct: bool) -> Self
where Self: Sized,

Builder pattern method identical to Self::set_distinct.

Source

fn with_limit(self, limit: Option<i64>, skip: Option<i64>) -> Self
where Self: Sized,

Builder pattern method identical to Self::set_limit.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§