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 toExpression<T>for SQL backends. Document-oriented backends like MongoDB can usebson::Documentor 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§
Sourcefn add_source(&mut self, source: impl Into<SourceRef<T>>, alias: Option<String>)
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.
Sourcefn add_expression(&mut self, expression: impl Expressive<T>)
fn add_expression(&mut self, expression: impl Expressive<T>)
Adds a complex expression to the SELECT clause.
Sourcefn add_where_condition(&mut self, condition: impl Into<C>)
fn add_where_condition(&mut self, condition: impl Into<C>)
Adds a condition to the WHERE clause.
Sourcefn set_distinct(&mut self, distinct: bool)
fn set_distinct(&mut self, distinct: bool)
Sets whether the query should return distinct results.
Sourcefn add_order_by(&mut self, order: impl Into<C>, direction: Order)
fn add_order_by(&mut self, order: impl Into<C>, direction: Order)
Adds an ORDER BY clause with direction and optional null handling.
Sourcefn add_group_by(&mut self, expression: impl Expressive<T>)
fn add_group_by(&mut self, expression: impl Expressive<T>)
Adds a GROUP BY clause.
Sourcefn set_limit(&mut self, limit: Option<i64>, skip: Option<i64>)
fn set_limit(&mut self, limit: Option<i64>, skip: Option<i64>)
Sets LIMIT and OFFSET for result pagination.
Sourcefn clear_fields(&mut self)
fn clear_fields(&mut self)
Removes all fields from the SELECT clause.
Sourcefn clear_where_conditions(&mut self)
fn clear_where_conditions(&mut self)
Removes all WHERE conditions.
Sourcefn clear_order_by(&mut self)
fn clear_order_by(&mut self)
Removes all ORDER BY clauses.
Sourcefn clear_group_by(&mut self)
fn clear_group_by(&mut self)
Removes all GROUP BY clauses.
Sourcefn has_fields(&self) -> bool
fn has_fields(&self) -> bool
Returns true if any fields have been added to SELECT clause.
Sourcefn has_where_conditions(&self) -> bool
fn has_where_conditions(&self) -> bool
Returns true if any WHERE conditions have been added.
Sourcefn has_order_by(&self) -> bool
fn has_order_by(&self) -> bool
Returns true if any ORDER BY clauses have been added.
Sourcefn has_group_by(&self) -> bool
fn has_group_by(&self) -> bool
Returns true if any GROUP BY clauses have been added.
Sourcefn is_distinct(&self) -> bool
fn is_distinct(&self) -> bool
Returns true if DISTINCT mode is enabled.
Sourcefn as_field(&self, field: impl Into<String>) -> Expression<T>
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.
Sourcefn as_count(&self) -> Expression<T>
fn as_count(&self) -> Expression<T>
Creates a COUNT(*) expression from this query configuration.
Sourcefn as_sum(&self, column: impl Expressive<T>) -> Expression<T>
fn as_sum(&self, column: impl Expressive<T>) -> Expression<T>
Creates a SUM(column) expression from this query configuration.
Sourcefn as_max(&self, column: impl Expressive<T>) -> Expression<T>
fn as_max(&self, column: impl Expressive<T>) -> Expression<T>
Creates a MAX(column) expression from this query configuration.
Sourcefn as_min(&self, column: impl Expressive<T>) -> Expression<T>
fn as_min(&self, column: impl Expressive<T>) -> Expression<T>
Creates a MIN(column) expression from this query configuration.
Provided Methods§
Sourcefn with_source(self, source: impl Into<SourceRef<T>>) -> Selfwhere
Self: Sized,
fn with_source(self, source: impl Into<SourceRef<T>>) -> Selfwhere
Self: Sized,
Builder pattern method identical to Self::add_source without alias.
Sourcefn with_source_as(
self,
source: impl Into<SourceRef<T>>,
alias: impl Into<String>,
) -> Selfwhere
Self: Sized,
fn with_source_as(
self,
source: impl Into<SourceRef<T>>,
alias: impl Into<String>,
) -> Selfwhere
Self: Sized,
Builder pattern method identical to Self::add_source with alias.
Sourcefn with_condition(self, condition: impl Into<C>) -> Selfwhere
Self: Sized,
fn with_condition(self, condition: impl Into<C>) -> Selfwhere
Self: Sized,
Builder pattern method identical to Self::add_where_condition.
Sourcefn with_order(self, order: impl Into<C>, direction: Order) -> Selfwhere
Self: Sized,
fn with_order(self, order: impl Into<C>, direction: Order) -> Selfwhere
Self: Sized,
Builder pattern method identical to Self::add_order_by.
Sourcefn with_field(self, field: impl Into<String>) -> Selfwhere
Self: Sized,
fn with_field(self, field: impl Into<String>) -> Selfwhere
Self: Sized,
Builder pattern method identical to Self::add_field.
Sourcefn with_expression(self, expression: impl Expressive<T>) -> Selfwhere
Self: Sized,
fn with_expression(self, expression: impl Expressive<T>) -> Selfwhere
Self: Sized,
Builder pattern method identical to Self::add_expression.
Sourcefn with_group_by(self, expression: impl Expressive<T>) -> Selfwhere
Self: Sized,
fn with_group_by(self, expression: impl Expressive<T>) -> Selfwhere
Self: Sized,
Builder pattern method identical to Self::add_group_by.
Sourcefn with_distinct(self, distinct: bool) -> Selfwhere
Self: Sized,
fn with_distinct(self, distinct: bool) -> Selfwhere
Self: Sized,
Builder pattern method identical to Self::set_distinct.
Sourcefn with_limit(self, limit: Option<i64>, skip: Option<i64>) -> Selfwhere
Self: Sized,
fn with_limit(self, limit: Option<i64>, skip: Option<i64>) -> Selfwhere
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.