rqb 0.1.7

sqlx-first typed Postgres query builder.
Documentation
use super::*;

impl Delete {
    /// Creates a delete statement for a table or view source.
    pub(crate) fn from(target: impl Into<Source>) -> Self {
        Self {
            ctes: Vec::new(),
            target: target.into(),
            using: Vec::new(),
            filter: None,
            returning: Vec::new(),
        }
    }

    /// Adds a CTE to the delete statement.
    #[inline]
    pub fn with(mut self, cte: Cte) -> Self {
        self.ctes.push(cte);
        self
    }

    /// Adds a `USING` source.
    pub fn using(mut self, source: impl Into<Source>) -> Self {
        self.using.push(source.into());
        self
    }

    /// Adds one or more fields to `RETURNING`.
    ///
    /// Use a field for one returned column or tuple syntax for a small
    /// heterogeneous field list: `.returning((users::ID, users::EMAIL))`.
    pub fn returning(mut self, fields: impl IntoColumns) -> Self {
        self.returning.extend(fields.into_columns().items);
        self
    }

    /// Adds an aliased expression to `RETURNING`.
    pub fn returning_as(mut self, expr: impl Into<ValueExpr>, alias: impl Into<String>) -> Self {
        self.returning.push(SelectItem {
            expr: expr.into(),
            alias: Some(alias.into()),
        });
        self
    }

    /// Replaces `RETURNING` with every field exposed by the target source.
    #[inline]
    pub fn returning_all(mut self) -> Self {
        self.returning.clear();
        push_returning_fields(&self.target, &mut self.returning);
        self
    }
}

impl_filter_methods!(Delete);