Statement

Enum Statement 

Source
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

Source

pub fn assignments(&self) -> Option<&Assignments>

Returns this statement’s assignments if it is an Update.

Source§

impl Statement

Source

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.

Source

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.

Source

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

Source

pub fn is_delete(&self) -> bool

Returns true if this statement is a Delete.

Source

pub fn as_delete(&self) -> Option<&Delete>

Attempts to return a reference to an inner Delete.

Source

pub fn into_delete(self) -> Option<Delete>

Consumes self and attempts to return the inner Delete.

Source

pub fn into_delete_unwrap(self) -> Delete

Consumes self and returns the inner Delete.

§Panics

If self is not a Statement::Delete.

Source§

impl Statement

Source

pub fn eval(&self, input: impl Input) -> Result<Value>

Evaluates this statement using the provided Input for argument resolution. Only Query statements are supported.

§Errors

Returns an error for non-Query statements, or if evaluation of any sub-expression fails.

Source

pub fn eval_const(&self) -> Result<Value>

Evaluates this statement as a constant expression (no external input).

Source§

impl Statement

Source

pub fn filter(&self) -> Option<&Filter>

Returns a reference to this statement’s filter, if it has one.

Returns None for INSERT statements.

Source

pub fn filter_unwrap(&self) -> &Filter

Returns a reference to this statement’s filter.

§Panics

Panics if the statement has no filter.

Source

pub fn filter_or_default(&self) -> &Filter

Returns this statement’s filter, or Filter::ALL if it has none.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn is_insert(&self) -> bool

Returns true if this statement is an Insert.

Source

pub fn as_insert(&self) -> Option<&Insert>

Attempts to return a reference to an inner Insert.

Source

pub fn into_insert(self) -> Option<Insert>

Consumes self and attempts to return the inner Insert.

Source

pub fn into_insert_unwrap(self) -> Insert

Consumes self and returns the inner Insert.

§Panics

If self is not a Statement::Insert.

Source§

impl Statement

Source

pub fn is_query(&self) -> bool

Returns true if this statement is a Query.

Source

pub fn as_query(&self) -> Option<&Query>

Attempts to return a reference to an inner Query.

Source

pub fn as_query_mut(&mut self) -> Option<&mut Query>

Returns a mutable reference to the inner Query, if this is a query statement.

Source

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.

Source

pub fn into_query_unwrap(self) -> Query

Consumes self and returns the inner Query.

§Panics

If self is not a Statement::Query.

Source§

impl Statement

Source

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.

Source

pub fn take_returning(&mut self) -> Option<Returning>

Take the Returning clause

Source

pub fn set_returning(&mut self, returning: Returning)

Set the Returning clause

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn query_select_unwrap(&self) -> &Select

Returns a reference to this statement’s inner Select.

§Panics

Panics if this is not a query statement with a SELECT body.

Source§

impl Statement

Source

pub fn is_update(&self) -> bool

Returns true if this statement is an Update.

Source§

impl Statement

Source

pub fn name(&self) -> &str

Returns the statement variant name for logging.

Source

pub fn substitute(&mut self, input: impl Input)

Substitutes argument placeholders in this statement with concrete values from input.

Source

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.

Source

pub fn as_update(&self) -> Option<&Update>

Attempts to return a reference to an inner Update.

Source

pub fn into_update(self) -> Option<Update>

Consumes self and attempts to return the inner Update.

Source

pub fn is_single(&self) -> bool

Returns true if this statement expects at most one result row.

Source

pub fn into_update_unwrap(self) -> Update

Consumes self and returns the inner Update.

§Panics

If self is not a Statement::Update.

Trait Implementations§

Source§

impl Clone for Statement

Source§

fn clone(&self) -> Statement

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 Statement

Source§

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

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

impl From<Delete> for Statement

Source§

fn from(src: Delete) -> Self

Converts to this type from the input type.
Source§

impl From<Insert> for Statement

Source§

fn from(src: Insert) -> Self

Converts to this type from the input type.
Source§

impl From<Query> for Statement

Source§

fn from(value: Query) -> Self

Converts to this type from the input type.
Source§

impl From<Select> for Statement

Source§

fn from(value: Select) -> Self

Converts to this type from the input type.
Source§

impl From<Statement> for ExprStmt

Source§

fn from(value: Statement) -> Self

Converts to this type from the input type.
Source§

impl From<Update> for Statement

Source§

fn from(src: Update) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Resolve> IntoExprTarget<'a, T> for &'a Statement

Source§

fn into_expr_target(self, schema: &'a T) -> ExprTarget<'a>

Converts self into an ExprTarget using the provided schema.
Source§

impl Node for Statement

Source§

fn visit<V: Visit>(&self, visit: V)

Traverses this node with an immutable visitor.
Source§

fn visit_mut<V: VisitMut>(&mut self, visit: V)

Traverses this node with a mutable visitor.
Source§

impl PartialEq for Statement

Source§

fn eq(&self, other: &Statement) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Statement

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.