Struct Where

Source
pub struct Where { /* private fields */ }
Expand description

Represents a WHERE clause builder for SQL queries.

Implementations§

Source§

impl Where

Source

pub fn new() -> Self

Creates a new Where instance with an empty statement.

§Example
use lumus_sql_builder::sqlite::Where;

let mut condition = Where::new();
condition.equal_to("name", "Dayvson Spacca");

assert_eq!(condition.build(), "name = 'Dayvson Spacca'")
Source

pub fn from(statement: &str) -> Self

Creates a new Where instance with a specified initial statement.

§Example
use lumus_sql_builder::sqlite::Where;

let mut condition = Where::from("name = 'Dayvson Spacca'");
condition.and().greater_than("age", "21");

assert_eq!(condition.build(), "name = 'Dayvson Spacca' AND age > '21'");
Source

pub fn equal_to(&mut self, field: &str, value: &str) -> &mut Self

Adds an equality condition (field = value) to the WHERE clause.

Source

pub fn not_equal_to(&mut self, field: &str, value: &str) -> &mut Self

Adds a not equal condition (field != value) to the WHERE clause.

Source

pub fn greater_than(&mut self, field: &str, value: &str) -> &mut Self

Adds a greater than condition (field > value) to the WHERE clause.

Source

pub fn greater_than_equal(&mut self, field: &str, value: &str) -> &mut Self

Adds a greater than or equal condition (field >= value) to the WHERE clause.

Source

pub fn less_than(&mut self, field: &str, value: &str) -> &mut Self

Adds a less than condition (field < value) to the WHERE clause.

Source

pub fn less_than_equal(&mut self, field: &str, value: &str) -> &mut Self

Adds a less than or equal condition (field <= value) to the WHERE clause.

Source

pub fn is_null(&mut self, field: &str) -> &mut Self

Adds a IS NULL condition (field IS NULL) to the WHERE clause.

Source

pub fn is_not_null(&mut self, field: &str) -> &mut Self

Adds a IS NOT NULL condition (field IS NOT NULL) to the WHERE clause.

Source

pub fn inside(&mut self, field: &str, values: Vec<&str>) -> &mut Self

Adds an IN condition (field IN (values)) to the WHERE clause.

Source

pub fn not_inside(&mut self, field: &str, values: Vec<&str>) -> &mut Self

Adds a NOT IN condition (field NOT IN (values)) to the WHERE clause.

Source

pub fn like(&mut self, field: &str, value: &str) -> &mut Self

Adds a LIKE condition (field LIKE value) to the WHERE clause.

Source

pub fn not_like(&mut self, field: &str, value: &str) -> &mut Self

Adds a NOT LIKE condition (field NOT LIKE value) to the WHERE clause.

Source

pub fn and(&mut self) -> &mut Self

Appends AND to the current statement in the WHERE clause.

Source

pub fn or(&mut self) -> &mut Self

Appends OR to the current statement in the WHERE clause.

Source

pub fn nest(&mut self) -> &mut Self

Appends a left parenthesis ( to the current statement in the WHERE clause.

Source

pub fn unnest(&mut self) -> &mut Self

Appends a right parenthesis ) to the current statement in the WHERE clause.

Source

pub fn build(&self) -> String

Constructs and returns the final SQL statement represented by the WHERE clause.

Trait Implementations§

Source§

impl Debug for Where

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Where

§

impl RefUnwindSafe for Where

§

impl Send for Where

§

impl Sync for Where

§

impl Unpin for Where

§

impl UnwindSafe for Where

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, 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.