pub struct DeleteExecutor;Expand description
Executor for DELETE statements
Implementations§
Source§impl DeleteExecutor
impl DeleteExecutor
Sourcepub fn execute(
stmt: &DeleteStmt,
database: &mut Database,
) -> Result<usize, ExecutorError>
pub fn execute( stmt: &DeleteStmt, database: &mut Database, ) -> Result<usize, ExecutorError>
Execute a DELETE statement
§Arguments
stmt- The DELETE statement AST nodedatabase- The database to delete from
§Returns
Number of rows deleted or error
§Examples
use vibesql_ast::{BinaryOperator, DeleteStmt, Expression, WhereClause};
use vibesql_catalog::{ColumnSchema, TableSchema};
use vibesql_executor::DeleteExecutor;
use vibesql_storage::Database;
use vibesql_types::{DataType, SqlValue};
let mut db = Database::new();
// Create table
let schema = TableSchema::new(
"users".to_string(),
vec![
ColumnSchema::new("id".to_string(), DataType::Integer, false),
ColumnSchema::new(
"name".to_string(),
DataType::Varchar { max_length: Some(50) },
false,
),
],
);
db.create_table(schema).unwrap();
// Insert rows
db.insert_row(
"users",
vibesql_storage::Row::new(vec![SqlValue::Integer(1), SqlValue::Varchar("Alice".to_string())]),
)
.unwrap();
db.insert_row(
"users",
vibesql_storage::Row::new(vec![SqlValue::Integer(2), SqlValue::Varchar("Bob".to_string())]),
)
.unwrap();
// Delete specific row
let stmt = DeleteStmt {
only: false,
table_name: "users".to_string(),
where_clause: Some(WhereClause::Condition(Expression::BinaryOp {
left: Box::new(Expression::ColumnRef { table: None, column: "id".to_string() }),
op: BinaryOperator::Equal,
right: Box::new(Expression::Literal(SqlValue::Integer(1))),
})),
};
let count = DeleteExecutor::execute(&stmt, &mut db).unwrap();
assert_eq!(count, 1);Sourcepub fn execute_with_procedural_context(
stmt: &DeleteStmt,
database: &mut Database,
procedural_context: &ExecutionContext,
) -> Result<usize, ExecutorError>
pub fn execute_with_procedural_context( stmt: &DeleteStmt, database: &mut Database, procedural_context: &ExecutionContext, ) -> Result<usize, ExecutorError>
Execute a DELETE statement with procedural context Supports procedural variables in WHERE clause
Sourcepub fn execute_with_trigger_context(
stmt: &DeleteStmt,
database: &mut Database,
trigger_context: &TriggerContext<'_>,
) -> Result<usize, ExecutorError>
pub fn execute_with_trigger_context( stmt: &DeleteStmt, database: &mut Database, trigger_context: &TriggerContext<'_>, ) -> Result<usize, ExecutorError>
Execute a DELETE statement with trigger context This allows DELETE statements within trigger bodies to reference OLD/NEW pseudo-variables
Auto Trait Implementations§
impl Freeze for DeleteExecutor
impl RefUnwindSafe for DeleteExecutor
impl Send for DeleteExecutor
impl Sync for DeleteExecutor
impl Unpin for DeleteExecutor
impl UnwindSafe for DeleteExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more