pub struct Delete { /* private fields */ }
Expand description

Builder to contruct a Delete command

Implementations§

source§

impl Delete

source

pub fn and(self, condition: &str) -> Self

The same as where_clause method, useful to write more idiomatic SQL query

Example
use sql_query_builder as sql;

let delete = sql::Delete::new()
  .delete_from("users")
  .where_clause("created_at < $1")
  .and("active = false");
source

pub fn as_string(&self) -> String

Gets the current state of the Delete and returns it as string

Example
use sql_query_builder as sql;

let query = sql::Delete::new()
  .delete_from("users")
  .where_clause("id = $1")
  .as_string();

Output

DELETE FROM users WHERE id = $1
source

pub fn debug(self) -> Self

Prints the current state of the Delete into console output in a more ease to read version. This method is useful to debug complex queries or just to print the generated SQL while you type

Example
use sql_query_builder as sql;

let delete_query = sql::Delete::new()
  .delete_from("users")
  .where_clause("login = 'foo'")
  .debug()
  .where_clause("name = 'Foo'")
  .as_string();

Output

DELETE FROM users
WHERE login = 'foo'
source

pub fn delete_from(self, table_name: &str) -> Self

The delete clause. This method overrides the previous value

Example
use sql_query_builder as sql;

let delete = sql::Delete::new()
  .delete_from("orders");

let delete = sql::Delete::new()
  .delete_from("address")
  .delete_from("orders");
source

pub fn new() -> Self

Create Delete’s instance

source

pub fn print(self) -> Self

Prints the current state of the Delete into console output similar to debug method, the difference is that this method prints in one line.

source

pub fn raw(self, raw_sql: &str) -> Self

Adds at the beginning a raw SQL query.

Example
use sql_query_builder as sql;

let raw_query = "delete from users";
let delete_query = sql::Delete::new()
  .raw(raw_query)
  .where_clause("login = 'foo'")
  .as_string();

Output

delete from users
WHERE login = 'foo'
source

pub fn raw_after(self, clause: DeleteClause, raw_sql: &str) -> Self

Adds a raw SQL query after a specified clause.

Example
use sql_query_builder as sql;

let raw = "where name = 'Foo'";
let delete_query = sql::Delete::new()
  .delete_from("users")
  .raw_after(sql::DeleteClause::DeleteFrom, raw)
  .as_string();

Output

DELETE FROM users
where name = 'Foo'
source

pub fn raw_before(self, clause: DeleteClause, raw_sql: &str) -> Self

Adds a raw SQL query before a specified clause.

Example
use sql_query_builder as sql;

let raw = "delete from users";
let delete_query = sql::Delete::new()
  .raw_before(sql::DeleteClause::Where, raw)
  .where_clause("name = 'Bar'")
  .as_string();

Output

delete from users
WHERE name = 'Bar'
source

pub fn where_clause(self, condition: &str) -> Self

The where clause

Example
use sql_query_builder as sql;

let delete = sql::Delete::new()
  .delete_from("users")
  .where_clause("login = 'foo'");
source§

impl Delete

source

pub fn returning(self, output_name: &str) -> Self

The returning clause, this method can be used enabling the feature flag postgresql

source

pub fn with(self, name: &str, query: impl WithQuery + 'static) -> Self

The with clause, this method can be used enabling the feature flag postgresql

Example
use sql_query_builder as sql;

let deactivated_users = sql::Select::new().select("id").from("users").where_clause("ative = false");
let delete = sql::Delete::new()
  .with("deactivated_users", deactivated_users)
  .delete_from("users")
  .where_clause("id in (select * from deactivated_users)")
  .debug();

Output

WITH deactivated_users AS (
  SELECT id
  FROM users
  WHERE ative = false
)
DELETE FROM users
WHERE id in (select * from deactivated_users)

Trait Implementations§

source§

impl Clone for Delete

source§

fn clone(&self) -> Delete

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Delete

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Delete

source§

fn default() -> Delete

Returns the “default value” for a type. Read more
source§

impl Display for Delete

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Delete

§

impl !Send for Delete

§

impl !Sync for Delete

§

impl Unpin for Delete

§

impl !UnwindSafe for Delete

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.