qubl

Struct QueryBuilder

Source
pub struct QueryBuilder {
    pub query: String,
    pub table: String,
    pub qtype: QueryType,
    pub list: Vec<KeywordList>,
}
Expand description

Struct that benefits to build queries for interactions with rdbms’s.

Fields§

§query: String§table: String§qtype: QueryType§list: Vec<KeywordList>

Implementations§

Source§

impl QueryBuilder

Implementations For QueryBuilder.

Source

pub fn select(fields: Vec<&str>) -> Result<Self, Error>

Select constructor. Use it if you want to build a Select Query.

Source

pub fn delete() -> Result<Self, Error>

Delete constructor. Use it if you want to build a Delete Query.

Source

pub fn update() -> Result<Self, Error>

Update constructor. Use it if you want to build a Update Query.

Source

pub fn insert( columns: Vec<&str>, values: Vec<(&str, ValueType)>, ) -> Result<Self, Error>

Insert constructor. Use it if you want to build a Insert Query.

Source

pub fn count(condition: &str, _as: Option<&str>) -> Self

Count constructor. Use it if you want to learn to length of a table.

Source

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

define the table. It should came after the constructors.

Source

pub fn where_cond( &mut self, column: &str, mark: &str, value: (&str, ValueType), ) -> &mut Self

add the “WHERE” keyword with it’s synthax.

Source

pub fn where_in( &mut self, column: &str, ins: Vec<(&str, ValueType)>, ) -> &mut Self

It adds the “IN” keyword with it’s synthax. Don’t use “.where_cond()” method if you use it.

Source

pub fn where_not_in( &mut self, column: &str, ins: Vec<(&str, ValueType)>, ) -> &mut Self

It adds the “NOT IN” keyword with it’s synthax. Don’t use “.where_cond()” method if you use it.

Source

pub fn where_in_custom(&mut self, column: &str, query: &str) -> &mut Self

It adds the “IN” keyword with it’s synthax and an empty condition, use it if you want to give more complex condition to “IN” keyword. Don’t use “.where_cond()” with it.

Source

pub fn where_not_in_custom(&mut self, column: &str, query: &str) -> &mut Self

It adds the “NOT IN” keyword with it’s synthax and an empty condition, use it if you want to give more complex condition to “NOT IN” keyword. Don’t use “.where_cond()” with it.

Source

pub fn or( &mut self, column: &str, mark: &str, value: (&str, ValueType), ) -> &mut Self

It adds the “OR” keyword with it’s synthax. Warning: It’s not ready yet to chaining “AND” and “OR” keywords, for now, applying that kind of complex query use “.append_custom()” method instead.

Source

pub fn set(&mut self, column: &str, value: (&str, ValueType)) -> &mut Self

It adds the “SET” keyword with it’s synthax.

Source

pub fn and( &mut self, column: &str, mark: &str, value: (&str, ValueType), ) -> &mut Self

It adds the “AND” keyword with it’s synthax. Warning: It’s not ready yet to chaining “OR” and “AND” keywords, for now, applying that kind of complex query use “.append_custom()” method instead.

Source

pub fn offset(&mut self, offset: i32) -> &mut Self

It adds the “OFFSET” keyword with it’s synthax. Be careful about it’s alignment with “LIMIT” keyword.

Source

pub fn limit(&mut self, limit: i32) -> &mut Self

It adds the “LIMIT” keyword with it’s synthax.

Source

pub fn like(&mut self, columns: Vec<&str>, operand: &str) -> &mut Self

It adds the “LIKE” keyword with it’s synthax.

Source

pub fn order_by(&mut self, column: &str, ordering: &str) -> &mut Self

It adds the “ORDER BY” keyword with it’s synthax. It only accepts “ASC”, “DESC”, “asc”, “desc” values.

Source

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

A practical method that adds a query for shuffling the lines.

Source

pub fn group_by(&mut self, column: &str) -> &mut Self

It adds the “GROUP BY” keyword with it’s Synthax.

Source

pub fn having( &mut self, column: &str, mark: &str, value: (&str, ValueType), ) -> &mut Self

Source

pub fn append_custom(&mut self, query: &str) -> &mut Self

A wildcard method that gives you the chance to write a part of your query. Warning, it does not add any keyword to builder, i’ll encourage to add proper keyword to it with .append_keyword() method for your custom query, otherwise you should continue building your query by yourself with that function, or you’ve to be prepared to encounter bugs.

Source

pub fn append_keyword(&mut self, keyword: KeywordList) -> &mut Self

A wildcard method that benefits you to append a keyword to the keyword list, so the QueryBuilder can build your queries properly, later than you appended your custom string to your query. It should be used with .append_custom() method.

Source

pub fn json_extract( &mut self, column: &str, field: &str, _as: Option<&str>, ) -> &mut Self

It applies “JSON_EXTRACT()” mysql function with it’s Synthax. If you encounter any syntactic bugs or deficiencies about that function, please report it via opening an issue.

Source

pub fn json_contains( &mut self, column: &str, needle: (&str, ValueType), path: Option<&str>, ) -> &mut Self

It applies “JSON_CONTAINS()” mysql function with it’s Synthax. If you encounter any syntactic bugs or deficiencies about that function, please report it via opening an issue.

Source

pub fn finish(&self) -> String

finishes the query and returns the result as string.

Trait Implementations§

Source§

impl Clone for QueryBuilder

Source§

fn clone(&self) -> QueryBuilder

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 QueryBuilder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

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