Struct SelectQuery

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

Struct representing a SQL-INSERT Query A simple query to select everything from a table can be created like this:

§Example

use query_builder::SelectQuery;

// create the query
let query = SelectQuery::select(&["*"]).from("users");

// make sure it looks like you would expect it to look
assert_eq!(query.as_string(), "SELECT * FROM users");

Fields§

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

Implementations§

Source§

impl<'a, 'c> SelectQuery<'a, 'c>

Source

pub fn select(rows: &[&'a str]) -> SelectQuery<'a, 'c>

Creates a new SelectQuery that selects data from the row/s rows

Source

pub fn from(self, t: &'a str) -> Self

Sets the table to select from to the value of t

§Example
use query_builder::SelectQuery;

let q = SelectQuery::select(&["user"]).from("users");

assert_eq!(q.as_string(), "SELECT user FROM users")
Source

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

Sets the limit value of the Query to the value of l

§Example
use query_builder::SelectQuery;

let mut q = SelectQuery::select(&["user"]).from("users");
q.limit(12);

assert_eq!(q.as_string(), "SELECT user FROM users LIMIT 12")
Source

pub fn has_limit(&self) -> bool

Return whether or not the SelectQuery has a limit

§Example
use query_builder::SelectQuery;

let mut q = SelectQuery::select(&["user"]).from("users");
q.limit(12);
 
assert!(q.has_limit());
 
q.clear_limit();
assert!(!q.has_limit());
Source

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

Returns the value of the Limit of the SelectQuery if there is one

§Example
use query_builder::SelectQuery;
 
let mut q = SelectQuery::select(&["user"]).from("users");
assert_eq!(q.get_limit(), None);
 
q.limit(12);
assert_eq!(q.get_limit(), Some(12));
Source

pub fn clear_limit(&mut self)

Removes the limit from the query

§Example
use query_builder::SelectQuery;

let mut q = SelectQuery::select(&["user"]).from("users");
 
// set the limit
q.limit(42);
assert_eq!(q.as_string(), "SELECT user FROM users LIMIT 42");

// clear limit
q.clear_limit();
 
assert_eq!(q.as_string(), "SELECT user FROM users");
Source

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

Adds a ORDER BY clause to the query

Source

pub fn as_string(&self) -> String

Creates the string representation of the query

§Example
use query_builder::SelectQuery;

let mut q = SelectQuery::select(&["*"]).from("users");

assert_eq!(q.as_string(), "SELECT * FROM users")

Trait Implementations§

Source§

impl<'a, 'c> Debug for SelectQuery<'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 SelectQuery<'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 SelectQuery<'a, 'c>

§

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

§

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

§

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

§

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

§

impl<'a, 'c> UnwindSafe for SelectQuery<'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.