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.
impl QueryBuilder
Implementations For QueryBuilder.
Sourcepub fn select(fields: Vec<&str>) -> Result<Self, Error>
pub fn select(fields: Vec<&str>) -> Result<Self, Error>
Select constructor. Use it if you want to build a Select Query.
Sourcepub fn delete() -> Result<Self, Error>
pub fn delete() -> Result<Self, Error>
Delete constructor. Use it if you want to build a Delete Query.
Sourcepub fn update() -> Result<Self, Error>
pub fn update() -> Result<Self, Error>
Update constructor. Use it if you want to build a Update Query.
Sourcepub fn insert(
columns: Vec<&str>,
values: Vec<(&str, ValueType)>,
) -> Result<Self, Error>
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.
Sourcepub fn count(condition: &str, _as: Option<&str>) -> Self
pub fn count(condition: &str, _as: Option<&str>) -> Self
Count constructor. Use it if you want to learn to length of a table.
Sourcepub fn table(&mut self, table: &str) -> &mut Self
pub fn table(&mut self, table: &str) -> &mut Self
define the table. It should came after the constructors.
Sourcepub fn where_cond(
&mut self,
column: &str,
mark: &str,
value: (&str, ValueType),
) -> &mut Self
pub fn where_cond( &mut self, column: &str, mark: &str, value: (&str, ValueType), ) -> &mut Self
add the “WHERE” keyword with it’s synthax.
Sourcepub fn where_in(
&mut self,
column: &str,
ins: Vec<(&str, ValueType)>,
) -> &mut Self
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.
Sourcepub fn where_not_in(
&mut self,
column: &str,
ins: Vec<(&str, ValueType)>,
) -> &mut Self
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.
Sourcepub fn where_in_custom(&mut self, column: &str, query: &str) -> &mut Self
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.
Sourcepub fn where_not_in_custom(&mut self, column: &str, query: &str) -> &mut Self
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.
Sourcepub fn or(
&mut self,
column: &str,
mark: &str,
value: (&str, ValueType),
) -> &mut Self
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.
Sourcepub fn set(&mut self, column: &str, value: (&str, ValueType)) -> &mut Self
pub fn set(&mut self, column: &str, value: (&str, ValueType)) -> &mut Self
It adds the “SET” keyword with it’s synthax.
Sourcepub fn and(
&mut self,
column: &str,
mark: &str,
value: (&str, ValueType),
) -> &mut Self
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.
Sourcepub fn offset(&mut self, offset: i32) -> &mut Self
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.
Sourcepub fn limit(&mut self, limit: i32) -> &mut Self
pub fn limit(&mut self, limit: i32) -> &mut Self
It adds the “LIMIT” keyword with it’s synthax.
Sourcepub fn like(&mut self, columns: Vec<&str>, operand: &str) -> &mut Self
pub fn like(&mut self, columns: Vec<&str>, operand: &str) -> &mut Self
It adds the “LIKE” keyword with it’s synthax.
Sourcepub fn order_by(&mut self, column: &str, ordering: &str) -> &mut Self
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.
Sourcepub fn order_random(&mut self) -> &mut Self
pub fn order_random(&mut self) -> &mut Self
A practical method that adds a query for shuffling the lines.
Sourcepub fn group_by(&mut self, column: &str) -> &mut Self
pub fn group_by(&mut self, column: &str) -> &mut Self
It adds the “GROUP BY” keyword with it’s Synthax.
pub fn having( &mut self, column: &str, mark: &str, value: (&str, ValueType), ) -> &mut Self
Sourcepub fn append_custom(&mut self, query: &str) -> &mut Self
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.
Sourcepub fn append_keyword(&mut self, keyword: KeywordList) -> &mut Self
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.
Sourcepub fn json_extract(
&mut self,
haystack: &str,
needle: &str,
_as: Option<&str>,
) -> &mut Self
pub fn json_extract( &mut self, haystack: &str, needle: &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.
Trait Implementations§
Source§impl Clone for QueryBuilder
impl Clone for QueryBuilder
Source§fn clone(&self) -> QueryBuilder
fn clone(&self) -> QueryBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more