besu 0.0.1

A typesafe, async, and database-agnostic query builder for Rust.
Documentation
use std::{
    future::{Future, IntoFuture},
    marker::PhantomData,
    pin::Pin,
};

use crate::{Dialect, Driver, Table};

/// Represents an SQL `DELETE` operation.
#[non_exhaustive]
pub struct DeleteOperation {
    /// The name of the table being deleted.
    pub table: &'static str,
}

/// Builder for an SQL `DELETE` operation.
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,
        }
    }

    /// Convert the operation to a raw SQL and values.
    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 })
    }
}