use std::{
future::{Future, IntoFuture},
marker::PhantomData,
pin::Pin,
};
use crate::{Dialect, Driver, Table};
#[non_exhaustive]
pub struct DeleteOperation {
pub table: &'static str,
}
pub struct Delete<D: Driver, T> {
driver: D,
op: DeleteOperation,
phantom: PhantomData<T>,
}
impl<D: Driver, T: Table> Delete<D, T> {
pub(crate) fn new(driver: D) -> Self {
Self {
driver,
op: DeleteOperation { table: T::NAME },
phantom: PhantomData,
}
}
pub fn to_sql(&self) -> (String, D::Arguments<'_>) {
D::Dialect::delete(&self.op)
}
}
impl<D: Driver, T: Table> IntoFuture for Delete<D, T> {
type Output = Result<D::Output, D::Error>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output>>>;
fn into_future(self) -> Self::IntoFuture {
let driver = self.driver.clone();
let (sql, arguments) = D::Dialect::delete(&self.op);
Box::pin(async move { driver.execute(&sql, arguments).await })
}
}