pub enum Statement {
Delete(Delete),
Insert(Insert),
Query(Query),
Update(Update),
}Expand description
A top-level statement in Toasty’s AST.
Each variant corresponds to one of the four fundamental database operations.
A Statement is the primary input to the query engine’s compilation
pipeline and the output of code generated by #[derive(Model)].
§Examples
use toasty_core::stmt::{Statement, Query, Values};
let query = Query::unit();
let stmt = Statement::from(query);
assert!(stmt.is_query());
assert!(!stmt.is_insert());Variants§
Delete(Delete)
Delete one or more existing records.
Insert(Insert)
Create one or more new records.
Query(Query)
Query (read) records from the database.
Update(Update)
Update one or more existing records.
Implementations§
Source§impl Statement
impl Statement
Sourcepub fn assignments(&self) -> Option<&Assignments>
pub fn assignments(&self) -> Option<&Assignments>
Returns this statement’s assignments if it is an Update.
Source§impl Statement
impl Statement
Sourcepub fn condition(&self) -> Option<&Condition>
pub fn condition(&self) -> Option<&Condition>
Returns a reference to this statement’s condition, if it has one and it
is set. Only Update statements support conditions.
Sourcepub fn condition_mut(&mut self) -> Option<&mut Condition>
pub fn condition_mut(&mut self) -> Option<&mut Condition>
Returns a mutable reference to the statement’s condition.
Returns None for statements that do not support conditions.
Sourcepub fn condition_mut_unwrap(&mut self) -> &mut Condition
pub fn condition_mut_unwrap(&mut self) -> &mut Condition
Returns a mutable reference to the statement’s condition.
§Panics
Panics if the statement does not support conditions.
Source§impl Statement
impl Statement
Sourcepub fn as_delete(&self) -> Option<&Delete>
pub fn as_delete(&self) -> Option<&Delete>
Attempts to return a reference to an inner Delete.
- If
selfis aStatement::Delete, a reference to the innerDeleteis returned wrapped inSome. - Else,
Noneis returned.
Sourcepub fn into_delete(self) -> Option<Delete>
pub fn into_delete(self) -> Option<Delete>
Consumes self and attempts to return the inner Delete.
- If
selfis aStatement::Delete, innerDeleteis returned wrapped inSome. - Else,
Noneis returned.
Sourcepub fn into_delete_unwrap(self) -> Delete
pub fn into_delete_unwrap(self) -> Delete
Source§impl Statement
impl Statement
Source§impl Statement
impl Statement
Sourcepub fn filter(&self) -> Option<&Filter>
pub fn filter(&self) -> Option<&Filter>
Returns a reference to this statement’s filter, if it has one.
Returns None for INSERT statements.
Sourcepub fn filter_unwrap(&self) -> &Filter
pub fn filter_unwrap(&self) -> &Filter
Sourcepub fn filter_or_default(&self) -> &Filter
pub fn filter_or_default(&self) -> &Filter
Returns this statement’s filter, or Filter::ALL if it has none.
Sourcepub fn filter_mut(&mut self) -> Option<&mut Filter>
pub fn filter_mut(&mut self) -> Option<&mut Filter>
Returns a mutable reference to the statement’s filter.
Returns None for statements that do not support filtering, such as
INSERT.
Sourcepub fn filter_mut_unwrap(&mut self) -> &mut Filter
pub fn filter_mut_unwrap(&mut self) -> &mut Filter
Returns a mutable reference to the statement’s filter.
§Panics
Panics if the statement does not support filtering.
Sourcepub fn filter_expr_unwrap(&self) -> &Expr
pub fn filter_expr_unwrap(&self) -> &Expr
Returns a reference to the filter’s inner expression.
§Panics
Panics if the statement has no filter or the filter has no expression.
Sourcepub fn filter_expr_mut(&mut self) -> Option<&mut Expr>
pub fn filter_expr_mut(&mut self) -> Option<&mut Expr>
Returns a mutable reference to the filter’s inner expression, if any.
Source§impl Statement
impl Statement
Sourcepub fn as_insert(&self) -> Option<&Insert>
pub fn as_insert(&self) -> Option<&Insert>
Attempts to return a reference to an inner Insert.
- If
selfis aStatement::Insert, a reference to the innerInsertis returned wrapped inSome. - Else,
Noneis returned.
Sourcepub fn into_insert(self) -> Option<Insert>
pub fn into_insert(self) -> Option<Insert>
Consumes self and attempts to return the inner Insert.
- If
selfis aStatement::Insert, innerInsertis returned wrapped inSome. - Else,
Noneis returned.
Sourcepub fn into_insert_unwrap(self) -> Insert
pub fn into_insert_unwrap(self) -> Insert
Source§impl Statement
impl Statement
Sourcepub fn as_query(&self) -> Option<&Query>
pub fn as_query(&self) -> Option<&Query>
Attempts to return a reference to an inner Query.
- If
selfis aStatement::Query, a reference to the innerQueryis returned wrapped inSome. - Else,
Noneis returned.
Sourcepub fn as_query_mut(&mut self) -> Option<&mut Query>
pub fn as_query_mut(&mut self) -> Option<&mut Query>
Returns a mutable reference to the inner Query, if this is a query statement.
- If
selfis aStatement::Query, a mutable reference to the innerQueryis returned wrapped inSome. - Else,
Noneis returned.
Sourcepub fn into_query(self) -> Option<Query>
pub fn into_query(self) -> Option<Query>
Consumes self and attempts to return the inner Query.
Returns None if self is not a Statement::Query.
Sourcepub fn into_query_unwrap(self) -> Query
pub fn into_query_unwrap(self) -> Query
Source§impl Statement
impl Statement
Sourcepub fn returning(&self) -> Option<&Returning>
pub fn returning(&self) -> Option<&Returning>
Returns a reference to this statement’s RETURNING clause, if present.
Returns None if the statement does not have a RETURNING clause or is
a statement type that does not support RETURNING.
Sourcepub fn take_returning(&mut self) -> Option<Returning>
pub fn take_returning(&mut self) -> Option<Returning>
Take the Returning clause
Sourcepub fn set_returning(&mut self, returning: Returning)
pub fn set_returning(&mut self, returning: Returning)
Set the Returning clause
Sourcepub fn returning_unwrap(&self) -> &Returning
pub fn returning_unwrap(&self) -> &Returning
Returns a reference to this statement’s RETURNING clause.
§Panics
Panics if the statement does not have a RETURNING clause.
Sourcepub fn returning_mut(&mut self) -> Option<&mut Returning>
pub fn returning_mut(&mut self) -> Option<&mut Returning>
Returns a mutable reference to this statement’s RETURNING clause, if present.
Returns None if the statement does not have a RETURNING clause or is
a statement type that does not support RETURNING.
Sourcepub fn returning_mut_unwrap(&mut self) -> &mut Returning
pub fn returning_mut_unwrap(&mut self) -> &mut Returning
Returns a mutable reference to this statement’s RETURNING clause.
§Panics
Panics if the statement does not have a RETURNING clause.
Source§impl Statement
impl Statement
Sourcepub fn query_select(&self) -> Option<&Select>
pub fn query_select(&self) -> Option<&Select>
If this is a query with a SELECT body, returns a reference to that
Select. Returns None otherwise.
Sourcepub fn query_select_unwrap(&self) -> &Select
pub fn query_select_unwrap(&self) -> &Select
Source§impl Statement
impl Statement
Sourcepub fn substitute(&mut self, input: impl Input)
pub fn substitute(&mut self, input: impl Input)
Substitutes argument placeholders in this statement with concrete values
from input.
Sourcepub fn is_const(&self) -> bool
pub fn is_const(&self) -> bool
Returns true if this statement is a query whose body contains only
constant values (no table references or subqueries) and has no CTEs.
Sourcepub fn as_update(&self) -> Option<&Update>
pub fn as_update(&self) -> Option<&Update>
Attempts to return a reference to an inner Update.
- If
selfis aStatement::Update, a reference to the innerUpdateis returned wrapped inSome. - Else,
Noneis returned.
Sourcepub fn into_update(self) -> Option<Update>
pub fn into_update(self) -> Option<Update>
Consumes self and attempts to return the inner Update.
- If
selfis aStatement::Update, innerUpdateis returned wrapped inSome. - Else,
Noneis returned.
Sourcepub fn into_update_unwrap(self) -> Update
pub fn into_update_unwrap(self) -> Update
Trait Implementations§
Source§impl<'a, T: Resolve> IntoExprTarget<'a, T> for &'a Statement
impl<'a, T: Resolve> IntoExprTarget<'a, T> for &'a Statement
Source§fn into_expr_target(self, schema: &'a T) -> ExprTarget<'a>
fn into_expr_target(self, schema: &'a T) -> ExprTarget<'a>
self into an ExprTarget using the provided schema.