Struct DeleteQuery

Source
pub struct DeleteQuery<'a, 'c> {
    pub whre: Vec<WhereClause<'a, 'c>>,
    /* private fields */
}
Expand description

Struct representing a SQL Delete Statement

Fields§

§whre: Vec<WhereClause<'a, 'c>>

Implementations§

Source§

impl<'a, 'c> DeleteQuery<'a, 'c>

Source

pub fn from(table: &'a str) -> DeleteQuery<'_, '_>

Return a new DeleteQuery that deletes data from table table

Source

pub fn limit(&mut self, limit: usize)

Sets the limit of items to delete

§Example
use query_builder::{DeleteQuery, Value, WhereClause};
 
let mut query = DeleteQuery::from("users");
// add values to delete
query.whre.push(WhereClause::new("name", Value::Varchar("gregory"), None));
 
// add the limit
query.limit(1);
 
// make sure the query looks like expected
assert_eq!(query.as_string(), "DELETE FROM users WHERE name = 'gregory' LIMIT 1");
Source

pub fn get_limit(&self) -> Option<usize>

Returns the limit of the DeleteQuery

§Example
use query_builder::{DeleteQuery, Value};
 
// create query
let mut query = DeleteQuery::from("users");
 
// set the limit
query.limit(12);
 
assert_eq!(query.get_limit(), Some(12));
Source

pub fn clear_limit(&mut self)

Removes the limit from the DeleteQuery

§Example
use query_builder::DeleteQuery;
 
let mut query = DeleteQuery::from("users");
/* add limit to the query */
query.limit(12);
 
assert_eq!(query.get_limit(), Some(12));
 
/* clear the limit */
query.clear_limit();
 
assert_eq!(query.get_limit(), None);
 
Source

pub fn order_by(&mut self, ob: OrderBy<'c>)

Adds a OrderBy clause to the query

§Example
use query_builder::{DeleteQuery, OrderBy};
 
let mut query = DeleteQuery::from("continents");
query.order_by(OrderBy::Row("population"));
 
assert_eq!(query.as_string(), "DELETE FROM continents ORDER BY population");
Source

pub fn is_ordered(&self) -> bool

Returns either true or false depending on whether or not the DeleteQuery contains a OrderBy clause

§Example
use query_builder::{DeleteQuery, OrderBy};
 
let mut query = DeleteQuery::from("states");
query.order_by(OrderBy::Row("population"));
 
assert!(query.is_ordered());
Source

pub fn clear_order_by(&mut self)

Removes the ORDER BY clause from the query

Source

pub fn as_string(&self) -> String

Return a String representing the DeleteQuery

§Example
use query_builder::{DeleteQuery, Value, WhereClause, Condition};
 
// create basic query
let mut query = DeleteQuery::from("people");
 
// set parameter of the query
query.whre.push(WhereClause::new("name", Value::Varchar("justine"), None));
query.whre.push(WhereClause::new("age", Value::Int(24), Some(Condition::And)));
query.limit(1);
 
assert_eq!(query.as_string(), "DELETE FROM people WHERE name = 'justine' AND age = 24 LIMIT 1");

Trait Implementations§

Source§

impl<'a, 'c> Debug for DeleteQuery<'a, 'c>

Source§

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

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

impl<'a, 'c> Display for DeleteQuery<'a, 'c>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, 'c> Freeze for DeleteQuery<'a, 'c>

§

impl<'a, 'c> RefUnwindSafe for DeleteQuery<'a, 'c>

§

impl<'a, 'c> Send for DeleteQuery<'a, 'c>

§

impl<'a, 'c> Sync for DeleteQuery<'a, 'c>

§

impl<'a, 'c> Unpin for DeleteQuery<'a, 'c>

§

impl<'a, 'c> UnwindSafe for DeleteQuery<'a, 'c>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.