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(arcstr::ArcStr::from("Alice")),
]),
)
.unwrap();
db.insert_row(
"users",
vibesql_storage::Row::new(vec![
SqlValue::Integer(2),
SqlValue::Varchar(arcstr::ArcStr::from("Bob")),
]),
)
.unwrap();
// Delete specific row
let stmt = DeleteStmt {
with_clause: None,
only: false,
table_name: "users".to_string(),
quoted: false,
where_clause: Some(WhereClause::Condition(Expression::BinaryOp {
left: Box::new(Expression::ColumnRef(vibesql_ast::ColumnIdentifier::simple("id", false))),
op: BinaryOperator::Equal,
right: Box::new(Expression::Literal(SqlValue::Integer(1))),
})),
order_by: None,
limit: None,
offset: None,
returning: None,
};
let count = DeleteExecutor::execute(&stmt, &mut db).unwrap();
assert_eq!(count, 1);Sourcepub fn execute_returning(
stmt: &DeleteStmt,
database: &mut Database,
) -> Result<(usize, Option<SelectResult>), ExecutorError>
pub fn execute_returning( stmt: &DeleteStmt, database: &mut Database, ) -> Result<(usize, Option<SelectResult>), ExecutorError>
Execute a DELETE statement, capturing RETURNING rows (SQLite 3.35.0+)
Returns the number of deleted rows plus, when the statement carries a RETURNING clause, the projected OLD rows (values before deletion) — one per deleted row, or one per INSTEAD OF trigger fire for views.
When the statement has no RETURNING clause the second element is None.
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 UnsafeUnpin for DeleteExecutor
impl UnwindSafe for DeleteExecutor
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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