pub struct QueryBuilder { /* private fields */ }
Expand description
The QueryBuilder is how you can build dynamically queries using the builder pattern.
§Features
There is a number a features that are supported by the QueryBuilder:
- All Major Query Types
- Select: Build a select query
- Insert: Build an insert query
- Update: Build an update query
- Delete: Build a delete query
- Conditions: Build a query with conditions
- Where: Build a query with where conditions
- Order By: Build a query with order by conditions
- Limit: Build a query with a limit
- Joins: Build a query with joins 2 tables
- Only Inner Joins are supported currently
§Example
use geekorm::prelude::*;
#[derive(Table, Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct Users {
pub id: PrimaryKeyInteger,
pub username: String,
pub age: i32,
pub postcode: Option<String>,
}
// Build a query to create a new table
let create_query = Users::query_create().build()
.expect("Failed to build create query");
println!("Create Query :: {}", create_query);
// Build a query to select rows from the table
let select_query = Users::query_select()
.where_eq("username", "geekmasher")
.order_by("age", QueryOrder::Asc)
.build()
.expect("Failed to build select query");
println!("Select Query :: {}", select_query);
// Output:
// SELECT (...) FROM User WHERE username = ? ORDER BY age ASC;
Implementations§
Source§impl QueryBuilder
impl QueryBuilder
Sourcepub fn select() -> QueryBuilder
pub fn select() -> QueryBuilder
Build a select query
Sourcepub fn create() -> QueryBuilder
pub fn create() -> QueryBuilder
Build a create query
Sourcepub fn all() -> QueryBuilder
pub fn all() -> QueryBuilder
Build a “get all rows” query
Sourcepub fn insert() -> QueryBuilder
pub fn insert() -> QueryBuilder
Build an insert query
Sourcepub fn update() -> QueryBuilder
pub fn update() -> QueryBuilder
Build an update query
Sourcepub fn delete() -> QueryBuilder
pub fn delete() -> QueryBuilder
Build a delete query
Sourcepub fn add_value(self, column: &str, value: impl Into<Value>) -> Self
pub fn add_value(self, column: &str, value: impl Into<Value>) -> Self
Add a value to the list of values for parameterized queries
Sourcepub fn where_ne(self, column: &str, value: impl Into<Value>) -> Self
pub fn where_ne(self, column: &str, value: impl Into<Value>) -> Self
Where clause for not equals
Sourcepub fn where_like(self, column: &str, value: impl Into<Value>) -> Self
pub fn where_like(self, column: &str, value: impl Into<Value>) -> Self
Where clause for like
Sourcepub fn where_gt(self, column: &str, value: impl Into<Value>) -> Self
pub fn where_gt(self, column: &str, value: impl Into<Value>) -> Self
Where clause for greater than
Sourcepub fn where_lt(self, column: &str, value: impl Into<Value>) -> Self
pub fn where_lt(self, column: &str, value: impl Into<Value>) -> Self
Where clause for less than
Sourcepub fn where_gte(self, column: &str, value: impl Into<Value>) -> Self
pub fn where_gte(self, column: &str, value: impl Into<Value>) -> Self
Where clause for greater than or equal to
Sourcepub fn where_lte(self, column: &str, value: impl Into<Value>) -> Self
pub fn where_lte(self, column: &str, value: impl Into<Value>) -> Self
Where clause for less than or equal to
Sourcepub fn filter(self, fields: Vec<(&str, impl Into<Value>)>) -> Self
pub fn filter(self, fields: Vec<(&str, impl Into<Value>)>) -> Self
Filter the query by multiple fields
Sourcepub fn order_by(self, column: &str, order: QueryOrder) -> Self
pub fn order_by(self, column: &str, order: QueryOrder) -> Self
Order the query by a particular column
Trait Implementations§
Source§impl Clone for QueryBuilder
impl Clone for QueryBuilder
Source§fn clone(&self) -> QueryBuilder
fn clone(&self) -> QueryBuilder
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for QueryBuilder
impl Debug for QueryBuilder
Source§impl Default for QueryBuilder
impl Default for QueryBuilder
Source§fn default() -> QueryBuilder
fn default() -> QueryBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for QueryBuilder
impl RefUnwindSafe for QueryBuilder
impl Send for QueryBuilder
impl Sync for QueryBuilder
impl Unpin for QueryBuilder
impl UnwindSafe for QueryBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request