use super::{IntoStatement, Statement};
use crate::{Executor, Result, schema::Load};
use std::marker::PhantomData;
use toasty_core::stmt;
pub struct Delete<T> {
pub(crate) untyped: stmt::Delete,
_p: PhantomData<T>,
}
impl<T> Delete<T> {
pub const fn from_untyped(untyped: stmt::Delete) -> Self {
Self {
untyped,
_p: PhantomData,
}
}
}
impl<T> Delete<T> {
pub fn set_condition(mut self, condition: toasty_core::stmt::Condition) -> Self {
self.untyped.condition = condition;
self
}
}
impl<T: Load> Delete<T> {
pub async fn exec(self, executor: &mut dyn Executor) -> Result<T::Output> {
executor.exec(self.into()).await
}
}
impl<T> IntoStatement for Delete<T> {
type Returning = T;
fn into_statement(self) -> Statement<T> {
Statement {
untyped: self.untyped.into(),
_p: PhantomData,
}
}
}
impl<T> From<Delete<T>> for Statement<T> {
fn from(value: Delete<T>) -> Self {
Self {
untyped: value.untyped.into(),
_p: PhantomData,
}
}
}